Do not change the active state of button controls on a panel when a tool control is activated. p=jorix, r=me (closes #2764)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10576 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-08-04 07:56:25 +00:00
parent 9d3c4ecb1c
commit ea1290f8d8
4 changed files with 78 additions and 14 deletions

View File

@@ -9,7 +9,7 @@
width: 24px;
height: 24px;
margin: 5px;
background-color:red;
background-color:white;
}
.olControlPanel .olControlMouseDefaultsItemActive {
@@ -78,6 +78,12 @@
{title:'Draw a feature'}),
new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent"})
]);
nav = new OpenLayers.Control.NavigationHistory();
// parent control must be added to the map
map.addControl(nav);
panel.addControls([nav.next, nav.previous]);
map.addControl(panel);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);

View File

@@ -76,9 +76,9 @@ OpenLayers.Control = OpenLayers.Class({
/**
* Property: type
* {OpenLayers.Control.TYPES} Controls can have a 'type'. The type
* determines the type of interactions which are possible with them when
* they are placed into a toolbar.
* {Number} Controls can have a 'type'. The type determines the type of
* interactions which are possible with them when they are placed in an
* <OpenLayers.Control.Panel>.
*/
type: null,
@@ -351,6 +351,17 @@ OpenLayers.Control = OpenLayers.Class({
CLASS_NAME: "OpenLayers.Control"
});
/**
* Constant: OpenLayers.Control.TYPE_BUTTON
*/
OpenLayers.Control.TYPE_BUTTON = 1;
/**
* Constant: OpenLayers.Control.TYPE_TOGGLE
*/
OpenLayers.Control.TYPE_TOGGLE = 2;
/**
* Constant: OpenLayers.Control.TYPE_TOOL
*/
OpenLayers.Control.TYPE_TOOL = 3;

View File

@@ -33,12 +33,37 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
* {<OpenLayers.Control>} The control which is activated when the control is
* activated (turned on), which also happens at instantiation.
*/
defaultControl: null,
defaultControl: null,
/**
* Constructor: OpenLayers.Control.Panel
* Create a new control panel.
*
*
* Each control in the panel is represented by an icon. When clicking
* on an icon, the <activateControl> method is called.
*
* Specific properties for controls on a panel:
* type - {Number} One of <OpenLayers.Control.TYPE_TOOL>,
* <OpenLayers.Control.TYPE_TOGGLE>, <OpenLayers.Control.TYPE_BUTTON>.
* If not provided, <OpenLayers.Control.TYPE_TOOL> is assumed.
* title - {string} Text displayed when mouse is over the icon that
* represents the control.
*
* The <OpenLayers.Control.type> of a control determines the behavior when
* clicking its icon:
* <OpenLayers.Control.TYPE_TOOL> - The control is activated and other
* controls of this type in the same panel are deactivated. This is
* the default type.
* <OpenLayers.Control.TYPE_TOGGLE> - The active state of the control is
* toggled.
* <OpenLayers.Control.TYPE_BUTTON> - The
* <OpenLayers.Control.Button.trigger> method of the control is called,
* but its active state is not changed.
*
* If a control is <OpenLayers.Control.active>, it will be drawn with the
* olControl[Name]ItemActive class, otherwise with the
* olControl[Name]ItemInactive class.
*
* Parameters:
* options - {Object} An optional object whose properties will be used
* to extend the control.
@@ -137,7 +162,12 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
/**
* APIMethod: activateControl
*
* This method is called when the user click on the icon representing a
* control in the panel.
*
* The action that triggers depends on the type of control, see the
* description of the types of controls in the method <addControls>.
*
* Parameters:
* control - {<OpenLayers.Control>}
*/
@@ -159,7 +189,8 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
}
for (var i=0, len=this.controls.length; i<len; i++) {
if (this.controls[i] != control) {
if (this.controls[i].type != OpenLayers.Control.TYPE_TOGGLE) {
if (this.controls[i].type === OpenLayers.Control.TYPE_TOOL ||
this.controls[i].type === null) {
this.controls[i].deactivate();
}
}
@@ -174,7 +205,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
* Control Panel.
*
* Parameters:
* controls - {<OpenLayers.Control>}
* controls - {<OpenLayers.Control>} Controls to add in the panel.
*/
addControls: function(controls) {
if (!(controls instanceof Array)) {

View File

@@ -10,7 +10,7 @@
t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
}
function test_Control_Panel_constructor2 (t) {
t.plan(11);
t.plan(16);
var map = new OpenLayers.Map('map');
var toolControl = new OpenLayers.Control.ZoomBox();
var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
@@ -24,6 +24,11 @@
});
var toggleControl = new ToggleControl();
var buttonControl = new OpenLayers.Control.Button({
trigger: function () {
t.ok(true, "trigger function of button is called.");
}
});
var panel = new OpenLayers.Control.Panel(
{defaultControl: anotherToolControl});
@@ -36,6 +41,7 @@
panel.addControls([toolControl, anotherToolControl, toggleControl]);
t.eq(panel.controls.length, 3,
"added three controls to the panel");
panel.addControls([buttonControl]);
panel.redrawsCount = 0;
map.addControl(panel);
@@ -56,15 +62,23 @@
panel.redrawsCount + " times.");
panel.activateControl(toolControl);
t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active,
"activated one tool control, the other one is inactive and the toggle control also.");
t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active && !buttonControl.active,
"activated one tool control, the other one is inactive and the toggle & button controls also.");
panel.redrawsCount = 0;
panel.activateControl(toggleControl);
t.ok((panel.redrawsCount > 0),"Redraw called on activated toggle " +
panel.redrawsCount + " times.");
t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
"activated the toggle control, which has no influence on the tool controls.");
"activated the toggle control, which has no influence on the tool & togggle controls.");
panel.activateControl(buttonControl);
t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
"activateContol calling for button, which has no influence on the tool & togggle controls.");
t.ok(!buttonControl.active,
"activateContol calling for button, button remains inactive.");
buttonControl.activate();
t.ok(buttonControl.active && toolControl.active && !anotherToolControl.active && toggleControl.active,
"activated the button control, which has no influence on the tool & togggle controls.");
panel.redrawsCount = 0;
panel.activateControl(anotherToolControl);
@@ -73,6 +87,8 @@
" times.");
t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
"activated the other tool control, the first one is inactive and the toggle control still active.");
t.ok(buttonControl.active,
"activated the other tool control, the button control still active.");
}
function test_Control_Panel_titles (t) {
t.plan(2);