Files
openlayers/tests/Control/test_PanZoom.html
2007-12-17 06:29:46 +00:00

161 lines
7.7 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function test_01_Control_PanZoom_constructor (t) {
t.plan( 4 );
control = new OpenLayers.Control.PanZoom();
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
t.eq( control.displayClass, "olControlPanZoom", "displayClass is correct" );
control = new OpenLayers.Control.PanZoom({position: new OpenLayers.Pixel(100,100)});
t.eq( control.position.x, 100, "PanZoom X Set correctly.");
t.eq( control.position.y, 100, "PanZoom y Set correctly.");
}
function test_02_Control_PanZoom_addControl (t) {
t.plan( 8 );
map = new OpenLayers.Map('map');
control = new OpenLayers.Control.PanZoom();
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
map.addControl(control);
t.ok( control.map === map, "Control.map is set to the map object" );
t.ok( map.controls[4] === control, "map.controls contains control" );
t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Control div zIndexed properly" );
t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Viewport div contains control div" );
t.eq( control.div.style.top, "4px", "Control div top located correctly by default");
var control2 = new OpenLayers.Control.PanZoom();
map.addControl(control2, new OpenLayers.Pixel(100,100));
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
}
function test_03_Control_PanZoom_control_events (t) {
loader();
if ( !window.document.createEvent ) {
//ie can't simulate mouseclicks
t.plan(0)
} else {
t.plan(35);
t.delay_call( 1, function() {
var flag;
function setFlag(evt) {
flag[evt.type] = true;
}
function resetFlags() {
flag = {
mousedown: false,
mouseup: false,
click: false,
dblclick: false
};
}
resetFlags();
window.mapper.events.register("mousedown", mapper, setFlag);
window.mapper.events.register("mouseup", mapper, setFlag);
window.mapper.events.register("click", mapper, setFlag);
window.mapper.events.register("dblclick", mapper, setFlag);
simulateClick(window, window.control.buttons[0]);
t.ok( window.mapper.getCenter().lat > window.centerLL.lat, "Pan up works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[1]);
t.ok( window.mapper.getCenter().lon < window.centerLL.lon, "Pan left works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[2]);
t.ok( window.mapper.getCenter().lon == window.centerLL.lon, "Pan right works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[3]);
t.ok( window.mapper.getCenter().lat == window.centerLL.lat, "Pan down works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[4]);
t.eq( window.mapper.getZoom(), 6, "zoomin works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[6]);
t.eq( window.mapper.getZoom(), 5, "zoomout works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
simulateClick(window, window.control.buttons[5]);
t.eq( window.mapper.getZoom(), 2, "zoomworld works correctly" );
t.ok(!flag.mousedown, "mousedown does not get to the map");
t.ok(flag.mouseup, "mouseup does get to the map");
t.ok(!flag.click, "click does not get to the map");
t.ok(!flag.dblclick, "dblclick does not get to the map");
resetFlags();
});
}
}
function simulateClick(window, elem) {
var evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("mouseup", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("dblclick", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
}
function loader() {
control = new OpenLayers.Control.PanZoom();
mapper = new OpenLayers.Map('map', { controls: [control]});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
mapper.addLayer(layer);
centerLL = new OpenLayers.LonLat(0,0);
mapper.setCenter(centerLL, 5);
}
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>