OpenLayers OpenLayers

Ticket #1649: patch-1649-r7658-B0.diff

File patch-1649-r7658-B0.diff, 7.6 kB (added by elemoine, 5 months ago)
  • tests/Protocol.html

    old new  
    44  <script type="text/javascript"> 
    55 
    66    function test_initialize(t) { 
    7         t.plan(2); 
     7        t.plan(3); 
    88        var options = {}; 
    99        var protocol = new OpenLayers.Protocol(options); 
    1010 
    1111        t.ok(protocol instanceof OpenLayers.Protocol, 
    1212             "new OpenLayers.Protocol returns object" ); 
    1313        t.eq(protocol.options, options, "constructor sets this.options"); 
     14        t.eq(protocol.autoDestroy, true, "constructor does not modify this.autoDestroy"); 
    1415    } 
    1516     
    1617    function test_destroy(t) { 
  • tests/Strategy.html

    old new  
    44  <script type="text/javascript"> 
    55 
    66    function test_initialize(t) { 
    7         t.plan(2); 
     7        t.plan(5); 
    88        var options = {}; 
    99        var strategy = new OpenLayers.Strategy(options); 
    1010 
    1111        t.ok(strategy instanceof OpenLayers.Strategy, 
    1212             "new OpenLayers.Strategy returns object" ); 
    1313        t.eq(strategy.options, options, "constructor sets this.options"); 
     14        t.eq(strategy.active, false, "constructor sets this.active to false"); 
     15        t.eq(strategy.autoActivate, true, "constructor does not modify this.autoActivate"); 
     16        t.eq(strategy.autoDestroy, true, "constructor does not modify this.autoDestroy"); 
    1417    } 
    1518     
    1619    function test_destroy(t) { 
     
    2326        t.eq(strategy.layer, null, "destroy nullify protocol.layer"); 
    2427    } 
    2528 
     29    function test_activate(t) { 
     30        t.plan(4); 
     31        var strategy = new OpenLayers.Strategy({ 
     32            layer: 'foo' 
     33        }); 
     34 
     35        var ret; 
     36        ret = strategy.activate(); 
     37 
     38        t.eq(strategy.active, true, "activate sets this.active to true on first call"); 
     39        t.eq(ret, true, "activate returns true on first call"); 
     40 
     41        ret = strategy.activate(); 
     42 
     43        t.eq(strategy.active, true, "activate does not modify this.active on second call"); 
     44        t.eq(ret, false, "activate returns false on second call"); 
     45    } 
     46 
     47    function test_deactivate(t) { 
     48        t.plan(4); 
     49        var strategy = new OpenLayers.Strategy({ 
     50            layer: 'foo' 
     51        }); 
     52        strategy.activate(); 
     53 
     54        var ret; 
     55        ret = strategy.deactivate(); 
     56 
     57        t.eq(strategy.active, false, "deactivate sets this.active to false on first call"); 
     58        t.eq(ret, true, "deactivate returns true on first call"); 
     59 
     60        ret = strategy.deactivate(); 
     61 
     62        t.eq(strategy.active, false, "deactivate does not modify this.active on second call"); 
     63        t.eq(ret, false, "deactivate returns false on second call"); 
     64    } 
     65 
    2666  </script> 
    2767</head> 
    2868<body> 
  • lib/OpenLayers/Layer/Vector.js

    old new  
    229229     */ 
    230230    destroy: function() { 
    231231        if (this.stategies) { 
    232             for(var i=0, len=this.strategies.length; i<len; i++) { 
    233                 this.strategies[i].destroy(); 
     232            var strategy, i, len; 
     233            for(i=0, len=this.strategies.length; i<len; i++) { 
     234                strategy = this.strategies[i]; 
     235                if(strategy.autoDestroy) { 
     236                    strategy.destroy(); 
     237                } 
    234238            } 
    235239            this.strategies = null; 
    236240        } 
    237241        if (this.protocol) { 
    238             this.protocol.destroy(); 
     242            if(this.protocol.autoDestroy) { 
     243                this.protocol.destroy(); 
     244            } 
    239245            this.protocol = null; 
    240246        } 
    241247        this.destroyFeatures(); 
     
    296302            this.renderer.setSize(this.map.getSize()); 
    297303        } 
    298304        if(this.strategies) { 
    299             for(var i=0, len=this.strategies.length; i<len; i++) { 
    300                 this.strategies[i].activate(); 
     305            var strategy, i, len; 
     306            for(i=0, len=this.strategies.length; i<len; i++) { 
     307                strategy = this.strategies[i]; 
     308                if(strategy.autoActivate) { 
     309                    strategy.activate(); 
     310                } 
    301311            } 
    302312        } 
    303313    }, 
     314 
     315    /** 
     316     * Method: removeMap 
     317     * The layer has been removed from the map. 
     318     * 
     319     * Parameters: 
     320     * map - {<OpenLayers.Map>} 
     321     */ 
     322    removeMap: function(map) { 
     323        if(this.strategies) { 
     324            var strategy, i, len; 
     325            for(i=0, len=this.strategies.length; i<len; i++) { 
     326                strategy = this.strategies[i]; 
     327                if(strategy.autoActivate) { 
     328                    strategy.deactivate(); 
     329                } 
     330            } 
     331        } 
     332    }, 
    304333     
    305334    /** 
    306335     * Method: onMapResize 
  • lib/OpenLayers/Protocol.js

    old new  
    2020     * Any options sent to the constructor. 
    2121     */ 
    2222    options: null, 
    23      
     23 
    2424    /** 
     25     * Property: autoDestroy 
     26     * {Boolean} The creator of the protocol can set autoDestroy to false 
     27     *      to fully control when the protocol is destroyed. Defaults to 
     28     *      true. 
     29     */ 
     30    autoDestroy: true, 
     31    
     32    /** 
    2533     * Constructor: OpenLayers.Protocol 
    2634     * Abstract class for vector protocols.  Create instances of a subclass. 
    2735     * 
  • lib/OpenLayers/Strategy.js

    old new  
    2121     */ 
    2222    options: null, 
    2323 
     24    /**  
     25     * Property: active  
     26     * {Boolean} The control is active. 
     27     */ 
     28    active: null, 
     29 
    2430    /** 
     31     * Property: autoActivate 
     32     * {Boolean} The creator of the strategy can set autoActivate to false 
     33     *      to fully control when the protocol is activated and deactivated. 
     34     *      Defaults to true. 
     35     */ 
     36    autoActivate: true, 
     37 
     38    /** 
     39     * Property: autoDestroy 
     40     * {Boolean} The creator of the strategy can set autoDestroy to false 
     41     *      to fully control when the strategy is destroyed. Defaults to 
     42     *      true. 
     43     */ 
     44    autoDestroy: true, 
     45 
     46    /** 
    2547     * Constructor: OpenLayers.Strategy 
    2648     * Abstract class for vector strategies.  Create instances of a subclass. 
    2749     * 
     
    3254    initialize: function(options) { 
    3355        OpenLayers.Util.extend(this, options); 
    3456        this.options = options; 
     57        this.active = false; 
    3558    }, 
    3659     
    3760    /** 
     
    5679    /** 
    5780     * Method: activate 
    5881     * Activate the strategy.  Register any listeners, do appropriate setup. 
     82     * 
     83     * Returns: 
     84     * {Boolean} True if the strategy was effectively deactivated and false 
     85     *     if it was already activated. 
    5986     */ 
    6087    activate: function() { 
     88        if (!this.active) { 
     89            this.active = true; 
     90            return true; 
     91        } 
     92        return false; 
    6193    }, 
    6294     
    6395    /** 
    6496     * Method: deactivate 
    6597     * Deactivate the strategy.  Unregister any listeners, do appropriate 
    6698     *     tear-down. 
     99     * 
     100     * Returns: 
     101     * {Boolean} True if the strategy was effectively activated and false 
     102     *     if it was already deactivated. 
    67103     */ 
    68104    deactivate: function() { 
     105        if (this.active) { 
     106            this.active = false; 
     107            return true; 
     108        } 
     109        return false; 
    69110    }, 
    70111    
    71112    CLASS_NAME: "OpenLayers.Strategy"