3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 function test_Control_Panel_constructor (t) {
8 control = new OpenLayers.Control.Panel();
9 t.ok( control instanceof OpenLayers.Control.Panel, "new OpenLayers.Control returns object" );
10 t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
12 function test_Control_Panel_constructor (t) {
14 var map = new OpenLayers.Map('map');
15 var panel = new OpenLayers.Control.Panel();
16 var toolControl = new OpenLayers.Control.ZoomBox();
17 var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
18 CLASS_NAME: 'mbControl.TestTool',
19 type: OpenLayers.Control.TYPE_TOOL
21 var anotherToolControl = new AnotherToolControl();
22 var ToggleControl = OpenLayers.Class(OpenLayers.Control, {
23 CLASS_NAME: 'mbControl.TestToggle',
24 type: OpenLayers.Control.TYPE_TOGGLE
26 var toggleControl = new ToggleControl();
28 t.ok(panel instanceof OpenLayers.Control.Panel,
29 "new OpenLayers.Control.Panel returns object");
31 panel.addControls([toolControl, anotherToolControl, toggleControl]);
33 t.eq(panel.controls.length, 3,
34 "added three controls to the panel");
35 map.addControl(panel);
37 panel.activateControl(toolControl);
38 t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active,
39 "activated one tool control, the other one is inactive and the toggle control also.");
41 panel.redraw = function(){
42 t.ok(true,"Redraw called on activated toggle");
45 panel.activateControl(toggleControl);
46 t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
47 "activated the toggle control, which has no influence on the tool controls.");
49 panel.activateControl(anotherToolControl);
50 t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
51 "activated the other tool control, the first one is inactive and the toggle control still active.");
53 function test_Control_Panel_titles (t) {
55 var panel = new OpenLayers.Control.Panel();
56 var toolControl = new OpenLayers.Control.ZoomBox({
57 title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."
59 panel.addControls([toolControl]);
60 t.eq(panel.controls.length, 1, "added a control to the panel");
61 t.eq(panel.controls[0].title, toolControl.panel_div.title, "the title is correctly set");
64 function test_Control_Panel_getBy(t) {
67 getBy: OpenLayers.Control.Panel.prototype.getBy,
68 getControlsBy: OpenLayers.Control.Panel.prototype.getControlsBy,
70 {foo: "foo", id: Math.random()},
71 {foo: "bar", id: Math.random()},
72 {foo: "foobar", id: Math.random()},
73 {foo: "foo bar", id: Math.random()},
74 {foo: "foo", id: Math.random()}
80 got: panel.getControlsBy("foo", "foo"),
81 expected: [panel.controls[0], panel.controls[4]],
82 message: "(string literal) got two controls matching foo"
84 got: panel.getControlsBy("foo", "bar"),
85 expected: [panel.controls[1]],
86 message: "(string literal) got one control matching foo"
88 got: panel.getControlsBy("foo", "barfoo"),
90 message: "(string literal) got empty array for no foo match"
92 got: panel.getControlsBy("foo", /foo/),
93 expected: [panel.controls[0], panel.controls[2], panel.controls[3], panel.controls[4]],
94 message: "(regexp literal) got three controls containing string"
96 got: panel.getControlsBy("foo", /foo$/),
97 expected: [panel.controls[0], panel.controls[4]],
98 message: "(regexp literal) got three controls ending with string"
100 got: panel.getControlsBy("foo", /\s/),
101 expected: [panel.controls[3]],
102 message: "(regexp literal) got control containing space"
104 got: panel.getControlsBy("foo", new RegExp("BAR", "i")),
105 expected: [panel.controls[1], panel.controls[2], panel.controls[3]],
106 message: "(regexp object) got layers ignoring case"
108 got: panel.getControlsBy("foo", {test: function(str) {return str.length > 3;}}),
109 expected: [panel.controls[2], panel.controls[3]],
110 message: "(custom object) got controls with foo length greater than 3"
113 t.plan(cases.length);
114 for(var i=0; i<cases.length; ++i) {
115 t.eq(cases[i].got, cases[i].expected, cases[i].message);
124 <div id="map" style="width: 1024px; height: 512px;"/>