Ticket #1343: events.patch
| File events.patch, 35.7 kB (added by tschaub, 1 year ago) |
|---|
-
tests/Control/test_SelectFeature.html
old new 78 78 // mock up layer 79 79 var layer = { 80 80 selectedFeatures: [], 81 drawFeature: function() {} 81 drawFeature: function() {}, 82 events: { 83 triggerEvent: function() {} 84 } 82 85 }; 83 86 // mock up active control 84 87 var control = new OpenLayers.Control.SelectFeature(layer); -
tests/Control/test_ModifyFeature.html
old new 5 5 6 6 function test_ModifyFeature_constructor(t) { 7 7 t.plan(3); 8 var layer = "foo"; 8 var layer = { 9 events: { 10 on: function() {} 11 } 12 }; 9 13 var options = { 10 14 geometryTypes: "bar" 11 15 }; 12 16 var control = new OpenLayers.Control.ModifyFeature(layer, options); 13 17 14 t. eq(control.layer, "foo",18 t.ok(control.layer == layer, 15 19 "constructor sets layer correctly"); 16 20 t.eq(control.selectControl.geometryTypes, "bar", 17 21 "constructor sets options correctly on feature handler"); … … 72 76 * In the future, feature deletion may be added to the control. 73 77 */ 74 78 75 var control = new OpenLayers.Control.ModifyFeature({style: null}); 79 var control = new OpenLayers.Control.ModifyFeature({ 80 style: null, 81 events: { 82 on: function() {} 83 } 84 }); 76 85 var delKey = 46; 77 86 var dKey = 100; 78 87 control.deleteCodes = [delKey, dKey]; … … 197 206 layer.destroyFeatures = function(verts) { 198 207 t.ok(verts == 'b', "Virtual verts destroyed correctly"); 199 208 } 200 control.unselectFeature( fakeFeature);209 control.unselectFeature({feature: fakeFeature}); 201 210 t.eq(control.feature, null, "feature is set to null"); 202 211 } 203 212 function test_ModifyFeature_selectFeature(t) { … … 216 225 var fakeFeature = {'id':'myFakeFeature','geometry':{'CLASS_NAME':'OpenLayers.Geometry.Point'}}; 217 226 218 227 // Points don't call collectVertices 219 control.selectFeature( fakeFeature);228 control.selectFeature({feature: fakeFeature}); 220 229 221 230 control.collectVertices = function() { 222 231 t.ok(true, "collectVertices called"); … … 232 241 fakeFeature.geometry.CLASS_NAME='OpenLayers.Geometry.Polygon'; 233 242 234 243 // OnSelect calls collectVertices and passes features to layer 235 control.selectFeature( fakeFeature);244 control.selectFeature({feature: fakeFeature}); 236 245 237 246 control.vertices = ['a']; 238 247 control.virtualVertices = ['b']; … … 244 253 } 245 254 246 255 // Features are removed whenever they exist 247 control.selectFeature( fakeFeature);256 control.selectFeature({feature: fakeFeature}); 248 257 249 258 } 250 259 … … 389 398 t.eq(feature.id, testFeature.id, 390 399 "onModificationStart called with the right feature"); 391 400 }; 392 control.selectFeature( testFeature);401 control.selectFeature({feature: testFeature}); 393 402 } 394 403 395 404 function test_ModifyFeature_onModification(t) { … … 450 459 t.eq(feature.id, testFeature.id, 451 460 "onModificationEnd called with the right feature"); 452 461 }; 453 control.unselectFeature( testFeature);462 control.unselectFeature({feature: testFeature}); 454 463 } 455 464 456 465 -
tests/test_Events.html
old new 205 205 eventTypes = ["something"]; 206 206 events = new OpenLayers.Events(null, null, eventTypes); 207 207 var instance = {id: Math.random()}; 208 var listener = function( ) {208 var listener = function(obj) { 209 209 t.eq(this.id, instance.id, 210 210 "listener called with proper scope"); 211 t.eq(arguments [0].id, evt.id,212 "listener called with evt as first arg");213 t.eq( arguments[1], "arg1",214 "listener called with correct extra arg1");215 t.eq( arguments[2], "arg2",216 " listener called with correct extra arg2");211 t.eq(arguments.length, 1, 212 "listener called with a single argument"); 213 t.eq(typeof arguments, "object", 214 "listener called with an object"); 215 t.eq(obj.foo, evt.foo, 216 "foo property set on the layer"); 217 217 }; 218 218 events.register("something", instance, listener); 219 var evt = {id: Math.random()}; 220 events.triggerEvent("something", evt, ["arg1", "arg2", "arg3"]); 219 var evt = { 220 id: Math.random(), 221 "foo": "bar" 222 }; 223 events.triggerEvent("something", evt); 221 224 events.unregister("something", instance, listener); 222 225 223 226 // test return from triggerEvent -
tests/Layer/test_Grid.html
old new 499 499 events: { 500 500 unregister: function(name, obj, func) { 501 501 g_unregistered[name] = [obj, func]; 502 } 502 }, 503 un: OpenLayers.Events.prototype.un 503 504 } 504 505 } 505 506 -
lib/OpenLayers/Map.js
old new 32 32 * map.events.register(type, obj, listener); 33 33 * (end) 34 34 * 35 * Listeners will be called with a reference to an event object. The 36 * properties of this event depends on exactly what happened. 37 * 38 * All event objects have at least the following properties: 39 * - *object* {Object} A reference to map.events.object. 40 * - *element* {DOMElement} A reference to map.events.element. 41 * 42 * Browser events have the following additional properties: 43 * - *xy* {<OpenLayers.Pixel>} The pixel location of the event (relative 44 * to the the map viewport). 45 * - other properties that come with browser events 46 * 35 47 * Supported map event types: 36 * - *addlayer* triggered after a layer has been added 37 * - *removelayer* triggered after a layer has been removed 48 * - *addlayer* triggered after a layer has been added. The event object 49 * will include a *layer* property that references the added layer. 50 * - *removelayer* triggered after a layer has been removed. The event 51 * object will include a *layer* property that references the removed 52 * layer. 38 53 * - *changelayer* triggered after a layer name change, order change, or 39 * visibility change (due to resolution thresholds) 54 * visibility change (due to resolution thresholds). Listeners will 55 * receive an event object with *layer* and *property* properties. The 56 * *layer* property will be a reference to the changed layer. The 57 * *property* property will be a key to the changed property (name, 58 * visibility, or order). 40 59 * - *movestart* triggered after the start of a drag, pan, or zoom 41 60 * - *move* triggered after each drag, pan, or zoom 42 61 * - *moveend* triggered after a drag, pan, or zoom completes … … 735 754 layer.redraw(); 736 755 } 737 756 738 this.events.triggerEvent("addlayer" );757 this.events.triggerEvent("addlayer", {layer: layer}); 739 758 }, 740 759 741 760 /** … … 808 827 809 828 this.resetLayersZIndex(); 810 829 811 this.events.triggerEvent("removelayer" );830 this.events.triggerEvent("removelayer", {layer: layer}); 812 831 }, 813 832 814 833 /** … … 860 879 for (var i = 0; i < this.layers.length; i++) { 861 880 this.setLayerZIndex(this.layers[i], i); 862 881 } 863 this.events.triggerEvent("changelayer"); 882 this.events.triggerEvent("changelayer", { 883 layer: layer, property: "order" 884 }); 864 885 } 865 886 }, 866 887 … … 933 954 this.setCenter(newCenter, newZoom, false, true); 934 955 } 935 956 936 this.events.triggerEvent("changebaselayer"); 957 this.events.triggerEvent("changebaselayer", { 958 layer: this.baseLayer 959 }); 937 960 } 938 961 } 939 962 }, … … 1453 1476 if (!inRange) { 1454 1477 layer.display(false); 1455 1478 } 1456 this.events.triggerEvent("changelayer"); 1479 this.events.triggerEvent("changelayer", { 1480 layer: layer, property: "visibility" 1481 }); 1457 1482 } 1458 1483 if (inRange && layer.visibility) { 1459 1484 layer.moveTo(bounds, zoomChanged, dragging); -
lib/OpenLayers/Popup.js
old new 403 403 registerEvents:function() { 404 404 this.events = new OpenLayers.Events(this, this.div, null, true); 405 405 406 this.events.register("mousedown", this, this.onmousedown); 407 this.events.register("mousemove", this, this.onmousemove); 408 this.events.register("mouseup", this, this.onmouseup); 409 this.events.register("click", this, this.onclick); 410 this.events.register("mouseout", this, this.onmouseout); 411 this.events.register("dblclick", this, this.ondblclick); 406 this.events.on({ 407 "mousedown": this.onmousedown, 408 "mousemove": this.onmousemove, 409 "mouseup": this.onmouseup, 410 "click": this.onclick, 411 "mouseout": this.onmouseout, 412 "dblclick": this.ondblclick, 413 scope: this 414 }); 415 412 416 }, 413 417 414 418 /** -
lib/OpenLayers/Events.js
old new 481 481 // disable dragstart in IE so that mousedown/move/up works normally 482 482 OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop); 483 483 }, 484 485 /** 486 * Method: on 487 * Convenience method for registering listeners with a common scope. 488 * 489 * Example use: 490 * (code) 491 * events.on({ 492 * "loadstart": loadStartListener, 493 * "loadend": loadEndListener, 494 * scope: object 495 * }); 496 * (end) 497 */ 498 on: function(object) { 499 for(var type in object) { 500 if(type != "scope") { 501 this.register(type, object.scope, object[type]); 502 } 503 } 504 }, 484 505 485 506 /** 486 507 * APIMethod: register … … 553 574 }, 554 575 555 576 /** 577 * Method: un 578 * Convenience method for unregistering listeners with a common scope. 579 * 580 * Example use: 581 * (code) 582 * events.un({ 583 * "loadstart": loadStartListener, 584 * "loadend": loadEndListener, 585 * scope: object 586 * }); 587 * (end) 588 */ 589 un: function(object) { 590 for(var type in object) { 591 if(type != "scope") { 592 this.unregister(type, object.scope, object[type]); 593 } 594 } 595 }, 596 597 /** 556 598 * APIMethod: unregister 557 599 * 558 600 * Parameters: … … 596 638 * Parameters: 597 639 * type - {String} 598 640 * evt - {Event} 599 * args - {Array} Optional array of arguments to call the listener with.600 641 * 601 642 * Returns: 602 643 * {Boolean} The last listener return. If a listener returns false, the 603 644 * chain of listeners will stop getting called. 604 645 */ 605 triggerEvent: function (type, evt , args) {646 triggerEvent: function (type, evt) { 606 647 607 648 // prep evt object with object & div references 608 649 if (evt == null) { … … 610 651 } 611 652 evt.object = this.object; 612 653 evt.element = this.element; 613 614 if(!args) { 615 args = [evt]; 616 } else { 617 args.unshift(evt); 618 } 619 654 620 655 // execute all callbacks registered for specified type 621 656 // get a clone of the listeners array to 622 657 // allow for splicing during callbacks … … 627 662 for (var i = 0; i < listeners.length; i++) { 628 663 var callback = listeners[i]; 629 664 // bind the context to callback.obj 630 continueChain = callback.func.apply(callback.obj, args);665 continueChain = callback.func.apply(callback.obj, [evt]); 631 666 632 667 if ((continueChain != undefined) && (continueChain == false)) { 633 668 // if callback returns false, execute no more callbacks. -
lib/OpenLayers/Control/OverviewMap.js
old new 154 154 this.minimizeDiv = null; 155 155 } 156 156 157 this.map.events.unregister('moveend', this, this.update); 158 this.map.events.unregister("changebaselayer", this, 159 this.baseLayerDraw); 157 this.map.events.un({ 158 "moveend": this.update, 159 "changebaselayer": this.baseLayerDraw, 160 scope: this 161 }); 160 162 161 163 OpenLayers.Control.prototype.destroy.apply(this, arguments); 162 164 }, -
lib/OpenLayers/Control/Attribution.js
old new 35 35 * Destroy control. 36 36 */ 37 37 destroy: function() { 38 this.map.events.unregister("removelayer", this, this.updateAttribution); 39 this.map.events.unregister("addlayer", this, this.updateAttribution); 40 this.map.events.unregister("changelayer", this, this.updateAttribution); 41 this.map.events.unregister("changebaselayer", this, this.updateAttribution); 38 this.map.events.un({ 39 "removelayer": this.updateAttribution, 40 "addlayer": this.updateAttribution, 41 "changelayer": this.updateAttribution, 42 "changebaselayer": this.updateAttribution, 43 scope: this 44 }); 42 45 43 46 OpenLayers.Control.prototype.destroy.apply(this, arguments); 44 47 }, … … 53 56 draw: function() { 54 57 OpenLayers.Control.prototype.draw.apply(this, arguments); 55 58 56 this.map.events.register('changebaselayer', this, this.updateAttribution); 57 this.map.events.register('changelayer', this, this.updateAttribution); 58 this.map.events.register('addlayer', this, this.updateAttribution); 59 this.map.events.register('removelayer', this, this.updateAttribution); 59 this.map.events.on({ 60 'changebaselayer': this.updateAttribution, 61 'changelayer': this.updateAttribution, 62 'addlayer': this.updateAttribution, 63 'removelayer': this.updateAttribution, 64 scope: this 65 }); 60 66 this.updateAttribution(); 61 67 62 68 return this.div; -
lib/OpenLayers/Control/PanZoomBar.js
old new 79 79 this.divEvents.destroy(); 80 80 this.divEvents = null; 81 81 82 this.map.events.unregister("zoomend", this, this.moveZoomBar); 83 this.map.events.unregister("changebaselayer", this, this.redraw); 82 this.map.events.un({ 83 "zoomend": this.moveZoomBar, 84 "changebaselayer": this.redraw, 85 scope: this 86 }); 84 87 85 88 OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); 86 89 }, … … 164 167 this.slider = slider; 165 168 166 169 this.sliderEvents = new OpenLayers.Events(this, slider, null, true); 167 this.sliderEvents.register("mousedown", this, this.zoomBarDown); 168 this.sliderEvents.register("mousemove", this, this.zoomBarDrag); 169 this.sliderEvents.register("mouseup", this, this.zoomBarUp); 170 this.sliderEvents.register("dblclick", this, this.doubleClick); 171 this.sliderEvents.register("click", this, this.doubleClick); 170 this.sliderEvents.on({ 171 "mousedown": this.zoomBarDown, 172 "mousemove": this.zoomBarDrag, 173 "mouseup": this.zoomBarUp, 174 "dblclick": this.doubleClick, 175 "click": this.doubleClick 176 }); 172 177 173 178 var sz = new OpenLayers.Size(); 174 179 sz.h = this.zoomStopHeight * this.map.getNumZoomLevels(); … … 194 199 this.zoombarDiv = div; 195 200 196 201 this.divEvents = new OpenLayers.Events(this, div, null, true); 197 this.divEvents.register("mousedown", this, this.divClick); 198 this.divEvents.register("mousemove", this, this.passEventToSlider); 199 this.divEvents.register("dblclick", this, this.doubleClick); 200 this.divEvents.register("click", this, this.doubleClick); 202 this.divEvents.on({ 203 "mousedown": this.divClick, 204 "mousemove": this.passEventToSlider, 205 "dblclick": this.doubleClick, 206 "click": this.doubleClick 207 }); 201 208 202 209 this.div.appendChild(div); 203 210 … … 250 257 if (!OpenLayers.Event.isLeftClick(evt)) { 251 258 return; 252 259 } 253 this.map.events.register("mousemove", this, this.passEventToSlider); 254 this.map.events.register("mouseup", this, this.passEventToSlider); 260 this.map.events.on({ 261 "mousemove": this.passEventToSlider, 262 "mouseup": this.passEventToSlider, 263 scope: this 264 }); 255 265 this.mouseDragStart = evt.xy.clone(); 256 266 this.zoomStart = evt.xy.clone(); 257 267 this.div.style.cursor = "move"; … … 298 308 } 299 309 if (this.zoomStart) { 300 310 this.div.style.cursor=""; 301 this.map.events.unregister("mouseup", this, this.passEventToSlider); 302 this.map.events.unregister("mousemove", this, this.passEventToSlider); 311 this.map.events.un({ 312 "mouseup": this.passEventToSlider, 313 "mousemove": this.passEventToSlider, 314 scope: this 315 }); 303 316 var deltaY = this.zoomStart.y - evt.xy.y; 304 317 this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 305 318 this.moveZoomBar(); -
lib/OpenLayers/Control/MouseToolbar.js
old new 105 105 btn.activeImgLocation = activeImgLocation; 106 106 107 107 btn.events = new OpenLayers.Events(this, btn, null, true); 108 btn.events.register("mousedown", this, this.buttonDown); 109 btn.events.register("mouseup", this, this.buttonUp); 110 btn.events.register("dblclick", this, OpenLayers.Event.stop); 108 btn.events.on({ 109 "mousedown": this.buttonDown, 110 "mouseup": this.buttonUp, 111 "dblclick": OpenLayers.Event.stop, 112 scope: this 113 }); 111 114 btn.action = id; 112 115 btn.title = title; 113 116 btn.alt = title; -
lib/OpenLayers/Control/MouseDefaults.js
old new 47 47 } 48 48 this.handler = null; 49 49 50 this.map.events.unregister( "click", this, this.defaultClick ); 51 this.map.events.unregister( "dblclick", this, this.defaultDblClick ); 52 this.map.events.unregister( "mousedown", this, this.defaultMouseDown ); 53 this.map.events.unregister( "mouseup", this, this.defaultMouseUp ); 54 this.map.events.unregister( "mousemove", this, this.defaultMouseMove ); 55 this.map.events.unregister( "mouseout", this, this.defaultMouseOut ); 50 this.map.events.un({ 51 "click": this.defaultClick, 52 "dblclick": this.defaultDblClick, 53 "mousedown": this.defaultMouseDown, 54 "mouseup": this.defaultMouseUp, 55 "mousemove": this.defaultMouseMove, 56 "mouseout": this.defaultMouseOut, 57 scope: this 58 }); 56 59 57 60 //unregister mousewheel events specifically on the window and document 58 61 OpenLayers.Event.stopObserving(window, "DOMMouseScroll", … … 70 73 * Method: draw 71 74 */ 72 75 draw: function() { 73 this.map.events.register( "click", this, this.defaultClick ); 74 this.map.events.register( "dblclick", this, this.defaultDblClick ); 75 this.map.events.register( "mousedown", this, this.defaultMouseDown ); 76 this.map.events.register( "mouseup", this, this.defaultMouseUp ); 77 this.map.events.register( "mousemove", this, this.defaultMouseMove ); 78 this.map.events.register( "mouseout", this, this.defaultMouseOut ); 76 this.map.events.on({ 77 "click": this.defaultClick, 78 "dblclick": this.defaultDblClick, 79 "mousedown": this.defaultMouseDown, 80 "mouseup": this.defaultMouseUp, 81 "mousemove": this.defaultMouseMove, 82 "mouseout": this.defaultMouseOut, 83 scope: this 84 }); 79 85 80 86 this.registerWheelEvents(); 81 87 -
lib/OpenLayers/Control/Permalink.js
old new 115 115 this.element.href=""; 116 116 this.div.appendChild(this.element); 117 117 } 118 this.map.events.register('moveend', this, this.updateLink); 119 this.map.events.register('changelayer', this, this.updateLink); 120 this.map.events.register('changebaselayer', this, this.updateLink); 118 this.map.events.on({ 119 'moveend': this.updateLink, 120 'changelayer': this.updateLink, 121 'changebaselayer': this.updateLink, 122 scope: this 123 }); 121 124 return this.div; 122 125 }, 123 126 -
lib/OpenLayers/Control/LayerSwitcher.js
old new 113 113 this.clearLayersArray("base"); 114 114 this.clearLayersArray("data"); 115 115 116 this.map.events.unregister("addlayer", this, this.redraw); 117 this.map.events.unregister("changelayer", this, this.redraw); 118 this.map.events.unregister("removelayer", this, this.redraw); 119 this.map.events.unregister("changebaselayer", this, this.redraw); 116 this.map.events.un({ 117 "addlayer": this.redraw, 118 "changelayer": this.redraw, 119 "removelayer": this.redraw, 120 "changebaselayer": this.redraw, 121 scope: this 122 }); 120 123 121 124 OpenLayers.Control.prototype.destroy.apply(this, arguments); 122 125 }, … … 130 133 setMap: function(map) { 131 134 OpenLayers.Control.prototype.setMap.apply(this, arguments); 132 135 133 this.map.events.register("addlayer", this, this.redraw); 134 this.map.events.register("changelayer", this, this.redraw); 135 this.map.events.register("removelayer", this, this.redraw); 136 this.map.events.register("changebaselayer", this, this.redraw); 136 this.map.events.on({ 137 "addlayer": this.redraw, 138 "changelayer": this.redraw, 139 "removelayer": this.redraw, 140 "changebaselayer": this.redraw, 141 scope: this 142 }); 137 143 }, 138 144 139 145 /** -
lib/OpenLayers/Control/SelectFeature.js
old new 266 266 OpenLayers.Util.extend(feature.style, selectStyle); 267 267 268 268 this.layer.drawFeature(feature); 269 this.layer.events.triggerEvent("featureselected", {feature: feature}); 269 270 this.onSelect(feature); 270 271 }, 271 272 … … 284 285 } 285 286 this.layer.drawFeature(feature); 286 287 OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); 288 this.layer.events.triggerEvent("featureunselected", {feature: feature}); 287 289 this.onUnselect(feature); 288 290 }, 289 291 -
lib/OpenLayers/Control/ModifyFeature.js
old new 182 182 var selectOptions = { 183 183 geometryTypes: this.geometryTypes, 184 184 clickout: this.clickout, 185 toggle: this.toggle, 186 onSelect: function(feature) { 187 control.selectFeature.apply(control, [feature]); 188 }, 189 onUnselect: function(feature) { 190 control.unselectFeature.apply(control, [feature]); 191 } 185 toggle: this.toggle 192 186 }; 193 187 this.selectControl = new OpenLayers.Control.SelectFeature( 194 188 layer, selectOptions 195 189 ); 190 this.layer.events.on({ 191 "featureselected": this.selectFeature, 192 "featureunselected": this.unselectFeature, 193 scope: this 194 }); 196 195 197 196 // configure the drag control 198 197 var dragOptions = { … … 226 225 * Take care of things that are not handled in superclass. 227 226 */ 228 227 destroy: function() { 228 this.layer.events.un({ 229 "featureselected": this.selectFeature, 230 "featureunselected": this.unselectFeature, 231 scope: this 232 }); 229 233 this.layer = null; 230 234 this.selectControl.destroy(); 231 235 this.dragControl.destroy(); … … 276 280 * Called when the select feature control selects a feature. 277 281 * 278 282 * Parameters: 279 * feature - {<OpenLayers.Feature.Vector>} The selected feature. 283 * object - {Object} Object with a feature property referencing the 284 * selected feature. 280 285 */ 281 selectFeature: function( feature) {282 this.feature = feature;286 selectFeature: function(object) { 287 this.feature = object.feature; 283 288 this.resetVertices(); 284 289 this.dragControl.activate(); 285 290 this.onModificationStart(this.feature); … … 290 295 * Called when the select feature control unselects a feature. 291 296 * 292 297 * Parameters: 293 * feature - {<OpenLayers.Feature.Vector>} The unselected feature. 298 * object - {Object} Object with a feature property referencing the 299 * unselected feature. 294 300 */ 295 unselectFeature: function( feature) {301 unselectFeature: function(object) { 296 302 this.layer.removeFeatures(this.vertices); 297 303 this.vertices = []; 298 304 this.layer.destroyFeatures(this.virtualVertices); … … 307 313 } 308 314 this.feature = null; 309 315 this.dragControl.deactivate(); 310 this.onModificationEnd( feature);316 this.onModificationEnd(object.feature); 311 317 }, 312 318 313 319 /** -
lib/OpenLayers/Layer.js
old new 37 37 */ 38 38 opacity: null, 39 39 40 /** 40 /** 41 41 * Constant: EVENT_TYPES 42 * {Array(String)} Supported application event types 42 * {Array(String)} Supported application event types. Register a listener 43 * for a particular event with the following syntax: 44 * (code) 45 * layer.events.register(type, obj, listener); 46 * (end) 47 * 48 * Listeners will be called with a reference to an event object. The 49 * properties of this event depends on exactly what happened. 50 * 51 * All event objects have at least the following properties: 52 * - *object* {Object} A reference to layer.events.object. 53 * - *element* {DOMElement} A reference to layer.events.element. 54 * 55 * Supported map event types: 56 * - *loadstart* Triggered when layer loading starts. 57 * - *loadend* Triggered when layer loading ends. 58 * - *loadcancel* Triggered when layer loading is canceled. 59 * - *visibilitychanged* Triggered when layer visibility is changed. 43 60 */ 44 61 EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged"], 45 62 … … 327 344 if (newName != this.name) { 328 345 this.name = newName; 329 346 if (this.map != null) { 330 this.map.events.triggerEvent("changelayer"); 347 this.map.events.triggerEvent("changelayer", { 348 layer: this, 349 property: "name" 350 }); 331 351 } 332 352 } 333 353 }, … … 530 550 this.display(visibility); 531 551 this.redraw(); 532 552 if (this.map != null) { 533 this.map.events.triggerEvent("changelayer"); 553 this.map.events.triggerEvent("changelayer", { 554 layer: this, 555 property: "visibility" 556 }); 534 557 } 535 558 this.events.triggerEvent("visibilitychanged"); 536 559 } … … 576 599 if (isBaseLayer != this.isBaseLayer) { 577 600 this.isBaseLayer = isBaseLayer; 578 601 if (this.map != null) { 579 this.map.events.triggerEvent("changebaselayer"); 602 this.map.events.triggerEvent("changebaselayer", { 603 layer: this 604 }); 580 605 } 581 606 } 582 607 }, -
lib/OpenLayers/Layer/Grid.js
old new 526 526 * tile - {<OpenLayers.Tile>} 527 527 */ 528 528 removeTileMonitoringHooks: function(tile) { 529 tile.events.unregister("loadstart", this, tile.onLoadStart); 530 tile.events.unregister("loadend", this, tile.onLoadEnd); 529 tile.events.un({ 530 "loadstart": tile.onLoadStart, 531 "loadend": tile.onLoadEnd, 532 scope: this 533 }); 531 534 }, 532 535 533 536 /** -
lib/OpenLayers/Layer/WFS.js
old new 353 353 * tile - {<OpenLayers.Tile>} 354 354 */ 355 355 removeTileMonitoringHooks: function(tile) { 356 tile.events.unregister("loadstart", tile, tile.onLoadStart); 357 tile.events.unregister("loadend", tile, tile.onLoadEnd); 356 tile.events.un({ 357 "loadstart": tile.onLoadStart, 358 "loadend": tile.onLoadEnd, 359 scope: tile 360 }); 358 361 }, 359 362 360 363 /** -
lib/OpenLayers/Layer/Vector.js
old new 20 20 OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { 21 21 22 22 /** 23 * Constant: EVENT_TYPES 24 * {Array(String)} Supported application event types. Register a listener 25 * for a particular event with the following syntax: 26 * (code) 27 * layer.events.register(type, obj, listener); 28 * (end) 29 * 30 * Listeners will be called with a reference to an event object. The 31 * properties of this event depends on exactly what happened. 32 * 33 * All event objects have at least the following properties: 34 * - *object* {Object} A reference to layer.events.object. 35 * - *element* {DOMElement} A reference to layer.events.element. 36 * 37 * Supported map event types: 38 * - *loadstart* Triggered when layer loading starts. 39 * - *loadend* Triggered when layer loading ends. 40 * - *loadcancel* Triggered when layer loading is canceled. 41 * - *visibilitychanged* Triggered when layer visibility is changed. 42 * - *beforefeatureadded* Triggered before a feature is added. Listeners 43 * will receive an object with a *feature* property referencing the 44 * feature to be added. 45 * - *featureadded* Triggered after a feature is added. The event 46 * object passed to listeners will have a *feature* property with a 47 * reference to the added feature. 48 * - *featuresadded* Triggered after features are added. The event 49 * object passed to listeners will have a *features* property with a 50 * reference to an array of added features. 51 * - *featureselected* Triggered after a feature is selected. Listeners 52 * will receive an object with a *feature* property referencing the 53 * selected feature. 54 * - *featureunselected* Triggered after a feature is unselected. 55 * Listeners will receive an object with a *feature* property 56 * referencing the unselected feature. 57 */ 58 EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged", 59 "beforefeatureadded", "featureadded", 60 "featuresadded", "featureselected", "featureunselected"], 61 62 /** 23 63 * APIProperty: isBaseLayer 24 64 * {Boolean} The layer is a base layer. Default is true. Set this property 25 65 * in the layer options … … 273 313 } 274 314 275 315 if (notify) { 316 this.events.triggerEvent("beforefeatureadded", { 317 feature: feature 318 }); 276 319 this.preFeatureInsert(feature); 277 320 } 278 321 … … 281 324 } 282 325 283 326 if (notify) { 327 this.events.triggerEvent("featureadded", { 328 feature: feature 329 }); 284 330 this.onFeatureInsert(feature); 285 331 } 286 332 } 333 334 if(notify) { 335 this.events.triggerEvent("featuresadded", {features: features}); 336 } 287 337 }, 288 338 289 339
