New saveState option to restore the active state of controls in a panel after re-activating the panel. r=crschmidt,jorix (closes #2753)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10679 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -32,9 +32,25 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
* APIProperty: defaultControl
|
||||
* {<OpenLayers.Control>} The control which is activated when the control is
|
||||
* activated (turned on), which also happens at instantiation.
|
||||
* If <saveState> is true, <defaultControl> will be nullified after the
|
||||
* first activation of the panel.
|
||||
*/
|
||||
defaultControl: null,
|
||||
|
||||
/**
|
||||
* APIProperty: saveState
|
||||
* {Boolean} If set to true, the active state of this panel's controls will
|
||||
* be stored on panel deactivation, and restored on reactivation. Default
|
||||
* is false.
|
||||
*/
|
||||
saveState: false,
|
||||
|
||||
/**
|
||||
* Property: activeState
|
||||
* {Object} stores the active state of this panel's controls.
|
||||
*/
|
||||
activeState: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.Panel
|
||||
* Create a new control panel.
|
||||
@@ -71,6 +87,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
initialize: function(options) {
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.controls = [];
|
||||
this.activeState = {};
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -88,7 +105,8 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
OpenLayers.Event.stopObservingElement(this.controls[i].panel_div);
|
||||
this.controls[i].panel_div = null;
|
||||
}
|
||||
}
|
||||
this.activeState = null;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -96,11 +114,17 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
activate: function() {
|
||||
if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
|
||||
for(var i=0, len=this.controls.length; i<len; i++) {
|
||||
if (this.controls[i] == this.defaultControl) {
|
||||
this.controls[i].activate();
|
||||
var control;
|
||||
for (var i=0, len=this.controls.length; i<len; i++) {
|
||||
control = this.controls[i];
|
||||
if (control === this.defaultControl ||
|
||||
(this.saveState && this.activeState[control.id])) {
|
||||
control.activate();
|
||||
}
|
||||
}
|
||||
if (this.saveState === true) {
|
||||
this.defaultControl = null;
|
||||
}
|
||||
this.redraw();
|
||||
return true;
|
||||
} else {
|
||||
@@ -113,8 +137,10 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
deactivate: function() {
|
||||
if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
|
||||
for(var i=0, len=this.controls.length; i<len; i++) {
|
||||
this.controls[i].deactivate();
|
||||
var control;
|
||||
for (var i=0, len=this.controls.length; i<len; i++) {
|
||||
control = this.controls[i];
|
||||
this.activeState[control.id] = control.deactivate();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user