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:
+7
-1
@@ -9,7 +9,7 @@
|
|||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
background-color:red;
|
background-color:white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.olControlPanel .olControlMouseDefaultsItemActive {
|
.olControlPanel .olControlMouseDefaultsItemActive {
|
||||||
@@ -78,6 +78,12 @@
|
|||||||
{title:'Draw a feature'}),
|
{title:'Draw a feature'}),
|
||||||
new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent"})
|
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.addControl(panel);
|
||||||
|
|
||||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ OpenLayers.Control = OpenLayers.Class({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: type
|
* Property: type
|
||||||
* {OpenLayers.Control.TYPES} Controls can have a 'type'. The type
|
* {Number} Controls can have a 'type'. The type determines the type of
|
||||||
* determines the type of interactions which are possible with them when
|
* interactions which are possible with them when they are placed in an
|
||||||
* they are placed into a toolbar.
|
* <OpenLayers.Control.Panel>.
|
||||||
*/
|
*/
|
||||||
type: null,
|
type: null,
|
||||||
|
|
||||||
@@ -351,6 +351,17 @@ OpenLayers.Control = OpenLayers.Class({
|
|||||||
CLASS_NAME: "OpenLayers.Control"
|
CLASS_NAME: "OpenLayers.Control"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Control.TYPE_BUTTON
|
||||||
|
*/
|
||||||
OpenLayers.Control.TYPE_BUTTON = 1;
|
OpenLayers.Control.TYPE_BUTTON = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Control.TYPE_TOGGLE
|
||||||
|
*/
|
||||||
OpenLayers.Control.TYPE_TOGGLE = 2;
|
OpenLayers.Control.TYPE_TOGGLE = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Control.TYPE_TOOL
|
||||||
|
*/
|
||||||
OpenLayers.Control.TYPE_TOOL = 3;
|
OpenLayers.Control.TYPE_TOOL = 3;
|
||||||
|
|||||||
@@ -39,6 +39,31 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* Constructor: OpenLayers.Control.Panel
|
* Constructor: OpenLayers.Control.Panel
|
||||||
* Create a new 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:
|
* Parameters:
|
||||||
* options - {Object} An optional object whose properties will be used
|
* options - {Object} An optional object whose properties will be used
|
||||||
* to extend the control.
|
* to extend the control.
|
||||||
@@ -137,6 +162,11 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: activateControl
|
* 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:
|
* Parameters:
|
||||||
* control - {<OpenLayers.Control>}
|
* 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++) {
|
for (var i=0, len=this.controls.length; i<len; i++) {
|
||||||
if (this.controls[i] != control) {
|
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();
|
this.controls[i].deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +205,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* Control Panel.
|
* Control Panel.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* controls - {<OpenLayers.Control>}
|
* controls - {<OpenLayers.Control>} Controls to add in the panel.
|
||||||
*/
|
*/
|
||||||
addControls: function(controls) {
|
addControls: function(controls) {
|
||||||
if (!(controls instanceof Array)) {
|
if (!(controls instanceof Array)) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
|
t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
|
||||||
}
|
}
|
||||||
function test_Control_Panel_constructor2 (t) {
|
function test_Control_Panel_constructor2 (t) {
|
||||||
t.plan(11);
|
t.plan(16);
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
var toolControl = new OpenLayers.Control.ZoomBox();
|
var toolControl = new OpenLayers.Control.ZoomBox();
|
||||||
var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
|
var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
|
||||||
@@ -24,6 +24,11 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
var toggleControl = new ToggleControl();
|
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(
|
var panel = new OpenLayers.Control.Panel(
|
||||||
{defaultControl: anotherToolControl});
|
{defaultControl: anotherToolControl});
|
||||||
@@ -36,6 +41,7 @@
|
|||||||
panel.addControls([toolControl, anotherToolControl, toggleControl]);
|
panel.addControls([toolControl, anotherToolControl, toggleControl]);
|
||||||
t.eq(panel.controls.length, 3,
|
t.eq(panel.controls.length, 3,
|
||||||
"added three controls to the panel");
|
"added three controls to the panel");
|
||||||
|
panel.addControls([buttonControl]);
|
||||||
|
|
||||||
panel.redrawsCount = 0;
|
panel.redrawsCount = 0;
|
||||||
map.addControl(panel);
|
map.addControl(panel);
|
||||||
@@ -56,15 +62,23 @@
|
|||||||
panel.redrawsCount + " times.");
|
panel.redrawsCount + " times.");
|
||||||
|
|
||||||
panel.activateControl(toolControl);
|
panel.activateControl(toolControl);
|
||||||
t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active,
|
t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active && !buttonControl.active,
|
||||||
"activated one tool control, the other one is inactive and the toggle control also.");
|
"activated one tool control, the other one is inactive and the toggle & button controls also.");
|
||||||
|
|
||||||
panel.redrawsCount = 0;
|
panel.redrawsCount = 0;
|
||||||
panel.activateControl(toggleControl);
|
panel.activateControl(toggleControl);
|
||||||
t.ok((panel.redrawsCount > 0),"Redraw called on activated toggle " +
|
t.ok((panel.redrawsCount > 0),"Redraw called on activated toggle " +
|
||||||
panel.redrawsCount + " times.");
|
panel.redrawsCount + " times.");
|
||||||
t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
|
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.redrawsCount = 0;
|
||||||
panel.activateControl(anotherToolControl);
|
panel.activateControl(anotherToolControl);
|
||||||
@@ -73,6 +87,8 @@
|
|||||||
" times.");
|
" times.");
|
||||||
t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
|
t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
|
||||||
"activated the other tool control, the first one is inactive and the toggle control still 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) {
|
function test_Control_Panel_titles (t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user