diff --git a/examples/panel.html b/examples/panel.html index dcc8275303..36275e1290 100644 --- a/examples/panel.html +++ b/examples/panel.html @@ -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); diff --git a/lib/OpenLayers/Control.js b/lib/OpenLayers/Control.js index 9bae56580e..61118eb7ca 100644 --- a/lib/OpenLayers/Control.js +++ b/lib/OpenLayers/Control.js @@ -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 + * . */ 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; diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index 184be92fa8..772ff5e35c 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -33,12 +33,37 @@ OpenLayers.Control.Panel = OpenLayers.Class(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 method is called. + * + * Specific properties for controls on a panel: + * type - {Number} One of , + * , . + * If not provided, is assumed. + * title - {string} Text displayed when mouse is over the icon that + * represents the control. + * + * The of a control determines the behavior when + * clicking its icon: + * - The control is activated and other + * controls of this type in the same panel are deactivated. This is + * the default type. + * - The active state of the control is + * toggled. + * - The + * method of the control is called, + * but its active state is not changed. + * + * If a control is , 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 . + * * Parameters: * control - {} */ @@ -159,7 +189,8 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { } for (var i=0, len=this.controls.length; i} + * controls - {} Controls to add in the panel. */ addControls: function(controls) { if (!(controls instanceof Array)) { diff --git a/tests/Control/Panel.html b/tests/Control/Panel.html index 88ad431f30..2c7474a19d 100644 --- a/tests/Control/Panel.html +++ b/tests/Control/Panel.html @@ -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);