OpenLayers OpenLayers

Changeset 6155

Show
Ignore:
Timestamp:
02/08/08 20:09:15 (10 months ago)
Author:
tschaub
Message:

Adding events to controls. All controls trigger activate and deactivate events now. The panel listens for those events and redraws itself appropriately.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/events/lib/OpenLayers/Control.js

    r6125 r6155  
    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     * layer.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 layer loading starts. 
     133     *  - *deactivate* Triggered when layer loading ends. 
     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(); 
    137169        // eliminate circular references 
    138170        if (this.handler) { 
     
    196228            this.position = px.clone(); 
    197229        } 
    198         this.moveTo(this.position);         
     230        this.moveTo(this.position); 
    199231        return this.div; 
    200232    }, 
     
    233265        } 
    234266        this.active = true; 
     267        this.events.triggerEvent("activate"); 
    235268        return true; 
    236269    }, 
     
    251284            } 
    252285            this.active = false; 
     286            this.events.triggerEvent("deactivate"); 
    253287            return true; 
    254288        } 
  • sandbox/tschaub/events/lib/OpenLayers/Control/Panel.js

    r5910 r6155  
    4646        OpenLayers.Control.prototype.destroy.apply(this, arguments); 
    4747        for(var i = this.controls.length - 1 ; i >= 0; i--) { 
     48            this.controls[i].events.un({ 
     49                "activate": this.redraw, 
     50                "deactivate": this.redraw, 
     51                scope: this 
     52            }); 
    4853            OpenLayers.Event.stopObservingElement(this.controls[i].panel_div); 
    4954            this.controls[i].panel_div = null; 
     
    6166                } 
    6267            }     
    63             this.redraw(); 
    6468            return true; 
    6569        } else { 
     
    7680                this.controls[i].deactivate(); 
    7781            }     
    78             this.redraw(); 
    7982            return true; 
    8083        } else { 
     
    9497            this.map.addControl(this.controls[i]); 
    9598            this.controls[i].deactivate(); 
     99            this.controls[i].events.on({ 
     100                "activate": this.redraw, 
     101                "deactivate": this.redraw, 
     102                scope: this 
     103            }); 
    96104        } 
    97105        this.activate(); 
     
    103111     */ 
    104112    redraw: function() { 
     113        console.log('asdf'); 
    105114        this.div.innerHTML = ""; 
    106115        if (this.active) { 
     
    146155            } 
    147156        } 
    148         this.redraw(); 
    149157    }, 
    150158 
     
    186194                this.map.addControl(controls[i]); 
    187195                controls[i].deactivate(); 
     196                controls[i].events.on({ 
     197                    "activate": this.redraw, 
     198                    "deactivate": this.redraw, 
     199                    scope: this 
     200                }); 
    188201            } 
    189202            this.redraw();