git-svn-id: http://svn.openlayers.org/trunk/openlayers@10576 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
167 lines
7.4 KiB
HTML
167 lines
7.4 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
function test_Control_Panel_constructor (t) {
|
|
t.plan( 2 );
|
|
|
|
control = new OpenLayers.Control.Panel();
|
|
t.ok( control instanceof OpenLayers.Control.Panel, "new OpenLayers.Control returns object" );
|
|
t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
|
|
}
|
|
function test_Control_Panel_constructor2 (t) {
|
|
t.plan(16);
|
|
var map = new OpenLayers.Map('map');
|
|
var toolControl = new OpenLayers.Control.ZoomBox();
|
|
var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
|
|
CLASS_NAME: 'mbControl.TestTool',
|
|
type: OpenLayers.Control.TYPE_TOOL
|
|
});
|
|
var anotherToolControl = new AnotherToolControl();
|
|
var ToggleControl = OpenLayers.Class(OpenLayers.Control, {
|
|
CLASS_NAME: 'mbControl.TestToggle',
|
|
type: OpenLayers.Control.TYPE_TOGGLE
|
|
});
|
|
|
|
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});
|
|
t.ok(panel instanceof OpenLayers.Control.Panel,
|
|
"new OpenLayers.Control.Panel returns object");
|
|
panel.redraw = function(){
|
|
panel.redrawsCount++;
|
|
};
|
|
|
|
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);
|
|
t.ok((panel.redrawsCount > 0), "Redraw called on add panel to map " +
|
|
panel.redrawsCount + " times.");
|
|
t.ok((panel.active),"Panel is active after add panel to map.");
|
|
|
|
panel.redrawsCount = 0;
|
|
panel.addControls(new AnotherToolControl());
|
|
t.ok((panel.redrawsCount > 0),
|
|
"Redraw called on add control to panel after add panel to map " +
|
|
panel.redrawsCount + " times.");
|
|
|
|
panel.deactivate();
|
|
panel.redrawsCount = 0;
|
|
panel.activate();
|
|
t.ok((panel.redrawsCount > 0),"Redraw called on activate panel " +
|
|
panel.redrawsCount + " times.");
|
|
|
|
panel.activateControl(toolControl);
|
|
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 & 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);
|
|
t.ok((panel.redrawsCount > 0),
|
|
"Redraw called on activated tool control " + panel.redrawsCount +
|
|
" 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);
|
|
var panel = new OpenLayers.Control.Panel();
|
|
var toolControl = new OpenLayers.Control.ZoomBox({
|
|
title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."
|
|
});
|
|
panel.addControls([toolControl]);
|
|
t.eq(panel.controls.length, 1, "added a control to the panel");
|
|
t.eq(panel.controls[0].title, toolControl.panel_div.title, "the title is correctly set");
|
|
}
|
|
|
|
function test_Control_Panel_getBy(t) {
|
|
|
|
var panel = {
|
|
getBy: OpenLayers.Control.Panel.prototype.getBy,
|
|
getControlsBy: OpenLayers.Control.Panel.prototype.getControlsBy,
|
|
controls: [
|
|
{foo: "foo", id: Math.random()},
|
|
{foo: "bar", id: Math.random()},
|
|
{foo: "foobar", id: Math.random()},
|
|
{foo: "foo bar", id: Math.random()},
|
|
{foo: "foo", id: Math.random()}
|
|
]
|
|
};
|
|
|
|
var cases = [
|
|
{
|
|
got: panel.getControlsBy("foo", "foo"),
|
|
expected: [panel.controls[0], panel.controls[4]],
|
|
message: "(string literal) got two controls matching foo"
|
|
}, {
|
|
got: panel.getControlsBy("foo", "bar"),
|
|
expected: [panel.controls[1]],
|
|
message: "(string literal) got one control matching foo"
|
|
}, {
|
|
got: panel.getControlsBy("foo", "barfoo"),
|
|
expected: [],
|
|
message: "(string literal) got empty array for no foo match"
|
|
}, {
|
|
got: panel.getControlsBy("foo", /foo/),
|
|
expected: [panel.controls[0], panel.controls[2], panel.controls[3], panel.controls[4]],
|
|
message: "(regexp literal) got three controls containing string"
|
|
}, {
|
|
got: panel.getControlsBy("foo", /foo$/),
|
|
expected: [panel.controls[0], panel.controls[4]],
|
|
message: "(regexp literal) got three controls ending with string"
|
|
}, {
|
|
got: panel.getControlsBy("foo", /\s/),
|
|
expected: [panel.controls[3]],
|
|
message: "(regexp literal) got control containing space"
|
|
}, {
|
|
got: panel.getControlsBy("foo", new RegExp("BAR", "i")),
|
|
expected: [panel.controls[1], panel.controls[2], panel.controls[3]],
|
|
message: "(regexp object) got layers ignoring case"
|
|
}, {
|
|
got: panel.getControlsBy("foo", {test: function(str) {return str.length > 3;}}),
|
|
expected: [panel.controls[2], panel.controls[3]],
|
|
message: "(custom object) got controls with foo length greater than 3"
|
|
}
|
|
];
|
|
t.plan(cases.length);
|
|
for(var i=0; i<cases.length; ++i) {
|
|
t.eq(cases[i].got, cases[i].expected, cases[i].message);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 1024px; height: 512px;"/>
|
|
</body>
|
|
</html>
|