OpenLayers OpenLayers

Changeset 6175

Show
Ignore:
Timestamp:
02/09/08 14:24:48 (10 months ago)
Author:
ahocevar
Message:

merging from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/ahocevar/styleMap/examples/navigation-history.html

    r6166 r6175  
    3737                map = new OpenLayers.Map('map'); 
    3838                 
    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 
    5441                map.addControl(nav); 
    5542 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Control.js

    r6106 r6175  
    105105    handler: null, 
    106106 
     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 
    107137    /** 
    108138     * Constructor: OpenLayers.Control 
     
    125155        OpenLayers.Util.extend(this, options); 
    126156         
     157        this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES); 
    127158        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 
    128159    }, 
     
    135166     */ 
    136167    destroy: function () { 
     168        this.events.destroy(); 
     169        this.events = null; 
    137170        // eliminate circular references 
    138171        if (this.handler) { 
     
    233266        } 
    234267        this.active = true; 
     268        this.events.triggerEvent("activate"); 
    235269        return true; 
    236270    }, 
     
    251285            } 
    252286            this.active = false; 
     287            this.events.triggerEvent("deactivate"); 
    253288            return true; 
    254289        } 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Control/NavigationHistory.js

    r6166 r6175  
    8181 
    8282    /** 
    83      * Property: events 
    84      * {<OpenLayers.Events>} An events object that will be used for registering 
    85      *     listeners.  Defaults to the map events for this control. 
    86      */ 
    87     events: null, 
    88  
    89     /** 
    9083     * Property: registry 
    9184     * {Object} An object with keys corresponding to event types.  Values 
     
    145138        var previousOptions = { 
    146139            trigger: OpenLayers.Function.bind(this.previousTrigger, this), 
    147             displayClass: this.displayClass + "Previous", 
    148             onActivate: function() {}, 
    149             onDeactivate: function() {} 
     140            displayClass: this.displayClass + "Previous" 
    150141        }; 
    151142        if(options) { 
     
    156147        var nextOptions = { 
    157148            trigger: OpenLayers.Function.bind(this.nextTrigger, this), 
    158             displayClass: this.displayClass + "Next", 
    159             onActivate: function() {}, 
    160             onDeactivate: function() {} 
     149            displayClass: this.displayClass + "Next" 
    161150        }; 
    162151        if(options) { 
     
    180169        if(state && !this.previous.active) { 
    181170            this.previous.activate(); 
    182             this.previous.onActivate(); 
    183171        } else if(!state && this.previous.active) { 
    184172            this.previous.deactivate(); 
    185             this.previous.onDeactivate(); 
    186173        } 
    187174    }, 
     
    200187        if(state && !this.next.active) { 
    201188            this.next.activate(); 
    202             this.next.onActivate(); 
    203189        } else if(!state && this.next.active) { 
    204190            this.next.deactivate(); 
    205             this.next.onDeactivate(); 
    206191        } 
    207192    }, 
     
    365350                    this.setListeners(); 
    366351                } 
    367                 if(!this.events) { 
    368                     this.events = this.map.events; 
    369                 } 
    370352                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]); 
    372354                } 
    373355                activated = true; 
     
    403385            if(OpenLayers.Control.prototype.deactivate.apply(this)) { 
    404386                for(var type in this.listeners) { 
    405                     this.events.unregister( 
     387                    this.map.events.unregister( 
    406388                        type, this, this.listeners[type] 
    407389                    ); 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Control/Panel.js

    r5910 r6175  
    4646        OpenLayers.Control.prototype.destroy.apply(this, arguments); 
    4747        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            } 
    4855            OpenLayers.Event.stopObservingElement(this.controls[i].panel_div); 
    4956            this.controls[i].panel_div = null; 
     
    7683                this.controls[i].deactivate(); 
    7784            }     
    78             this.redraw(); 
    7985            return true; 
    8086        } else { 
     
    94100            this.map.addControl(this.controls[i]); 
    95101            this.controls[i].deactivate(); 
     102            this.controls[i].events.on({ 
     103                "activate": this.redraw, 
     104                "deactivate": this.redraw, 
     105                scope: this 
     106            }); 
    96107        } 
    97108        this.activate(); 
     
    146157            } 
    147158        } 
    148         this.redraw(); 
    149159    }, 
    150160 
     
    186196                this.map.addControl(controls[i]); 
    187197                controls[i].deactivate(); 
     198                controls[i].events.on({ 
     199                    "activate": this.redraw, 
     200                    "deactivate": this.redraw, 
     201                    scope: this 
     202                }); 
    188203            } 
    189204            this.redraw(); 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Control/SelectFeature.js

    r6166 r6175  
    262262        this.layer.events.triggerEvent("featureselected", {feature: feature}); 
    263263        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}); 
    264267        this.onSelect(feature); 
    265268    }, 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Grid.js

    r6152 r6175  
    671671        this.clearGrid(); 
    672672        this.setTileSize(); 
    673         this.initSingleTile(this.map.getExtent()); 
    674673      } 
    675674    }, 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/HTTPRequest.js

    r5614 r6175  
    116116     * Parameters: 
    117117     * newParams - {Object} 
     118     * 
     119     * Returns: 
     120     * redrawn: {Boolean} whether the layer was actually redrawn. 
    118121     */ 
    119122    mergeNewParams:function(newParams) { 
    120123        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        } 
    122143    }, 
    123144     
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/Vector.js

    r6165 r6175  
    268268    moveTo: function(bounds, zoomChanged, dragging) { 
    269269        OpenLayers.Layer.prototype.moveTo.apply(this, arguments); 
    270          
     270 
    271271        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"; 
    274276            var extent = this.map.getExtent(); 
    275277            this.renderer.setExtent(extent); 
    276         } 
    277  
     278             
     279            this.renderer.root.style.visibility = "visible"; 
     280        } 
     281         
    278282        if (!this.drawn || zoomChanged) { 
    279283            this.drawn = true; 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WFS.js

    r6152 r6175  
    385385        var upperParams = OpenLayers.Util.upperCaseObject(newParams); 
    386386        var newArguments = [upperParams]; 
    387         OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
     387        return OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this,  
    388388                                                                 newArguments); 
    389389    }, 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Layer/WMS.js

    r5614 r6175  
    194194        var upperParams = OpenLayers.Util.upperCaseObject(newParams); 
    195195        var newArguments = [upperParams]; 
    196         OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,  
     196        return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,  
    197197                                                             newArguments); 
    198198    }, 
  • sandbox/ahocevar/styleMap/lib/OpenLayers/Map.js

    r6152 r6175  
    486486        }     
    487487 
     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        } 
    488494        if (this.layers != null) { 
    489495            for (var i = this.layers.length - 1; i>=0; --i) { 
     
    493499            }  
    494500            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; 
    501501        } 
    502502        if (this.viewPortDiv) { 
  • sandbox/ahocevar/styleMap/tests/Control/test_ModifyFeature.html

    r6152 r6175  
    66    function test_ModifyFeature_constructor(t) { 
    77        t.plan(3); 
    8         var layer = {name: "foo", styleMap: {createSymbolizer: function(){}}};    
    98        var layer = { 
    109            styleMap: {createSymbolizer: function(){}}, 
  • sandbox/ahocevar/styleMap/tests/Control/test_Navigation.html

    r6131 r6175  
    1818 
    1919    function test_Control_Navigation_destroy (t) { 
    20         t.plan(9); 
     20        t.plan(10); 
    2121         
    2222        var temp = OpenLayers.Control.prototype.destroy; 
     
    2727 
    2828        var control = { 
     29            events: { 
     30                destroy: function() { 
     31                    t.ok(true, "events destroyed"); 
     32                } 
     33            }, 
    2934            'deactivate': function() { 
    3035                t.ok(true, "navigation control deactivated before being destroyed");