Ticket #1649: patch-1649-r7658-C0.diff
| File patch-1649-r7658-C0.diff, 10.9 kB (added by fredj, 5 months ago) |
|---|
-
tests/Protocol.html
old new 4 4 <script type="text/javascript"> 5 5 6 6 function test_initialize(t) { 7 t.plan( 2);7 t.plan(3); 8 8 var options = {}; 9 9 var protocol = new OpenLayers.Protocol(options); 10 10 11 11 t.ok(protocol instanceof OpenLayers.Protocol, 12 12 "new OpenLayers.Protocol returns object" ); 13 13 t.eq(protocol.options, options, "constructor sets this.options"); 14 t.eq(protocol.autoDestroy, true, "constructor does not modify this.autoDestroy"); 14 15 } 15 16 16 17 function test_destroy(t) { -
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(5); 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"); 16 t.eq(strategy.autoDestroy, true, "constructor does not modify this.autoDestroy"); 14 17 } 15 18 16 19 function test_destroy(t) { … … 25 28 t.eq(strategy.options, null, "destroy nullify protocol.options"); 26 29 } 27 30 31 function test_activate(t) { 32 t.plan(4); 33 var strategy = new OpenLayers.Strategy({ 34 layer: 'foo' 35 }); 36 37 var ret = strategy.activate(); 38 39 t.eq(strategy.active, true, "activate sets this.active to true on first call"); 40 t.eq(ret, true, "activate returns true on first call"); 41 42 ret = strategy.activate(); 43 44 t.eq(strategy.active, true, "activate does not modify this.active on second call"); 45 t.eq(ret, false, "activate returns false on second call"); 46 } 47 48 function test_deactivate(t) { 49 t.plan(4); 50 var strategy = new OpenLayers.Strategy({ 51 layer: 'foo' 52 }); 53 strategy.activate(); 54 55 var 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 28 66 </script> 29 67 </head> 30 68 <body> -
tests/Layer/Vector.html
old new 6 6 var name = "Vector Layer"; 7 7 8 8 function test_Layer_Vector_constructor(t) { 9 t.plan( 3);9 t.plan(4); 10 10 11 var layer = new OpenLayers.Layer.Vector(name); 11 var options = {protocol: new OpenLayers.Protocol(), 12 strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]} 13 var layer = new OpenLayers.Layer.Vector(name, options); 14 12 15 t.ok(layer instanceof OpenLayers.Layer.Vector, "new OpenLayers.Layer.Vector returns correct object" ); 13 16 t.eq(layer.name, name, "layer name is correctly set"); 14 17 t.ok(layer.renderer.CLASS_NAME, "layer has a renderer"); 15 18 19 t.ok((layer.name == layer.strategies[0].layer.name) && 20 (layer.strategies[0].layer.name == layer.strategies[1].layer.name), 21 "setLayer was called on strategies"); 16 22 } 17 23 18 24 function test_Layer_Vector_addFeatures(t) { … … 216 222 } 217 223 218 224 function test_Layer_Vector_destroy (t) { 219 t.plan(2); 220 layer = new OpenLayers.Layer.Vector(name); 225 t.plan(4); 226 227 var options = {protocol: new OpenLayers.Protocol(), 228 strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]} 229 var layer = new OpenLayers.Layer.Vector(name, options); 221 230 var map = new OpenLayers.Map('map'); 222 231 map.addLayer(layer); 223 232 layer.destroy(); 224 233 t.eq(layer.map, null, "layer.map is null after destroy"); 225 t.eq(layer.getFeatureFromEvent({'target':'map'}), null, "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed."); 234 t.eq(layer.getFeatureFromEvent({'target':'map'}), null, 235 "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed."); 236 237 t.eq(layer.protocol, null, "layer.protocol is null after destroy"); 238 t.eq(layer.strategies, null, "layer.strategies is null after destroy"); 226 239 } 227 240 241 function test_Layer_Vector_destroy_no_autoDestroy (t) { 242 t.plan(4); 243 244 var options = {protocol: new OpenLayers.Protocol({autoDestroy: false}), 245 strategies: [new OpenLayers.Strategy({autoDestroy: false}), 246 new OpenLayers.Strategy({autoDestroy: false})]} 247 var layer = new OpenLayers.Layer.Vector(name, options); 248 var map = new OpenLayers.Map('map'); 249 map.addLayer(layer); 250 layer.destroy(); 251 252 t.ok(options.protocol.options != null, "options.protocol.destroy was not called") 253 t.ok(options.strategies[0].layer != null && 254 options.strategies[1].layer != null, "options.strategies.destroy was not called") 255 t.eq(layer.protocol, null, "layer.protocol is null after destroy"); 256 t.eq(layer.strategies, null, "layer.strategies is null after destroy"); 257 } 258 228 259 function test_Layer_Vector_externalGraphic(t) { 229 260 t.plan(11); 230 261 var layer = new OpenLayers.Layer.Vector("Test Layer", {isBaseLayer: true}); -
lib/OpenLayers/Layer/Vector.js
old new 228 228 * Destroy this layer 229 229 */ 230 230 destroy: function() { 231 if (this.stategies) { 232 for(var i=0, len=this.strategies.length; i<len; i++) { 233 this.strategies[i].destroy(); 231 if (this.strategies) { 232 var strategy; 233 for (var i = 0, len = this.strategies.length; i < len; i++) { 234 strategy = this.strategies[i]; 235 if (strategy.autoDestroy) { 236 strategy.destroy(); 237 } 234 238 } 235 239 this.strategies = null; 236 240 } 237 241 if (this.protocol) { 238 this.protocol.destroy(); 242 if (this.protocol.autoDestroy) { 243 this.protocol.destroy(); 244 } 239 245 this.protocol = null; 240 246 } 241 247 this.destroyFeatures(); … … 295 301 this.renderer.map = this.map; 296 302 this.renderer.setSize(this.map.getSize()); 297 303 } 298 if(this.strategies) { 299 for(var i=0, len=this.strategies.length; i<len; i++) { 300 this.strategies[i].activate(); 304 if (this.strategies) { 305 var strategy; 306 for(var i = 0, len = this.strategies.length; i < len; i++) { 307 strategy = this.strategies[i]; 308 if (strategy.autoActivate) { 309 strategy.activate(); 310 } 301 311 } 302 312 } 303 313 }, 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; 325 for(var 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 }, 304 333 305 334 /** 306 335 * Method: onMapResize -
lib/OpenLayers/Protocol.js
old new 20 20 * Any options sent to the constructor. 21 21 */ 22 22 options: null, 23 23 24 24 /** 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 /** 25 33 * Constructor: OpenLayers.Protocol 26 34 * Abstract class for vector protocols. Create instances of a subclass. 27 35 * -
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} 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 /** 25 47 * Constructor: OpenLayers.Strategy 26 48 * Abstract class for vector strategies. Create instances of a subclass. 27 49 * … … 32 54 initialize: function(options) { 33 55 OpenLayers.Util.extend(this, options); 34 56 this.options = options; 57 this.active = false; 35 58 }, 36 59 37 60 /** … … 57 80 /** 58 81 * Method: activate 59 82 * Activate the strategy. Register any listeners, do appropriate setup. 83 * 84 * Returns: 85 * {Boolean} True if the strategy was effectively deactivated and false 86 * if it was already activated. 60 87 */ 61 88 activate: function() { 89 if (!this.active) { 90 this.active = true; 91 return true; 92 } 93 return false; 62 94 }, 63 95 64 96 /** 65 97 * Method: deactivate 66 98 * Deactivate the strategy. Unregister any listeners, do appropriate 67 99 * tear-down. 100 * 101 * Returns: 102 * {Boolean} True if the strategy was effectively activated and false 103 * if it was already deactivated. 68 104 */ 69 105 deactivate: function() { 106 if (this.active) { 107 this.active = false; 108 return true; 109 } 110 return false; 70 111 }, 71 112 72 113 CLASS_NAME: "OpenLayers.Strategy"
