Giving all controls an events instance. You can now listen for activate and deactivate on any control. Panel controls do this to know when they should redraw. Navigation history control demonstrates the effect of this change. r=elemoine (closes #1346)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6167 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-09 16:46:02 +00:00
parent 9bfd829512
commit bf224d699d
5 changed files with 61 additions and 40 deletions

View File

@@ -104,6 +104,36 @@ OpenLayers.Control = OpenLayers.Class({
*/
handler: null,
/**
* Property: events
* {<OpenLayers.Events>} Events instance for triggering control specific
* events.
*/
events: null,
/**
* Constant: EVENT_TYPES
* {Array(String)} Supported application event types. Register a listener
* for a particular event with the following syntax:
* (code)
* control.events.register(type, obj, listener);
* (end)
*
* Listeners will be called with a reference to an event object. The
* properties of this event depends on exactly what happened.
*
* All event objects have at least the following properties:
* - *object* {Object} A reference to control.events.object (a reference
* to the control).
* - *element* {DOMElement} A reference to control.events.element (which
* will be null unless documented otherwise).
*
* Supported map event types:
* - *activate* Triggered when activated.
* - *deactivate* Triggered when deactivated.
*/
EVENT_TYPES: ["activate", "deactivate"],
/**
* Constructor: OpenLayers.Control
* Create an OpenLayers Control. The options passed as a parameter
@@ -124,6 +154,7 @@ OpenLayers.Control = OpenLayers.Class({
OpenLayers.Util.extend(this, options);
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
},
@@ -134,6 +165,7 @@ OpenLayers.Control = OpenLayers.Class({
* to prevent memory leaks.
*/
destroy: function () {
this.events.destroy();
// eliminate circular references
if (this.handler) {
this.handler.destroy();
@@ -232,6 +264,7 @@ OpenLayers.Control = OpenLayers.Class({
this.handler.activate();
}
this.active = true;
this.events.triggerEvent("activate");
return true;
},
@@ -250,6 +283,7 @@ OpenLayers.Control = OpenLayers.Class({
this.handler.deactivate();
}
this.active = false;
this.events.triggerEvent("deactivate");
return true;
}
return false;