OpenLayers OpenLayers

Changeset 6106

Show
Ignore:
Timestamp:
02/08/08 10:52:03 (1 year ago)
Author:
tschaub
Message:

For controls with multiple handlers, we now tack them on to a handlers object. The base destroy takes care of the handlers. r=crschmidt,uz/2 (closes #1338)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control.js

    r5910 r6106  
    140140            this.handler = null; 
    141141        } 
     142        if(this.handlers) { 
     143            for(var key in this.handlers) { 
     144                if(this.handlers.hasOwnProperty(key) && 
     145                   typeof this.handlers[key].destroy == "function") { 
     146                    this.handlers[key].destroy(); 
     147                } 
     148            } 
     149            this.handlers = null; 
     150        } 
    142151        if (this.map) { 
    143152            this.map.removeControl(this); 
  • trunk/openlayers/lib/OpenLayers/Control/DragFeature.js

    r5614 r6106  
    7878 
    7979    /** 
    80      * Property: dragHandler 
    81      * {<OpenLayers.Handler.Drag>} 
    82      */ 
    83     dragHandler: null, 
    84  
    85     /** 
    8680     * Property: dragCallbacks 
    8781     * {Object} The functions that are sent to the drag handler for callback. 
    8882     */ 
    8983    dragCallbacks: {}, 
    90  
    91     /** 
    92      * Property: featureHandler 
    93      * {<OpenLayers.Handler.Feature>} 
    94      */ 
    95     featureHandler: null, 
    9684 
    9785    /** 
     
    120108        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    121109        this.layer = layer; 
    122         this.dragCallbacks = OpenLayers.Util.extend({down: this.downFeature, 
    123                                                      move: this.moveFeature, 
    124                                                      up: this.upFeature, 
    125                                                      out: this.cancel, 
    126                                                      done: this.doneDragging 
    127                                                     }, this.dragCallbacks); 
    128         this.dragHandler = new OpenLayers.Handler.Drag(this, this.dragCallbacks); 
    129         this.featureCallbacks = OpenLayers.Util.extend({over: this.overFeature, 
    130                                                         out: this.outFeature 
    131                                                        }, this.featureCallbacks); 
    132         var handlerOptions = {geometryTypes: this.geometryTypes}; 
    133         this.featureHandler = new OpenLayers.Handler.Feature(this, this.layer, 
    134                                                         this.featureCallbacks, 
    135                                                         handlerOptions); 
     110        this.handlers = { 
     111            drag: new OpenLayers.Handler.Drag( 
     112                this, OpenLayers.Util.extend({ 
     113                    down: this.downFeature, 
     114                    move: this.moveFeature, 
     115                    up: this.upFeature, 
     116                    out: this.cancel, 
     117                    done: this.doneDragging 
     118                }, this.dragCallbacks) 
     119            ), 
     120            feature: new OpenLayers.Handler.Feature( 
     121                this, this.layer, OpenLayers.Util.extend({ 
     122                    over: this.overFeature, 
     123                    out: this.outFeature 
     124                }, this.featureCallbacks), 
     125                {geometryTypes: this.geometryTypes} 
     126            ) 
     127        }; 
    136128    }, 
    137129     
     
    142134    destroy: function() { 
    143135        this.layer = null; 
    144         this.dragHandler.destroy(); 
    145         this.featureHandler.destroy(); 
    146136        OpenLayers.Control.prototype.destroy.apply(this, []); 
    147137    }, 
     
    155145     */ 
    156146    activate: function() { 
    157         return (this.featureHandler.activate() && 
     147        return (this.handlers.feature.activate() && 
    158148                OpenLayers.Control.prototype.activate.apply(this, arguments)); 
    159149    }, 
     
    168158    deactivate: function() { 
    169159        // the return from the handlers is unimportant in this case 
    170         this.dragHandler.deactivate(); 
    171         this.featureHandler.deactivate(); 
     160        this.handlers.drag.deactivate(); 
     161        this.handlers.feature.deactivate(); 
    172162        this.feature = null; 
    173163        this.dragging = false; 
     
    185175     */ 
    186176    overFeature: function(feature) { 
    187         if(!this.dragHandler.dragging) { 
     177        if(!this.handlers.drag.dragging) { 
    188178            this.feature = feature; 
    189             this.dragHandler.activate(); 
     179            this.handlers.drag.activate(); 
    190180            this.over = true; 
    191181            // TBD replace with CSS classes 
     
    239229    upFeature: function(pixel) { 
    240230        if(!this.over) { 
    241             this.dragHandler.deactivate(); 
     231            this.handlers.drag.deactivate(); 
    242232            this.feature = null; 
    243233            // TBD replace with CSS classes 
     
    266256     */ 
    267257    outFeature: function(feature) { 
    268         if(!this.dragHandler.dragging) { 
     258        if(!this.handlers.drag.dragging) { 
    269259            this.over = false; 
    270             this.dragHandler.deactivate(); 
     260            this.handlers.drag.deactivate(); 
    271261            // TBD replace with CSS classes 
    272262            this.map.div.style.cursor = "default"; 
     
    284274     */ 
    285275    cancel: function() { 
    286         this.dragHandler.deactivate(); 
     276        this.handlers.drag.deactivate(); 
    287277        this.over = false; 
    288278    }, 
     
    296286     */ 
    297287    setMap: function(map) { 
    298         this.dragHandler.setMap(map); 
    299         this.featureHandler.setMap(map); 
     288        this.handlers.drag.setMap(map); 
     289        this.handlers.feature.setMap(map); 
    300290        OpenLayers.Control.prototype.setMap.apply(this, arguments); 
    301291    }, 
  • trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js

    r5974 r6106  
    8484     
    8585    /** 
    86      * Property: keyboardHandler 
    87      * {<OpenLayers.Handler.Keyboard>
    88      */ 
    89     keyboardHandler: null, 
     86     * Property: handlers 
     87     * {Object
     88     */ 
     89    handlers: null, 
    9090     
    9191    /** 
     
    217217            keypress: this.handleKeypress 
    218218        }; 
    219         this.keyboardHandler = new OpenLayers.Handler.Keyboard( 
    220             this, keyboardOptions 
    221         )
     219        this.handlers = { 
     220            keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions) 
     221        }
    222222    }, 
    223223 
     
    230230        this.selectControl.destroy(); 
    231231        this.dragControl.destroy(); 
    232         this.keyboardHandler.destroy(); 
    233232        OpenLayers.Control.prototype.destroy.apply(this, []); 
    234233    }, 
     
    243242    activate: function() { 
    244243        return (this.selectControl.activate() && 
    245                 this.keyboardHandler.activate() && 
     244                this.handlers.keyboard.activate() && 
    246245                OpenLayers.Control.prototype.activate.apply(this, arguments)); 
    247246    }, 
     
    267266            } 
    268267            this.selectControl.deactivate(); 
    269             this.keyboardHandler.deactivate(); 
     268            this.handlers.keyboard.deactivate(); 
    270269            deactivated = true; 
    271270        } 
     
    353352                                                   [feature]); 
    354353                this.dragControl.lastPixel = pixel; 
    355                 this.dragControl.dragHandler.started = true; 
    356                 this.dragControl.dragHandler.start = pixel; 
    357                 this.dragControl.dragHandler.last = pixel; 
     354                this.dragControl.handlers.drag.started = true; 
     355                this.dragControl.handlers.drag.start = pixel; 
     356                this.dragControl.handlers.drag.last = pixel; 
    358357            } 
    359358        } 
     
    487486            if(vertex && 
    488487               OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && 
    489                !this.dragControl.dragHandler.dragging && 
     488               !this.dragControl.handlers.drag.dragging && 
    490489               vertex.geometry.parent) { 
    491490                // remove the vertex 
  • trunk/openlayers/lib/OpenLayers/Control/Navigation.js

    r5990 r6106  
    3737    zoomBox: null, 
    3838 
    39     /**  
    40      * Property: wheelHandler 
    41      * {<OpenLayers.Handler.MouseWheel>} 
    42      */ 
    43     wheelHandler: null, 
    44  
    4539    /** 
    4640     * Constructor: OpenLayers.Control.Navigation 
     
    5246     */ 
    5347    initialize: function(options) { 
     48        this.handlers = {}; 
    5449        OpenLayers.Control.prototype.initialize.apply(this, arguments); 
    5550    }, 
     
    6257     */ 
    6358    destroy: function() { 
    64         OpenLayers.Control.prototype.destroy.apply(this,arguments); 
    65  
    6659        this.deactivate(); 
    6760 
     
    7164        this.dragPan = null; 
    7265 
    73         if (this.wheelHandler) { 
    74             this.wheelHandler.destroy(); 
    75         } 
    76         this.wheelHandler = null; 
    77  
    78         if (this.clickHandler) { 
    79             this.clickHandler.destroy(); 
    80         } 
    81         this.clickHandler = null; 
    82          
    8366        if (this.zoomBox) { 
    8467            this.zoomBox.destroy(); 
    8568        } 
    8669        this.zoomBox = null; 
     70        OpenLayers.Control.prototype.destroy.apply(this,arguments); 
    8771    }, 
    8872     
     
    9276    activate: function() { 
    9377        this.dragPan.activate(); 
    94         this.wheelHandler.activate(); 
    95         this.clickHandler.activate(); 
     78        this.handlers.wheel.activate(); 
     79        this.handlers.click.activate(); 
    9680        this.zoomBox.activate(); 
    9781        return OpenLayers.Control.prototype.activate.apply(this,arguments); 
     
    10488        this.zoomBox.deactivate(); 
    10589        this.dragPan.deactivate(); 
    106         this.clickHandler.deactivate(); 
    107         this.wheelHandler.deactivate(); 
     90        this.handlers.click.deactivate(); 
     91        this.handlers.wheel.deactivate(); 
    10892        return OpenLayers.Control.prototype.deactivate.apply(this,arguments); 
    10993    }, 
     
    11397     */ 
    11498    draw: function() { 
    115         this.clickHandler = new OpenLayers.Handler.Click(this,  
     99        this.handlers.click = new OpenLayers.Handler.Click(this,  
    116100                                        { 'dblclick': this.defaultDblClick }, 
    117101                                        { 
     
    124108        this.dragPan.draw(); 
    125109        this.zoomBox.draw(); 
    126         this.wheelHandler = new OpenLayers.Handler.MouseWheel( 
     110        this.handlers.wheel = new OpenLayers.Handler.MouseWheel( 
    127111                                    this, {"up"  : this.wheelUp, 
    128112                                           "down": this.wheelDown} ); 
  • trunk/openlayers/lib/OpenLayers/Control/OverviewMap.js

    r6052 r6106  
    9999     
    100100    /** 
    101      * Property: dragHandler 
    102      * {<OpenLayers.Handler.Drag>} A handler for dragging the extent rectangle. 
    103      */ 
    104     dragHandler: null, 
     101     * Property: handlers 
     102     * {Object} 
     103     */ 
     104    handlers: null, 
    105105 
    106106    /** 
     
    115115    initialize: function(options) { 
    116116        this.layers = []; 
     117        this.handlers = {}; 
    117118        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    118119    }, 
     
    126127            return; 
    127128        } 
    128         this.dragHandler.destroy(); 
    129         this.clickHandler.destroy(); 
     129        this.handlers.click.destroy(); 
    130130 
    131131        this.mapDiv.removeChild(this.extentRectangle); 
     
    281281     */ 
    282282    rectDrag: function(px) { 
    283         var deltaX = this.dragHandler.last.x - px.x; 
    284         var deltaY = this.dragHandler.last.y - px.y; 
     283        var deltaX = this.handlers.drag.last.x - px.x; 
     284        var deltaY = this.handlers.drag.last.y - px.y; 
    285285        if(deltaX != 0 || deltaY != 0) { 
    286286            var rectTop = this.rectPxBounds.top; 
     
    457457        this.hComp = (this.hComp) ? this.hComp : 2; 
    458458 
    459         this.dragHandler = new OpenLayers.Handler.Drag( 
     459        this.handlers.drag = new OpenLayers.Handler.Drag( 
    460460            this, {move: this.rectDrag, done: this.updateMapToRect}, 
    461461            {map: this.ovmap} 
    462462        ); 
    463         this.clickHandler = new OpenLayers.Handler.Click( 
     463        this.handlers.click = new OpenLayers.Handler.Click( 
    464464            this, { 
    465465                "click": this.mapDivClick 
     
    471471            } 
    472472        ); 
    473         this.clickHandler.activate(); 
     473        this.handlers.click.activate(); 
    474474         
    475475        this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, 
    476476                                                null, true); 
    477477        this.rectEvents.register("mouseover", this, function(e) { 
    478             if(!this.dragHandler.active && !this.map.dragging) { 
    479                 this.dragHandler.activate(); 
     478            if(!this.handlers.drag.active && !this.map.dragging) { 
     479                this.handlers.drag.activate(); 
    480480            } 
    481481        }); 
    482482        this.rectEvents.register("mouseout", this, function(e) { 
    483             if(!this.dragHandler.dragging) { 
    484                 this.dragHandler.deactivate(); 
     483            if(!this.handlers.drag.dragging) { 
     484                this.handlers.drag.deactivate(); 
    485485            } 
    486486        }); 
  • trunk/openlayers/tests/Control/test_DragFeature.html

    r5506 r6106  
    1515        t.eq(control.layer, "bar", 
    1616             "constructor sets layer correctly");         
    17         t.eq(control.featureHandler.geometryTypes, "foo", 
     17        t.eq(control.handlers.feature.geometryTypes, "foo", 
    1818             "constructor sets options correctly on feature handler"); 
    1919    } 
     
    2525        map.addLayer(layer); 
    2626        var control = new OpenLayers.Control.DragFeature(layer); 
    27         control.dragHandler.destroy = function() { 
     27        control.handlers.drag.destroy = function() { 
    2828            t.ok(true, 
    2929                 "control.destroy calls destroy on drag handler"); 
    3030        } 
    31         control.featureHandler.destroy = function() { 
     31        control.handlers.feature.destroy = function() { 
    3232            t.ok(true, 
    3333                 "control.destroy calls destroy on feature handler"); 
    3434        } 
     35         
    3536        control.destroy(); 
    3637         
     
    4445        var control = new OpenLayers.Control.DragFeature(layer); 
    4546        map.addControl(control); 
    46         t.ok(!control.featureHandler.active, 
     47        t.ok(!control.handlers.feature.active, 
    4748             "feature handler is not active prior to activating control"); 
    4849        control.activate(); 
    49         t.ok(control.featureHandler.active, 
     50        t.ok(control.handlers.feature.active, 
    5051             "feature handler is active after activating control"); 
    5152    } 
     
    5960        map.addControl(control); 
    6061         
    61         control.dragHandler.deactivate = function() { 
     62        control.handlers.drag.deactivate = function() { 
    6263            t.ok(true, 
    6364                 "control.deactivate calls deactivate on drag handler"); 
    6465        } 
    65         control.featureHandler.deactivate = function() { 
     66        control.handlers.feature.deactivate = function() { 
    6667            t.ok(true, 
    6768                 "control.deactivate calls deactivate on feature handler"); 
     
    7980         
    8081        control.activate(); 
    81         t.ok(!control.dragHandler.active, 
     82        t.ok(!control.handlers.drag.active, 
    8283             "drag handler is not active before over a feature"); 
    8384         
     
    9091        t.eq(control.feature, "foo", 
    9192             "control gets the proper feature from the feature handler"); 
    92         t.ok(control.dragHandler.active, 
     93        t.ok(control.handlers.drag.active, 
    9394             "drag handler activated when over a feature"); 
    9495    } 
  • trunk/openlayers/tests/Control/test_ModifyFeature.html

    r5974 r6106  
    173173 
    174174        // now make sure nothing happens if the vertex is mid-drag 
    175         control.dragControl.dragHandler.dragging = true; 
     175        control.dragControl.handlers.drag.dragging = true; 
    176176        control.handleKeypress(delKey); 
    177177 
     
    306306        control.dragControl.map.div.style = {}; 
    307307        control.dragControl.map.div.cursor = "foo"; 
    308         control.dragControl.dragHandler.deactivate = function() { 
     308        control.dragControl.handlers.drag.deactivate = function() { 
    309309            this.active = false; 
    310310        } 
    311311        control.resetVertices(); 
    312         t.ok(!control.dragControl.dragHandler.active, "resetVertices deactivates drag handler"); 
     312        t.ok(!control.dragControl.handlers.drag.active, "resetVertices deactivates drag handler"); 
    313313        control.dragControl.map = null; 
    314314         
  • trunk/openlayers/tests/Control/test_Navigation.html

    r5990 r6106  
    66    function test_Control_Navigation_constructor (t) { 
    77        t.plan( 2 ); 
    8        var temp = OpenLayers.Control.prototype.initialize; 
    9        OpenLayers.Control.prototype.initialize = function() { 
    10            t.ok(true, "OpenLayers.Control's constructor called"); 
    11        }; 
     8        var temp = OpenLayers.Control.prototype.initialize; 
     9        OpenLayers.Control.prototype.initialize = function() { 
     10            t.ok(true, "OpenLayers.Control's constructor called"); 
     11        }; 
    1212 
    1313        var control = new OpenLayers.Control.Navigation(); 
    1414        t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" ); 
    1515 
    16        OpenLayers.Control.prototype.initialize = temp; 
     16        OpenLayers.Control.prototype.initialize = temp; 
    1717    } 
    1818 
    1919    function test_Control_Navigation_destroy (t) { 
    20         t.plan(10); 
    21          
    22         var temp = OpenLayers.Control.prototype.destroy; 
    23         OpenLayers.Control.prototype.destroy = function() { 
    24             t.ok(true, "OpenLayers.Control's destroy called"); 
    25         }; 
     20        t.plan(9); 
     21         
     22        var temp = OpenLayers.Control.prototype.destroy; 
     23        OpenLayers.Control.prototype.destroy = function() { 
     24            t.ok(true, "OpenLayers.Control's destroy called"); 
     25            temp.call(this); 
     26        }; 
    2627 
    27         var control = { 
    28             'deactivate': function() { 
    29                 t.ok(true, "navigation control deactivated before being destroyed"); 
    30             }, 
    31             'dragPan': { 
    32                 'destroy': function() { 
    33                     t.ok(true, "dragPan destroyed"); 
    34                 } 
    35             }, 
    36             'zoomBox': { 
    37                 'destroy': function() { 
    38                     t.ok(true, "zoomBox destroyed"); 
    39                 } 
    40             }, 
    41             'wheelHandler': { 
    42                 'destroy': function() { 
    43                     t.ok(true, "wheelHandler destroyed"); 
    44                 } 
    45             }, 
    46             'clickHandler': { 
    47                 'destroy': function() { 
    48                     t.ok(true, "clickHandler destroyed"); 
    49                 } 
    50             } 
    51         }; 
     28        var control = { 
     29            'deactivate': function() { 
     30                t.ok(true, "navigation control deactivated before being destroyed"); 
     31            }, 
     32            'dragPan': { 
     33                'destroy': function() { 
     34                    t.ok(true, "dragPan destroyed"); 
     35                } 
     36            }, 
     37            'zoomBox': { 
     38                'destroy': function() { 
     39                    t.ok(true, "zoomBox destroyed"); 
     40                } 
     41            }, 
     42            handlers: { 
     43                'wheel': { 
     44                    'destroy': function() { 
     45                        t.ok(true, "wheelHandler destroyed"); 
     46                    } 
     47                }, 
     48                'click': { 
     49                    'destroy': function() { 
     50                        t.ok(true, "clickHandler destroyed"); 
     51                    } 
     52                } 
     53            } 
     54        }; 
    5255 
    53        //this will also trigger one test by calling OpenLayers.Control's destroy 
    54        // and three more for the destruction of dragPan, zoomBox, and wheelHandler 
    55        OpenLayers.Control.Navigation.prototype.destroy.apply(control, []); 
     56        //this will also trigger one test by calling OpenLayers.Control's destroy 
     57        // and three more for the destruction of dragPan, zoomBox, and wheelHandler 
     58        OpenLayers.Control.Navigation.prototype.destroy.apply(control, []); 
    5659 
    57         t.eq(control.dragPan, null, "'dragPan' set to null"); 
    58         t.eq(control.zoomBox, null, "'zoomBox' set to null"); 
    59         t.eq(control.wheelHandler, null, "'wheelHandler' set to null"); 
    60         t.eq(control.clickHandler, null, "'clickHandler' set to null"); 
     60        t.eq(control.dragPan, null, "'dragPan' set to null"); 
     61        t.eq(control.zoomBox, null, "'zoomBox' set to null"); 
     62        t.eq(control.handlers, null, "handlers set to null"); 
    6163 
    62        OpenLayers.Control.prototype.destroy = temp; 
     64        OpenLayers.Control.prototype.destroy = temp; 
    6365    } 
    6466 
  • trunk/openlayers/tests/Control/test_OverviewMap.html

    r6006 r6106  
    5252        t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); 
    5353 
    54         control.dragHandler = { 
     54        control.handlers.drag = { 
    5555            last: new OpenLayers.Pixel(5,5), 
    5656            destroy: function() {}