Changeset 6175
- Timestamp:
- 02/09/08 14:24:48 (10 months ago)
- Files:
-
- sandbox/ahocevar/styleMap/examples/navigation-history.html (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Control.js (modified) (5 diffs)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Control/NavigationHistory.js (modified) (7 diffs)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Control/Panel.js (modified) (5 diffs)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Control/SelectFeature.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Grid.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/HTTPRequest.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Vector.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WFS.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WMS.js (modified) (1 diff)
- sandbox/ahocevar/styleMap/lib/OpenLayers/Map.js (modified) (2 diffs)
- sandbox/ahocevar/styleMap/tests/Control/test_ModifyFeature.html (modified) (1 diff)
- sandbox/ahocevar/styleMap/tests/Control/test_Navigation.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/ahocevar/styleMap/examples/navigation-history.html
r6166 r6175 37 37 map = new OpenLayers.Map('map'); 38 38 39 // set any application specific behavior here 40 // this will become unnecessary when controls have better event handling 41 var previousOptions = { 42 onActivate: function() {panel.redraw();}, 43 onDeactivate: function() {panel.redraw();} 44 }; 45 var nextOptions = { 46 onActivate: function() {panel.redraw();}, 47 onDeactivate: function() {panel.redraw();} 48 }; 49 var options = { 50 previousOptions: previousOptions, 51 nextOptions: nextOptions 52 }; 53 nav = new OpenLayers.Control.NavigationHistory(options); 39 nav = new OpenLayers.Control.NavigationHistory(); 40 // parent control must be added to the map 54 41 map.addControl(nav); 55 42 sandbox/ahocevar/styleMap/lib/OpenLayers/Control.js
r6106 r6175 105 105 handler: null, 106 106 107 /** 108 * Property: events 109 * {<OpenLayers.Events>} Events instance for triggering control specific 110 * events. 111 */ 112 events: null, 113 114 /** 115 * Constant: EVENT_TYPES 116 * {Array(String)} Supported application event types. Register a listener 117 * for a particular event with the following syntax: 118 * (code) 119 * control.events.register(type, obj, listener); 120 * (end) 121 * 122 * Listeners will be called with a reference to an event object. The 123 * properties of this event depends on exactly what happened. 124 * 125 * All event objects have at least the following properties: 126 * - *object* {Object} A reference to control.events.object (a reference 127 * to the control). 128 * - *element* {DOMElement} A reference to control.events.element (which 129 * will be null unless documented otherwise). 130 * 131 * Supported map event types: 132 * - *activate* Triggered when activated. 133 * - *deactivate* Triggered when deactivated. 134 */ 135 EVENT_TYPES: ["activate", "deactivate"], 136 107 137 /** 108 138 * Constructor: OpenLayers.Control … … 125 155 OpenLayers.Util.extend(this, options); 126 156 157 this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES); 127 158 this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 128 159 }, … … 135 166 */ 136 167 destroy: function () { 168 this.events.destroy(); 169 this.events = null; 137 170 // eliminate circular references 138 171 if (this.handler) { … … 233 266 } 234 267 this.active = true; 268 this.events.triggerEvent("activate"); 235 269 return true; 236 270 }, … … 251 285 } 252 286 this.active = false; 287 this.events.triggerEvent("deactivate"); 253 288 return true; 254 289 } sandbox/ahocevar/styleMap/lib/OpenLayers/Control/NavigationHistory.js
r6166 r6175 81 81 82 82 /** 83 * Property: events84 * {<OpenLayers.Events>} An events object that will be used for registering85 * listeners. Defaults to the map events for this control.86 */87 events: null,88 89 /**90 83 * Property: registry 91 84 * {Object} An object with keys corresponding to event types. Values … … 145 138 var previousOptions = { 146 139 trigger: OpenLayers.Function.bind(this.previousTrigger, this), 147 displayClass: this.displayClass + "Previous", 148 onActivate: function() {}, 149 onDeactivate: function() {} 140 displayClass: this.displayClass + "Previous" 150 141 }; 151 142 if(options) { … … 156 147 var nextOptions = { 157 148 trigger: OpenLayers.Function.bind(this.nextTrigger, this), 158 displayClass: this.displayClass + "Next", 159 onActivate: function() {}, 160 onDeactivate: function() {} 149 displayClass: this.displayClass + "Next" 161 150 }; 162 151 if(options) { … … 180 169 if(state && !this.previous.active) { 181 170 this.previous.activate(); 182 this.previous.onActivate();183 171 } else if(!state && this.previous.active) { 184 172 this.previous.deactivate(); 185 this.previous.onDeactivate();186 173 } 187 174 }, … … 200 187 if(state && !this.next.active) { 201 188 this.next.activate(); 202 this.next.onActivate();203 189 } else if(!state && this.next.active) { 204 190 this.next.deactivate(); 205 this.next.onDeactivate();206 191 } 207 192 }, … … 365 350 this.setListeners(); 366 351 } 367 if(!this.events) {368 this.events = this.map.events;369 }370 352 for(var type in this.listeners) { 371 this. events.register(type, this, this.listeners[type]);353 this.map.events.register(type, this, this.listeners[type]); 372 354 } 373 355 activated = true; … … 403 385 if(OpenLayers.Control.prototype.deactivate.apply(this)) { 404 386 for(var type in this.listeners) { 405 this. events.unregister(387 this.map.events.unregister( 406 388 type, this, this.listeners[type] 407 389 ); sandbox/ahocevar/styleMap/lib/OpenLayers/Control/Panel.js
r5910 r6175 46 46 OpenLayers.Control.prototype.destroy.apply(this, arguments); 47 47 for(var i = this.controls.length - 1 ; i >= 0; i--) { 48 if(this.controls[i].events) { 49 this.controls[i].events.un({ 50 "activate": this.redraw, 51 "deactivate": this.redraw, 52 scope: this 53 }); 54 } 48 55 OpenLayers.Event.stopObservingElement(this.controls[i].panel_div); 49 56 this.controls[i].panel_div = null; … … 76 83 this.controls[i].deactivate(); 77 84 } 78 this.redraw();79 85 return true; 80 86 } else { … … 94 100 this.map.addControl(this.controls[i]); 95 101 this.controls[i].deactivate(); 102 this.controls[i].events.on({ 103 "activate": this.redraw, 104 "deactivate": this.redraw, 105 scope: this 106 }); 96 107 } 97 108 this.activate(); … … 146 157 } 147 158 } 148 this.redraw();149 159 }, 150 160 … … 186 196 this.map.addControl(controls[i]); 187 197 controls[i].deactivate(); 198 controls[i].events.on({ 199 "activate": this.redraw, 200 "deactivate": this.redraw, 201 scope: this 202 }); 188 203 } 189 204 this.redraw(); sandbox/ahocevar/styleMap/lib/OpenLayers/Control/SelectFeature.js
r6166 r6175 262 262 this.layer.events.triggerEvent("featureselected", {feature: feature}); 263 263 this.layer.events.triggerEvent("featureselected", {feature: feature}); 264 this.layer.events.triggerEvent("featureselected", {feature: feature}); 265 this.layer.events.triggerEvent("featureselected", {feature: feature}); 266 this.layer.events.triggerEvent("featureselected", {feature: feature}); 264 267 this.onSelect(feature); 265 268 }, sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Grid.js
r6152 r6175 671 671 this.clearGrid(); 672 672 this.setTileSize(); 673 this.initSingleTile(this.map.getExtent());674 673 } 675 674 }, sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/HTTPRequest.js
r5614 r6175 116 116 * Parameters: 117 117 * newParams - {Object} 118 * 119 * Returns: 120 * redrawn: {Boolean} whether the layer was actually redrawn. 118 121 */ 119 122 mergeNewParams:function(newParams) { 120 123 this.params = OpenLayers.Util.extend(this.params, newParams); 121 this.redraw(); 124 return this.redraw(); 125 }, 126 127 /** 128 * APIMethod: redraw 129 * Redraws the layer. Returns true if the layer was redrawn, false if not. 130 * 131 * Parameters: 132 * force - {Boolean} Force redraw by adding random parameter. 133 * 134 * Returns: 135 * {Boolean} The layer was redrawn. 136 */ 137 redraw: function(force) { 138 if (force) { 139 return this.mergeNewParams({"_olSalt": Math.random()}); 140 } else { 141 return OpenLayers.Layer.prototype.redraw.apply(this, []); 142 } 122 143 }, 123 144 sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Vector.js
r6165 r6175 268 268 moveTo: function(bounds, zoomChanged, dragging) { 269 269 OpenLayers.Layer.prototype.moveTo.apply(this, arguments); 270 270 271 271 if (!dragging) { 272 this.div.style.left = - parseInt(this.map.layerContainerDiv.style.left) + "px"; 273 this.div.style.top = - parseInt(this.map.layerContainerDiv.style.top) + "px"; 272 this.renderer.root.style.visibility = "hidden"; 273 274 this.div.style.left = -parseInt(this.map.layerContainerDiv.style.left) + "px"; 275 this.div.style.top = -parseInt(this.map.layerContainerDiv.style.top) + "px"; 274 276 var extent = this.map.getExtent(); 275 277 this.renderer.setExtent(extent); 276 } 277 278 279 this.renderer.root.style.visibility = "visible"; 280 } 281 278 282 if (!this.drawn || zoomChanged) { 279 283 this.drawn = true; sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WFS.js
r6152 r6175 385 385 var upperParams = OpenLayers.Util.upperCaseObject(newParams); 386 386 var newArguments = [upperParams]; 387 OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,387 return OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, 388 388 newArguments); 389 389 }, sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WMS.js
r5614 r6175 194 194 var upperParams = OpenLayers.Util.upperCaseObject(newParams); 195 195 var newArguments = [upperParams]; 196 OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,196 return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, 197 197 newArguments); 198 198 }, sandbox/ahocevar/styleMap/lib/OpenLayers/Map.js
r6152 r6175 486 486 } 487 487 488 if (this.controls != null) { 489 for (var i = this.controls.length - 1; i>=0; --i) { 490 this.controls[i].destroy(); 491 } 492 this.controls = null; 493 } 488 494 if (this.layers != null) { 489 495 for (var i = this.layers.length - 1; i>=0; --i) { … … 493 499 } 494 500 this.layers = null; 495 }496 if (this.controls != null) {497 for (var i = this.controls.length - 1; i>=0; --i) {498 this.controls[i].destroy();499 }500 this.controls = null;501 501 } 502 502 if (this.viewPortDiv) { sandbox/ahocevar/styleMap/tests/Control/test_ModifyFeature.html
r6152 r6175 6 6 function test_ModifyFeature_constructor(t) { 7 7 t.plan(3); 8 var layer = {name: "foo", styleMap: {createSymbolizer: function(){}}};9 8 var layer = { 10 9 styleMap: {createSymbolizer: function(){}}, sandbox/ahocevar/styleMap/tests/Control/test_Navigation.html
r6131 r6175 18 18 19 19 function test_Control_Navigation_destroy (t) { 20 t.plan( 9);20 t.plan(10); 21 21 22 22 var temp = OpenLayers.Control.prototype.destroy; … … 27 27 28 28 var control = { 29 events: { 30 destroy: function() { 31 t.ok(true, "events destroyed"); 32 } 33 }, 29 34 'deactivate': function() { 30 35 t.ok(true, "navigation control deactivated before being destroyed");
