git-svn-id: http://svn.openlayers.org/trunk/openlayers@11229 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
174 lines
6.8 KiB
HTML
174 lines
6.8 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../OLLoader.js"></script>
|
|
<script type="text/javascript">
|
|
var map;
|
|
function test_Control_PanZoomBar_constructor (t) {
|
|
t.plan( 4 );
|
|
|
|
control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100)});
|
|
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
|
|
t.eq( control.displayClass, "olControlPanZoomBar", "displayClass is correct" );
|
|
t.eq( control.position.x, 100, "PanZoom X Set correctly.");
|
|
t.eq( control.position.y, 100, "PanZoom y Set correctly.");
|
|
}
|
|
function test_Control_PanZoomBar_addControl (t) {
|
|
t.plan( 8 );
|
|
map = new OpenLayers.Map('map', {controls:[]});
|
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(layer);
|
|
control = new OpenLayers.Control.PanZoomBar();
|
|
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar 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[0] === control, "map.controls contains control" );
|
|
t.eq( parseInt(control.div.style.zIndex), 1001, "Control div zIndexed properly" );
|
|
t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), 1001, "Viewport div contains control div" );
|
|
t.eq( control.div.style.top, "4px", "Control div top located correctly by default");
|
|
|
|
var control2 = new OpenLayers.Control.PanZoomBar();
|
|
map.addControl(control2, new OpenLayers.Pixel(100,100));
|
|
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
|
|
}
|
|
|
|
function test_Control_PanZoomBar_clearDiv(t) {
|
|
t.plan(2);
|
|
map = new OpenLayers.Map('map', {controls:[]});
|
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(layer);
|
|
control = new OpenLayers.Control.PanZoomBar();
|
|
map.addControl(control);
|
|
control.removeButtons();
|
|
map.destroy();
|
|
t.eq(control.div.childNodes.length, 0, "control's div cleared.");
|
|
t.eq(control.zoombarDiv, null, "zoombar div nullified.")
|
|
}
|
|
|
|
function test_Control_PanZoomBar_divClick (t) {
|
|
t.plan(2);
|
|
map = new OpenLayers.Map('map', {controls:[]});
|
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
|
map.addLayer(layer);
|
|
control = new OpenLayers.Control.PanZoomBar();
|
|
map.addControl(control);
|
|
control.divClick({'xy': {'x': 0, 'y': 50}, which: 1});
|
|
t.eq(map.zoom, 11, "zoom is correct on standard map");
|
|
|
|
map.fractionalZoom = true;
|
|
control.divClick({'xy': {'x': 0, 'y': 49}, which: 1});
|
|
t.eq(map.zoom.toFixed(3), '10.545', "zoom is correct on fractional zoom map");
|
|
|
|
}
|
|
|
|
function test_Control_PanZoomBar_forceFixedZoomLevel_divClick(t){
|
|
t.plan(1);
|
|
map = new OpenLayers.Map('map', {
|
|
controls: [],
|
|
fractionalZoom: true
|
|
});
|
|
var layer = new OpenLayers.Layer.WMS("Test Layer", "http://octo.metacarta.com/cgi-bin/mapserv?", {
|
|
map: "/mapdata/vmap_wms.map",
|
|
layers: "basic"
|
|
});
|
|
map.addLayer(layer);
|
|
control = new OpenLayers.Control.PanZoomBar({
|
|
forceFixedZoomLevel: true
|
|
});
|
|
map.addControl(control);
|
|
|
|
control.divClick({
|
|
'xy': {
|
|
'x': 0,
|
|
'y': 49
|
|
},
|
|
which: 1
|
|
});
|
|
t.eq(map.zoom, 11, "forceFixedZoomLevel makes sure that after a div click only fixed zoom levels are used even if the map has fractionalZoom");
|
|
}
|
|
|
|
function test_Control_PanZoomBar_forceFixedZoomLevel_zoomBarUp (t) {
|
|
var numRandomDrags = 25;
|
|
// plan one static recorded test and two for every random drag
|
|
t.plan(1 + (numRandomDrags * 2));
|
|
|
|
|
|
var map = new OpenLayers.Map('map', {
|
|
controls: [],
|
|
fractionalZoom: true
|
|
});
|
|
var layer = new OpenLayers.Layer.WMS("Test Layer", "http://octo.metacarta.com/cgi-bin/mapserv?", {
|
|
map: "/mapdata/vmap_wms.map",
|
|
layers: "basic"
|
|
});
|
|
map.addLayer(layer);
|
|
|
|
// zoom to a fractional ZoomLevel initially:
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 9.545);
|
|
|
|
control = new OpenLayers.Control.PanZoomBar({
|
|
forceFixedZoomLevel: true
|
|
});
|
|
map.addControl(control);
|
|
|
|
// The y values come from manually recording real values in an example
|
|
var evt = {
|
|
'xy': {
|
|
'x': 0,
|
|
'y': -10.633
|
|
},
|
|
which: 1
|
|
};
|
|
control.zoomStart = {
|
|
'x': 0,
|
|
'y': 5.366
|
|
};
|
|
control.mouseDragStart = {
|
|
'x': 0,
|
|
'y': -10.633
|
|
};
|
|
control.deltaY = control.zoomStart.y - evt.xy.y
|
|
control.zoomBarUp(evt);
|
|
t.eq(map.zoom, 11, "forceFixedZoomLevel makes sure that after dragging of the handle only fixed zoom levels are used even if the map has fractionalZoom");
|
|
|
|
// randomly drag the handle around
|
|
// we should never get a zoom < 0 or a non-integer zoom, regardless of
|
|
// captured random values for start and end of the drag.
|
|
for (var i = 0; i < numRandomDrags; i++) {
|
|
var randStartY = Math.random() * 10 * ((i % 2 === 0) ? -1 : 1);
|
|
var randStopY = Math.random() * 160 * ((i % 2 === 1) ? -1 : 1);
|
|
var evt = {
|
|
'xy': {
|
|
'x': 0,
|
|
'y': randStopY
|
|
},
|
|
which: 1
|
|
};
|
|
control.zoomStart = {
|
|
'x': 0,
|
|
'y': randStartY
|
|
};
|
|
control.mouseDragStart = {
|
|
'x': 0,
|
|
'y': randStopY
|
|
};
|
|
control.deltaY = control.zoomStart.y - evt.xy.y
|
|
control.zoomBarUp(evt);
|
|
|
|
t.eq(Math.floor(map.zoom), Math.ceil(map.zoom), 'Only integer zooms after random handle drag with forceFixedZoomLevel=true and fractionalZoom=true (current zoom was ' + map.zoom + ')');
|
|
t.ok(map.zoom >= 0, 'map.zoom is never < 0 after random handle drag with forceFixedZoomLevel=true and fractionalZoom=true');
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 1024px; height: 512px;"/>
|
|
</body>
|
|
</html>
|