Ticket #1649: patch-1649-r7658-A0.diff
| File patch-1649-r7658-A0.diff, 5.1 kB (added by elemoine, 5 months ago) |
|---|
-
tests/Strategy.html
old new 4 4 <script type="text/javascript"> 5 5 6 6 function test_initialize(t) { 7 t.plan( 2);7 t.plan(4); 8 8 var options = {}; 9 9 var strategy = new OpenLayers.Strategy(options); 10 10 11 11 t.ok(strategy instanceof OpenLayers.Strategy, 12 12 "new OpenLayers.Strategy returns object" ); 13 13 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"); 14 16 } 15 17 16 18 function test_destroy(t) { … … 23 25 t.eq(strategy.layer, null, "destroy nullify protocol.layer"); 24 26 } 25 27 28 function test_activate(t) { 29 t.plan(4); 30 var strategy = new OpenLayers.Strategy({ 31 layer: 'foo' 32 }); 33 34 var ret; 35 ret = strategy.activate(); 36 37 t.eq(strategy.active, true, "activate sets this.active to true on first call"); 38 t.eq(ret, true, "activate returns true on first call"); 39 40 ret = strategy.activate(); 41 42 t.eq(strategy.active, true, "activate does not modify this.active on second call"); 43 t.eq(ret, false, "activate returns false on second call"); 44 } 45 46 function test_deactivate(t) { 47 t.plan(4); 48 var strategy = new OpenLayers.Strategy({ 49 layer: 'foo' 50 }); 51 strategy.activate(); 52 53 var ret; 54 ret = strategy.deactivate(); 55 56 t.eq(strategy.active, false, "deactivate sets this.active to false on first call"); 57 t.eq(ret, true, "deactivate returns true on first call"); 58 59 ret = strategy.deactivate(); 60 61 t.eq(strategy.active, false, "deactivate does not modify this.active on second call"); 62 t.eq(ret, false, "deactivate returns false on second call"); 63 } 64 26 65 </script> 27 66 </head> 28 67 <body> -
lib/OpenLayers/Layer/Vector.js
old new 296 296 this.renderer.setSize(this.map.getSize()); 297 297 } 298 298 if(this.strategies) { 299 for(var i=0, len=this.strategies.length; i<len; i++) { 300 this.strategies[i].activate(); 299 var strategy, i, len; 300 for(i=0, len=this.strategies.length; i<len; i++) { 301 strategy = this.strategies[i]; 302 if(strategy.autoActivate) { 303 strategy.activate(); 304 } 301 305 } 302 306 } 303 307 }, 308 309 /** 310 * Method: removeMap 311 * The layer has been removed from the map. 312 * 313 * Parameters: 314 * map - {<OpenLayers.Map>} 315 */ 316 removeMap: function(map) { 317 if(this.strategies) { 318 var strategy, i, len; 319 for(i=0, len=this.strategies.length; i<len; i++) { 320 strategy = this.strategies[i]; 321 if(strategy.autoActivate) { 322 strategy.deactivate(); 323 } 324 } 325 } 326 }, 304 327 305 328 /** 306 329 * Method: onMapResize -
lib/OpenLayers/Strategy.js
old new 21 21 */ 22 22 options: null, 23 23 24 /** 25 * Property: active 26 * {Boolean} The control is active. 27 */ 28 active: null, 29 24 30 /** 31 * Property: autoActivate 32 * {Boolean} True if the layer including the strategy is responsible 33 * for activating and deactivating the strategy, false otherwise. 34 * Defaults to true. 35 */ 36 autoActivate: true, 37 38 /** 25 39 * Constructor: OpenLayers.Strategy 26 40 * Abstract class for vector strategies. Create instances of a subclass. 27 41 * … … 32 46 initialize: function(options) { 33 47 OpenLayers.Util.extend(this, options); 34 48 this.options = options; 49 this.active = false; 35 50 }, 36 51 37 52 /** … … 56 71 /** 57 72 * Method: activate 58 73 * Activate the strategy. Register any listeners, do appropriate setup. 74 * 75 * Returns: 76 * {Boolean} True if the strategy was effectively deactivated and false 77 * if it was already activated. 59 78 */ 60 79 activate: function() { 80 if (!this.active) { 81 this.active = true; 82 return true; 83 } 84 return false; 61 85 }, 62 86 63 87 /** 64 88 * Method: deactivate 65 89 * Deactivate the strategy. Unregister any listeners, do appropriate 66 90 * tear-down. 91 * 92 * Returns: 93 * {Boolean} True if the strategy was effectively activated and false 94 * if it was already deactivated. 67 95 */ 68 96 deactivate: function() { 97 if (this.active) { 98 this.active = false; 99 return true; 100 } 101 return false; 69 102 }, 70 103 71 104 CLASS_NAME: "OpenLayers.Strategy"
