allow toggling TYPE_TOOL controls in panels, p=jorix, r=me (closes #3294)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11965 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-05-10 07:13:22 +00:00
parent e1be8e9dfb
commit 0d45c5f148
2 changed files with 45 additions and 7 deletions

View File

@@ -46,6 +46,14 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
*/
saveState: false,
/**
* APIProperty: allowDepress
* {Boolean} If is true the <OpenLayers.Control.TYPE_TOOL> controls can
* be deactivated by clicking the icon that represents them. Default
* is false.
*/
allowDepress: false,
/**
* Property: activeState
* {Object} stores the active state of this panel's controls.
@@ -199,15 +207,19 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
}
return;
}
var c;
for (var i=0, len=this.controls.length; i<len; i++) {
c = this.controls[i];
if (c != control &&
(c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
c.deactivate();
if (this.allowDepress && control.active) {
control.deactivate();
} else {
var c;
for (var i=0, len=this.controls.length; i<len; i++) {
c = this.controls[i];
if (c != control &&
(c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
c.deactivate();
}
}
control.activate();
}
control.activate();
},
/**

View File

@@ -247,6 +247,7 @@
t.ok(!controlNoDeactive.active, "Tool control autoActivate:true is not active");
}
function test_Control_Panel_deactivate (t) {
t.plan(2);
var map = new OpenLayers.Map('map');
@@ -262,6 +263,31 @@
map.destroy();
}
function test_allowDepress (t) {
t.plan(2);
var map = new OpenLayers.Map('map');
var panel = new OpenLayers.Control.Panel();
panel.addControls([new OpenLayers.Control(),new OpenLayers.Control()]);
map.addControl(panel);
var control1 = panel.controls[1]
panel.activateControl(control1);
panel.allowDepress = false;
panel.activateControl(control1);
t.eq(control1.active, true,
"control1 remains active after calling again activateControl when allowDepress = false");
panel.allowDepress = true;
panel.activateControl(control1);
t.eq(control1.active, false,
"control1 is inactive after calling again activateControl when allowDepress = true");
// panel.deactivate();
map.destroy();
}
</script>
</head>
<body>