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

@@ -79,13 +79,6 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
*/
clearOnDeactivate: false,
/**
* Property: events
* {<OpenLayers.Events>} An events object that will be used for registering
* listeners. Defaults to the map events for this control.
*/
events: null,
/**
* Property: registry
* {Object} An object with keys corresponding to event types. Values
@@ -144,9 +137,7 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
var previousOptions = {
trigger: OpenLayers.Function.bind(this.previousTrigger, this),
displayClass: this.displayClass + "Previous",
onActivate: function() {},
onDeactivate: function() {}
displayClass: this.displayClass + "Previous"
};
if(options) {
OpenLayers.Util.extend(previousOptions, options.previousOptions);
@@ -155,9 +146,7 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
var nextOptions = {
trigger: OpenLayers.Function.bind(this.nextTrigger, this),
displayClass: this.displayClass + "Next",
onActivate: function() {},
onDeactivate: function() {}
displayClass: this.displayClass + "Next"
};
if(options) {
OpenLayers.Util.extend(nextOptions, options.nextOptions);
@@ -179,10 +168,8 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
onPreviousChange: function(state, length) {
if(state && !this.previous.active) {
this.previous.activate();
this.previous.onActivate();
} else if(!state && this.previous.active) {
this.previous.deactivate();
this.previous.onDeactivate();
}
},
@@ -199,10 +186,8 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
onNextChange: function(state, length) {
if(state && !this.next.active) {
this.next.activate();
this.next.onActivate();
} else if(!state && this.next.active) {
this.next.deactivate();
this.next.onDeactivate();
}
},
@@ -364,11 +349,8 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
if(this.listeners == null) {
this.setListeners();
}
if(!this.events) {
this.events = this.map.events;
}
for(var type in this.listeners) {
this.events.register(type, this, this.listeners[type]);
this.map.events.register(type, this, this.listeners[type]);
}
activated = true;
if(this.previousStack.length == 0) {
@@ -402,7 +384,7 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
if(this.map) {
if(OpenLayers.Control.prototype.deactivate.apply(this)) {
for(var type in this.listeners) {
this.events.unregister(
this.map.events.unregister(
type, this, this.listeners[type]
);
}

View File

@@ -45,6 +45,11 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
destroy: function() {
OpenLayers.Control.prototype.destroy.apply(this, arguments);
for(var i = this.controls.length - 1 ; i >= 0; i--) {
this.controls[i].events.un({
"activate": this.redraw,
"deactivate": this.redraw,
scope: this
});
OpenLayers.Event.stopObservingElement(this.controls[i].panel_div);
this.controls[i].panel_div = null;
}
@@ -75,7 +80,6 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
for(var i = 0; i < this.controls.length; i++) {
this.controls[i].deactivate();
}
this.redraw();
return true;
} else {
return false;
@@ -93,6 +97,11 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
for (var i = 0; i < this.controls.length; i++) {
this.map.addControl(this.controls[i]);
this.controls[i].deactivate();
this.controls[i].events.on({
"activate": this.redraw,
"deactivate": this.redraw,
scope: this
});
}
this.activate();
return this.div;
@@ -145,7 +154,6 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
}
}
}
this.redraw();
},
/**
@@ -185,6 +193,11 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
for (var i = 0; i < controls.length; i++) {
this.map.addControl(controls[i]);
controls[i].deactivate();
controls[i].events.on({
"activate": this.redraw,
"deactivate": this.redraw,
scope: this
});
}
this.redraw();
}