- Timestamp:
- 08/05/08 09:59:12 (2 weeks ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer/Vector.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Protocol.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Strategy.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Strategy/Fixed.js (modified) (1 diff)
- trunk/openlayers/tests/Protocol.html (modified) (2 diffs)
- trunk/openlayers/tests/Strategy.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer/Vector.js
r7703 r7708 230 230 destroy: function() { 231 231 if (this.strategies) { 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 } 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 } … … 297 303 } 298 304 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 } 311 } 312 } 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, 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 } 301 330 } 302 331 } trunk/openlayers/lib/OpenLayers/Protocol.js
r7650 r7708 21 21 */ 22 22 options: null, 23 23 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 24 32 /** 25 33 * Constructor: OpenLayers.Protocol trunk/openlayers/lib/OpenLayers/Strategy.js
r7690 r7708 22 22 options: null, 23 23 24 /** 25 * Property: active 26 * {Boolean} The control is active. 27 */ 28 active: null, 29 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 24 46 /** 25 47 * Constructor: OpenLayers.Strategy … … 33 55 OpenLayers.Util.extend(this, options); 34 56 this.options = options; 57 // set the active property here, so that user cannot override it 58 this.active = false; 35 59 }, 36 60 … … 58 82 * Method: activate 59 83 * Activate the strategy. Register any listeners, do appropriate setup. 84 * 85 * Returns: 86 * {Boolean} True if the strategy was successfully activated or false if 87 * the strategy was already active. 60 88 */ 61 89 activate: function() { 90 if (!this.active) { 91 this.active = true; 92 return true; 93 } 94 return false; 62 95 }, 63 96 … … 66 99 * Deactivate the strategy. Unregister any listeners, do appropriate 67 100 * tear-down. 101 * 102 * Returns: 103 * {Boolean} True if the strategy was successfully deactivated or false if 104 * the strategy was already inactive. 68 105 */ 69 106 deactivate: function() { 107 if (this.active) { 108 this.active = false; 109 return true; 110 } 111 return false; 70 112 }, 71 113 trunk/openlayers/lib/OpenLayers/Strategy/Fixed.js
r7707 r7708 40 40 * Activate the strategy: reads all features from the protocol and add them 41 41 * to the layer. 42 * 43 * Returns: 44 * {Boolean} True if the strategy was successfully activated or false if 45 * the strategy was already active. 42 46 */ 43 47 activate: function() { 44 OpenLayers.Strategy.prototype.activate.apply(this, arguments); 45 this.layer.protocol.read({ 46 callback: this.merge, 47 scope: this 48 }); 48 if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) { 49 this.layer.protocol.read({ 50 callback: this.merge, 51 scope: this 52 }); 53 return true; 54 } 55 return false; 49 56 }, 50 57 trunk/openlayers/tests/Protocol.html
r7687 r7708 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); … … 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 trunk/openlayers/tests/Strategy.html
r7706 r7708 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); … … 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 … … 47 50 } 48 51 52 function test_activate(t) { 53 t.plan(4); 54 var strategy = new OpenLayers.Strategy({ 55 layer: 'foo' 56 }); 57 58 var ret; 59 ret = strategy.activate(); 60 61 t.eq(strategy.active, true, "activate sets this.active to true on first call"); 62 t.eq(ret, true, "activate returns true on first call"); 63 64 ret = strategy.activate(); 65 66 t.eq(strategy.active, true, "activate does not modify this.active on second call"); 67 t.eq(ret, false, "activate returns false on second call"); 68 } 69 70 function test_deactivate(t) { 71 t.plan(4); 72 var strategy = new OpenLayers.Strategy({ 73 layer: 'foo' 74 }); 75 strategy.activate(); 76 77 var ret; 78 ret = strategy.deactivate(); 79 80 t.eq(strategy.active, false, "deactivate sets this.active to false on first call"); 81 t.eq(ret, true, "deactivate returns true on first call"); 82 83 ret = strategy.deactivate(); 84 85 t.eq(strategy.active, false, "deactivate does not modify this.active on second call"); 86 t.eq(ret, false, "deactivate returns false on second call"); 87 } 88 49 89 </script> 50 90 </head>
