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:
@@ -46,6 +46,14 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
saveState: false,
|
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
|
* Property: activeState
|
||||||
* {Object} stores the active state of this panel's controls.
|
* {Object} stores the active state of this panel's controls.
|
||||||
@@ -199,15 +207,19 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var c;
|
if (this.allowDepress && control.active) {
|
||||||
for (var i=0, len=this.controls.length; i<len; i++) {
|
control.deactivate();
|
||||||
c = this.controls[i];
|
} else {
|
||||||
if (c != control &&
|
var c;
|
||||||
(c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
|
for (var i=0, len=this.controls.length; i<len; i++) {
|
||||||
c.deactivate();
|
c = this.controls[i];
|
||||||
|
if (c != control &&
|
||||||
|
(c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
|
||||||
|
c.deactivate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
control.activate();
|
||||||
}
|
}
|
||||||
control.activate();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -247,6 +247,7 @@
|
|||||||
t.ok(!controlNoDeactive.active, "Tool control autoActivate:true is not active");
|
t.ok(!controlNoDeactive.active, "Tool control autoActivate:true is not active");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_Panel_deactivate (t) {
|
function test_Control_Panel_deactivate (t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
@@ -262,6 +263,31 @@
|
|||||||
|
|
||||||
map.destroy();
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user