git-svn-id: http://svn.openlayers.org/trunk/openlayers@6177 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
144 lines
6.8 KiB
HTML
144 lines
6.8 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_initialize(t) {
|
|
t.plan(2);
|
|
var control = new OpenLayers.Control.ScaleLine();
|
|
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
t.eq(control.displayClass, "olControlScaleLine", "displayClass is correct" );
|
|
control.destroy();
|
|
}
|
|
|
|
function test_initwithelem(t) {
|
|
t.plan(1);
|
|
var control = new OpenLayers.Control.ScaleLine({"div":OpenLayers.Util.getElement('ScaleLine')});
|
|
t.ok(true, "If this happens, then we passed. (FF throws an error above otherwise)");
|
|
control.destroy();
|
|
}
|
|
|
|
function test_calcDegrees(t) {
|
|
t.plan(5);
|
|
var control = new OpenLayers.Control.ScaleLine();
|
|
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
var map = new OpenLayers.Map('map');
|
|
var layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
|
|
map.addLayer(layer);
|
|
map.zoomTo(0);
|
|
map.addControl(control);
|
|
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present.");
|
|
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present.");
|
|
t.eq(control.div.firstChild.innerHTML, "10000 km", "top scale has correct text.");
|
|
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text.");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_calcsOther (t) {
|
|
t.plan(5);
|
|
var control = new OpenLayers.Control.ScaleLine();
|
|
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
var map = new OpenLayers.Map('map');
|
|
map.units = "mi";
|
|
var layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
|
|
map.addLayer(layer);
|
|
map.zoomTo(0);
|
|
map.addControl(control);
|
|
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present.");
|
|
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present.");
|
|
t.eq(control.div.firstChild.innerHTML, "100 km", "top scale has correct text.");
|
|
t.eq(control.div.lastChild.innerHTML, "100 mi", "bottom scale has correct text.");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_calcMeters (t) {
|
|
t.plan(5);
|
|
// this example is taken from the projected-map.html OpenLayers example
|
|
var lat = 900863;
|
|
var lon = 235829;
|
|
var zoom = 6;
|
|
var map = new OpenLayers.Map( 'map' );
|
|
var basemap = new OpenLayers.Layer.WMS( "Boston",
|
|
"http://boston.freemap.in/cgi-bin/mapserv?",
|
|
{
|
|
map: '/www/freemap.in/boston/map/gmaps.map',
|
|
layers: 'border,water,roads,rapid_transit,buildings',
|
|
format: 'png',
|
|
transparent: 'off'
|
|
},
|
|
|
|
{
|
|
maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656),
|
|
maxResolution: 296985/1024,
|
|
projection:"EPSG:2805", // Used in WMS/WFS requests.
|
|
units: "m" // Only neccesary for working with scales.
|
|
} );
|
|
|
|
map.addLayer(basemap);
|
|
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
|
var control = new OpenLayers.Control.ScaleLine();
|
|
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
map.addControl(control);
|
|
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present.");
|
|
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present.");
|
|
t.eq(control.div.firstChild.innerHTML, "20000 km", "top scale has correct text.");
|
|
t.eq(control.div.lastChild.innerHTML, "20000 mi", "bottom scale has correct text.");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_useArguments (t) {
|
|
t.plan(5);
|
|
var control = new OpenLayers.Control.ScaleLine({topOutUnits: 'dd'} );
|
|
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
var map = new OpenLayers.Map('map');
|
|
var layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
|
|
map.addLayer(layer);
|
|
map.zoomTo(0);
|
|
map.addControl(control);
|
|
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present.");
|
|
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present.");
|
|
t.eq(control.div.firstChild.innerHTML, "100 dd", "top scale has correct text.");
|
|
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text.");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_respectZoom (t) {
|
|
t.plan(5);
|
|
|
|
// ok, switch the units we use for zoomed in values. This will test that we're both
|
|
// correctly respecting all specified parameters and that we're switching to the
|
|
// "in" units when zoomed in
|
|
var control = new OpenLayers.Control.ScaleLine({topOutUnits : "mi", bottomOutUnits: "km", topInUnits: 'ft', bottomInUnits: 'm'});
|
|
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
|
|
var map = new OpenLayers.Map('map');
|
|
var layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
|
|
map.addLayer(layer);
|
|
map.zoomTo(0);
|
|
map.addControl(control);
|
|
t.eq(control.div.firstChild.innerHTML, "5000 mi", "top scale respects constructor parameter.");
|
|
t.eq(control.div.lastChild.innerHTML, "10000 km", "bottom scale respects constructor parameter.");
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
map.zoomIn();
|
|
|
|
t.eq(control.div.firstChild.innerHTML, "10000 ft", "top scale zooms in & respects constructor parameter.");
|
|
t.eq(control.div.lastChild.innerHTML, "5000 m", "bottom scale zooms in & respects constructor parameter.");
|
|
map.destroy();
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<a id="ScaleLine" href="">ScaleLine</a> <br />
|
|
<div id="map" style="width: 1024px; height: 512px;"/>
|
|
</body>
|
|
</html>
|