OpenLayers OpenLayers

Ticket #1343: events.patch

File events.patch, 35.7 kB (added by tschaub, 1 year ago)

enhanced event handling

  • tests/Control/test_SelectFeature.html

    old new  
    7878        // mock up layer 
    7979        var layer = { 
    8080            selectedFeatures: [], 
    81             drawFeature: function() {} 
     81            drawFeature: function() {}, 
     82            events: { 
     83                triggerEvent: function() {} 
     84            } 
    8285        }; 
    8386        // mock up active control 
    8487        var control = new OpenLayers.Control.SelectFeature(layer); 
  • tests/Control/test_ModifyFeature.html

    old new  
    55     
    66    function test_ModifyFeature_constructor(t) { 
    77        t.plan(3); 
    8         var layer = "foo";         
     8        var layer = { 
     9            events: { 
     10                on: function() {} 
     11            } 
     12        }; 
    913        var options = { 
    1014            geometryTypes: "bar" 
    1115        }; 
    1216        var control = new OpenLayers.Control.ModifyFeature(layer, options); 
    1317         
    14         t.eq(control.layer, "foo"
     18        t.ok(control.layer == layer
    1519             "constructor sets layer correctly"); 
    1620        t.eq(control.selectControl.geometryTypes, "bar", 
    1721             "constructor sets options correctly on feature handler"); 
     
    7276         * In the future, feature deletion may be added to the control. 
    7377         */ 
    7478         
    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        }); 
    7685        var delKey = 46; 
    7786        var dKey = 100; 
    7887        control.deleteCodes = [delKey, dKey]; 
     
    197206        layer.destroyFeatures = function(verts) { 
    198207            t.ok(verts == 'b', "Virtual verts destroyed correctly"); 
    199208        } 
    200         control.unselectFeature(fakeFeature); 
     209        control.unselectFeature({feature: fakeFeature}); 
    201210        t.eq(control.feature, null, "feature is set to null"); 
    202211    }     
    203212    function test_ModifyFeature_selectFeature(t) { 
     
    216225        var fakeFeature = {'id':'myFakeFeature','geometry':{'CLASS_NAME':'OpenLayers.Geometry.Point'}}; 
    217226         
    218227        // Points don't call collectVertices 
    219         control.selectFeature(fakeFeature); 
     228        control.selectFeature({feature: fakeFeature}); 
    220229         
    221230        control.collectVertices = function() {  
    222231          t.ok(true, "collectVertices called");  
     
    232241        fakeFeature.geometry.CLASS_NAME='OpenLayers.Geometry.Polygon'; 
    233242         
    234243        // OnSelect calls collectVertices and passes features to layer  
    235         control.selectFeature(fakeFeature); 
     244        control.selectFeature({feature: fakeFeature}); 
    236245         
    237246        control.vertices = ['a']; 
    238247        control.virtualVertices = ['b']; 
     
    244253        }     
    245254 
    246255        // Features are removed whenever they exist 
    247         control.selectFeature(fakeFeature); 
     256        control.selectFeature({feature: fakeFeature}); 
    248257         
    249258    }   
    250259 
     
    389398            t.eq(feature.id, testFeature.id, 
    390399                 "onModificationStart called with the right feature"); 
    391400        }; 
    392         control.selectFeature(testFeature); 
     401        control.selectFeature({feature: testFeature}); 
    393402    } 
    394403     
    395404    function test_ModifyFeature_onModification(t) { 
     
    450459            t.eq(feature.id, testFeature.id, 
    451460                 "onModificationEnd called with the right feature"); 
    452461        }; 
    453         control.unselectFeature(testFeature); 
     462        control.unselectFeature({feature: testFeature}); 
    454463    } 
    455464 
    456465 
  • tests/test_Events.html

    old new  
    205205        eventTypes = ["something"]; 
    206206        events = new OpenLayers.Events(null, null, eventTypes); 
    207207        var instance = {id: Math.random()}; 
    208         var listener = function() { 
     208        var listener = function(obj) { 
    209209            t.eq(this.id, instance.id, 
    210210                 "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"); 
    217217        }; 
    218218        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); 
    221224        events.unregister("something", instance, listener); 
    222225         
    223226        // test return from triggerEvent 
  • tests/Layer/test_Grid.html

    old new  
    499499            events: { 
    500500                unregister: function(name, obj, func) { 
    501501                    g_unregistered[name] = [obj, func]; 
    502                 } 
     502                }, 
     503                un: OpenLayers.Events.prototype.un 
    503504            } 
    504505        } 
    505506 
  • lib/OpenLayers/Map.js

    old new  
    3232     * map.events.register(type, obj, listener); 
    3333     * (end) 
    3434     * 
     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     * 
    3547     * 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. 
    3853     *  - *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). 
    4059     *  - *movestart* triggered after the start of a drag, pan, or zoom 
    4160     *  - *move* triggered after each drag, pan, or zoom 
    4261     *  - *moveend* triggered after a drag, pan, or zoom completes 
     
    735754            layer.redraw(); 
    736755        } 
    737756 
    738         this.events.triggerEvent("addlayer"); 
     757        this.events.triggerEvent("addlayer", {layer: layer}); 
    739758    }, 
    740759 
    741760    /** 
     
    808827 
    809828        this.resetLayersZIndex(); 
    810829 
    811         this.events.triggerEvent("removelayer"); 
     830        this.events.triggerEvent("removelayer", {layer: layer}); 
    812831    }, 
    813832 
    814833    /** 
     
    860879            for (var i = 0; i < this.layers.length; i++) { 
    861880                this.setLayerZIndex(this.layers[i], i); 
    862881            } 
    863             this.events.triggerEvent("changelayer"); 
     882            this.events.triggerEvent("changelayer", { 
     883                layer: layer, property: "order" 
     884            }); 
    864885        } 
    865886    }, 
    866887 
     
    933954                    this.setCenter(newCenter, newZoom, false, true); 
    934955                } 
    935956 
    936                 this.events.triggerEvent("changebaselayer"); 
     957                this.events.triggerEvent("changebaselayer", { 
     958                    layer: this.baseLayer 
     959                }); 
    937960            }         
    938961        } 
    939962    }, 
     
    14531476                        if (!inRange) { 
    14541477                            layer.display(false); 
    14551478                        } 
    1456                         this.events.triggerEvent("changelayer"); 
     1479                        this.events.triggerEvent("changelayer", { 
     1480                            layer: layer, property: "visibility" 
     1481                        }); 
    14571482                    } 
    14581483                    if (inRange && layer.visibility) { 
    14591484                        layer.moveTo(bounds, zoomChanged, dragging); 
  • lib/OpenLayers/Popup.js

    old new  
    403403     registerEvents:function() { 
    404404        this.events = new OpenLayers.Events(this, this.div, null, true); 
    405405 
    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         
    412416     }, 
    413417 
    414418    /**  
  • lib/OpenLayers/Events.js

    old new  
    481481        // disable dragstart in IE so that mousedown/move/up works normally 
    482482        OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop); 
    483483    }, 
     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    }, 
    484505 
    485506    /** 
    486507     * APIMethod: register 
     
    553574    }, 
    554575     
    555576    /** 
     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    /** 
    556598     * APIMethod: unregister 
    557599     * 
    558600     * Parameters: 
     
    596638     * Parameters: 
    597639     * type - {String}  
    598640     * evt - {Event} 
    599      * args - {Array} Optional array of arguments to call the listener with. 
    600641     * 
    601642     * Returns: 
    602643     * {Boolean} The last listener return.  If a listener returns false, the 
    603644     *     chain of listeners will stop getting called. 
    604645     */ 
    605     triggerEvent: function (type, evt, args) { 
     646    triggerEvent: function (type, evt) { 
    606647 
    607648        // prep evt object with object & div references 
    608649        if (evt == null) { 
     
    610651        } 
    611652        evt.object = this.object; 
    612653        evt.element = this.element; 
    613          
    614         if(!args) { 
    615             args = [evt]; 
    616         } else { 
    617             args.unshift(evt); 
    618         } 
    619  
     654     
    620655        // execute all callbacks registered for specified type 
    621656        // get a clone of the listeners array to 
    622657        // allow for splicing during callbacks 
     
    627662            for (var i = 0; i < listeners.length; i++) { 
    628663                var callback = listeners[i]; 
    629664                // bind the context to callback.obj 
    630                 continueChain = callback.func.apply(callback.obj, args); 
     665                continueChain = callback.func.apply(callback.obj, [evt]); 
    631666     
    632667                if ((continueChain != undefined) && (continueChain == false)) { 
    633668                    // if callback returns false, execute no more callbacks. 
  • lib/OpenLayers/Control/OverviewMap.js

    old new  
    154154            this.minimizeDiv = null; 
    155155        } 
    156156         
    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        }); 
    160162 
    161163        OpenLayers.Control.prototype.destroy.apply(this, arguments);     
    162164    }, 
  • lib/OpenLayers/Control/Attribution.js

    old new  
    3535     * Destroy control. 
    3636     */ 
    3737    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        }); 
    4245         
    4346        OpenLayers.Control.prototype.destroy.apply(this, arguments); 
    4447    },     
     
    5356    draw: function() { 
    5457        OpenLayers.Control.prototype.draw.apply(this, arguments); 
    5558         
    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        }); 
    6066        this.updateAttribution(); 
    6167         
    6268        return this.div;     
  • lib/OpenLayers/Control/PanZoomBar.js

    old new  
    7979        this.divEvents.destroy(); 
    8080        this.divEvents = null; 
    8181 
    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        }); 
    8487 
    8588        OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); 
    8689    }, 
     
    164167        this.slider = slider; 
    165168         
    166169        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        }); 
    172177         
    173178        var sz = new OpenLayers.Size(); 
    174179        sz.h = this.zoomStopHeight * this.map.getNumZoomLevels(); 
     
    194199        this.zoombarDiv = div; 
    195200         
    196201        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        }); 
    201208         
    202209        this.div.appendChild(div); 
    203210 
     
    250257        if (!OpenLayers.Event.isLeftClick(evt)) { 
    251258            return; 
    252259        } 
    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        }); 
    255265        this.mouseDragStart = evt.xy.clone(); 
    256266        this.zoomStart = evt.xy.clone(); 
    257267        this.div.style.cursor = "move"; 
     
    298308        } 
    299309        if (this.zoomStart) { 
    300310            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            }); 
    303316            var deltaY = this.zoomStart.y - evt.xy.y; 
    304317            this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 
    305318            this.moveZoomBar(); 
  • lib/OpenLayers/Control/MouseToolbar.js

    old new  
    105105        btn.activeImgLocation = activeImgLocation; 
    106106         
    107107        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        }); 
    111114        btn.action = id; 
    112115        btn.title = title; 
    113116        btn.alt = title; 
  • lib/OpenLayers/Control/MouseDefaults.js

    old new  
    4747        } 
    4848        this.handler = null; 
    4949 
    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        }); 
    5659 
    5760        //unregister mousewheel events specifically on the window and document 
    5861        OpenLayers.Event.stopObserving(window, "DOMMouseScroll",  
     
    7073     * Method: draw 
    7174     */ 
    7275    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        }); 
    7985 
    8086        this.registerWheelEvents(); 
    8187 
  • lib/OpenLayers/Control/Permalink.js

    old new  
    115115            this.element.href=""; 
    116116            this.div.appendChild(this.element); 
    117117        } 
    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        }); 
    121124        return this.div; 
    122125    }, 
    123126    
  • lib/OpenLayers/Control/LayerSwitcher.js

    old new  
    113113        this.clearLayersArray("base"); 
    114114        this.clearLayersArray("data"); 
    115115         
    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        }); 
    120123         
    121124        OpenLayers.Control.prototype.destroy.apply(this, arguments); 
    122125    }, 
     
    130133    setMap: function(map) { 
    131134        OpenLayers.Control.prototype.setMap.apply(this, arguments); 
    132135 
    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        }); 
    137143    }, 
    138144 
    139145    /** 
  • lib/OpenLayers/Control/SelectFeature.js

    old new  
    266266        OpenLayers.Util.extend(feature.style, selectStyle); 
    267267 
    268268        this.layer.drawFeature(feature); 
     269        this.layer.events.triggerEvent("featureselected", {feature: feature}); 
    269270        this.onSelect(feature); 
    270271    }, 
    271272 
     
    284285        } 
    285286        this.layer.drawFeature(feature); 
    286287        OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); 
     288        this.layer.events.triggerEvent("featureunselected", {feature: feature}); 
    287289        this.onUnselect(feature); 
    288290    }, 
    289291 
  • lib/OpenLayers/Control/ModifyFeature.js

    old new  
    182182        var selectOptions = { 
    183183            geometryTypes: this.geometryTypes, 
    184184            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 
    192186        }; 
    193187        this.selectControl = new OpenLayers.Control.SelectFeature( 
    194188            layer, selectOptions 
    195189        ); 
     190        this.layer.events.on({ 
     191            "featureselected": this.selectFeature, 
     192            "featureunselected": this.unselectFeature, 
     193            scope: this 
     194        }); 
    196195 
    197196        // configure the drag control 
    198197        var dragOptions = { 
     
    226225     * Take care of things that are not handled in superclass. 
    227226     */ 
    228227    destroy: function() { 
     228        this.layer.events.un({ 
     229            "featureselected": this.selectFeature, 
     230            "featureunselected": this.unselectFeature, 
     231            scope: this 
     232        }); 
    229233        this.layer = null; 
    230234        this.selectControl.destroy(); 
    231235        this.dragControl.destroy(); 
     
    276280     * Called when the select feature control selects a feature. 
    277281     * 
    278282     * Parameters: 
    279      * feature - {<OpenLayers.Feature.Vector>} The selected feature. 
     283     * object - {Object} Object with a feature property referencing the 
     284     *     selected feature. 
    280285     */ 
    281     selectFeature: function(feature) { 
    282         this.feature = feature; 
     286    selectFeature: function(object) { 
     287        this.feature = object.feature; 
    283288        this.resetVertices(); 
    284289        this.dragControl.activate(); 
    285290        this.onModificationStart(this.feature); 
     
    290295     * Called when the select feature control unselects a feature. 
    291296     * 
    292297     * Parameters: 
    293      * feature - {<OpenLayers.Feature.Vector>} The unselected feature. 
     298     * object - {Object} Object with a feature property referencing the 
     299     *     unselected feature. 
    294300     */ 
    295     unselectFeature: function(feature) { 
     301    unselectFeature: function(object) { 
    296302        this.layer.removeFeatures(this.vertices); 
    297303        this.vertices = []; 
    298304        this.layer.destroyFeatures(this.virtualVertices); 
     
    307313        } 
    308314        this.feature = null; 
    309315        this.dragControl.deactivate(); 
    310         this.onModificationEnd(feature); 
     316        this.onModificationEnd(object.feature); 
    311317    }, 
    312318 
    313319    /** 
  • lib/OpenLayers/Layer.js

    old new  
    3737     */ 
    3838    opacity: null, 
    3939 
    40     /**  
     40    /** 
    4141     * 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. 
    4360     */ 
    4461    EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged"], 
    4562         
     
    327344        if (newName != this.name) { 
    328345            this.name = newName; 
    329346            if (this.map != null) { 
    330                 this.map.events.triggerEvent("changelayer"); 
     347                this.map.events.triggerEvent("changelayer", { 
     348                    layer: this, 
     349                    property: "name" 
     350                }); 
    331351            } 
    332352        } 
    333353    },     
     
    530550            this.display(visibility); 
    531551            this.redraw(); 
    532552            if (this.map != null) { 
    533                 this.map.events.triggerEvent("changelayer"); 
     553                this.map.events.triggerEvent("changelayer", { 
     554                    layer: this, 
     555                    property: "visibility" 
     556                }); 
    534557            } 
    535558            this.events.triggerEvent("visibilitychanged"); 
    536559        } 
     
    576599        if (isBaseLayer != this.isBaseLayer) { 
    577600            this.isBaseLayer = isBaseLayer; 
    578601            if (this.map != null) { 
    579                 this.map.events.triggerEvent("changebaselayer"); 
     602                this.map.events.triggerEvent("changebaselayer", { 
     603                    layer: this 
     604                }); 
    580605            } 
    581606        } 
    582607    }, 
  • lib/OpenLayers/Layer/Grid.js

    old new  
    526526     * tile - {<OpenLayers.Tile>} 
    527527     */ 
    528528    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        }); 
    531534    }, 
    532535     
    533536    /** 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    353353     * tile - {<OpenLayers.Tile>} 
    354354     */ 
    355355    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        }); 
    358361    }, 
    359362 
    360363    /** 
  • lib/OpenLayers/Layer/Vector.js

    old new  
    2020OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { 
    2121 
    2222    /** 
     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    /** 
    2363     * APIProperty: isBaseLayer 
    2464     * {Boolean} The layer is a base layer.  Default is true.  Set this property 
    2565     * in the layer options 
     
    273313            } 
    274314 
    275315            if (notify) { 
     316                this.events.triggerEvent("beforefeatureadded", { 
     317                    feature: feature 
     318                }); 
    276319                this.preFeatureInsert(feature); 
    277320            } 
    278321 
     
    281324            } 
    282325             
    283326            if (notify) { 
     327                this.events.triggerEvent("featureadded", { 
     328                    feature: feature 
     329                }); 
    284330                this.onFeatureInsert(feature); 
    285331            } 
    286332        } 
     333         
     334        if(notify) { 
     335            this.events.triggerEvent("featuresadded", {features: features}); 
     336        } 
    287337    }, 
    288338 
    289339