| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"><!-- |
|---|
| 5 |
var map; |
|---|
| 6 |
function test_01_Control_ScaleLine_constructor (t) { |
|---|
| 7 |
t.plan( 2 ); |
|---|
| 8 |
control = new OpenLayers.Control.ScaleLine(); |
|---|
| 9 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 10 |
t.eq( control.displayClass, "olControlScaleLine", "displayClass is correct" ); |
|---|
| 11 |
} |
|---|
| 12 |
function test_02_Control_ScaleLine_initwithelem (t) { |
|---|
| 13 |
t.plan( 1 ); |
|---|
| 14 |
control = new OpenLayers.Control.ScaleLine({"div":OpenLayers.Util.getElement('ScaleLine')}); |
|---|
| 15 |
t.ok(true, "If this happens, then we passed. (FF throws an error above otherwise)"); |
|---|
| 16 |
} |
|---|
| 17 |
function test_04_Control_ScaleLine_calcDegrees (t) { |
|---|
| 18 |
t.plan(5); |
|---|
| 19 |
control = new OpenLayers.Control.ScaleLine(); |
|---|
| 20 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 21 |
map = new OpenLayers.Map('map'); |
|---|
| 22 |
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); |
|---|
| 23 |
map.addLayer(layer); |
|---|
| 24 |
map.zoomTo(0); |
|---|
| 25 |
map.addControl(control); |
|---|
| 26 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 27 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 28 |
t.eq(control.div.firstChild.innerHTML, "10000 km", "top scale has correct text."); |
|---|
| 29 |
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text."); |
|---|
| 30 |
} |
|---|
| 31 |
function test_05_Control_ScaleLine_calcsOther (t) { |
|---|
| 32 |
t.plan(5); |
|---|
| 33 |
control = new OpenLayers.Control.ScaleLine(); |
|---|
| 34 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 35 |
map = new OpenLayers.Map('map'); |
|---|
| 36 |
map.units = "mi"; |
|---|
| 37 |
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); |
|---|
| 38 |
map.addLayer(layer); |
|---|
| 39 |
map.zoomTo(0); |
|---|
| 40 |
map.addControl(control); |
|---|
| 41 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 42 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 43 |
t.eq(control.div.firstChild.innerHTML, "100 km", "top scale has correct text."); |
|---|
| 44 |
t.eq(control.div.lastChild.innerHTML, "100 mi", "bottom scale has correct text."); |
|---|
| 45 |
} |
|---|
| 46 |
function test_06_Control_ScaleLine_calcMeters (t) { |
|---|
| 47 |
t.plan(5); |
|---|
| 48 |
// this example is taken from the projected-map.html OpenLayers example |
|---|
| 49 |
var lat = 900863; |
|---|
| 50 |
var lon = 235829; |
|---|
| 51 |
var zoom = 6; |
|---|
| 52 |
var map, layer; |
|---|
| 53 |
map = new OpenLayers.Map( 'map' ); |
|---|
| 54 |
var basemap = new OpenLayers.Layer.WMS( "Boston", |
|---|
| 55 |
"http://boston.freemap.in/cgi-bin/mapserv?", |
|---|
| 56 |
{ |
|---|
| 57 |
map: '/www/freemap.in/boston/map/gmaps.map', |
|---|
| 58 |
layers: 'border,water,roads,rapid_transit,buildings', |
|---|
| 59 |
format: 'png', |
|---|
| 60 |
transparent: 'off' |
|---|
| 61 |
}, |
|---|
| 62 |
|
|---|
| 63 |
{ |
|---|
| 64 |
maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), |
|---|
| 65 |
maxResolution: 296985/1024, |
|---|
| 66 |
projection:"EPSG:2805", // Used in WMS/WFS requests. |
|---|
| 67 |
units: "m" // Only neccesary for working with scales. |
|---|
| 68 |
} ); |
|---|
| 69 |
|
|---|
| 70 |
map.addLayer(basemap); |
|---|
| 71 |
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); |
|---|
| 72 |
map.addControl(new OpenLayers.Control.LayerSwitcher()); |
|---|
| 73 |
control = new OpenLayers.Control.ScaleLine(); |
|---|
| 74 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 75 |
map.addControl(control); |
|---|
| 76 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 77 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 78 |
t.eq(control.div.firstChild.innerHTML, "20000 km", "top scale has correct text."); |
|---|
| 79 |
t.eq(control.div.lastChild.innerHTML, "20000 mi", "bottom scale has correct text."); |
|---|
| 80 |
|
|---|
| 81 |
} |
|---|
| 82 |
function test_07_Control_ScaleLine_useArguments (t) { |
|---|
| 83 |
t.plan(5); |
|---|
| 84 |
control = new OpenLayers.Control.ScaleLine({topOutUnits: 'dd'} ); |
|---|
| 85 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 86 |
map = new OpenLayers.Map('map'); |
|---|
| 87 |
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); |
|---|
| 88 |
map.addLayer(layer); |
|---|
| 89 |
map.zoomTo(0); |
|---|
| 90 |
map.addControl(control); |
|---|
| 91 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 92 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 93 |
t.eq(control.div.firstChild.innerHTML, "100 dd", "top scale has correct text."); |
|---|
| 94 |
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text."); |
|---|
| 95 |
} |
|---|
| 96 |
function test_08_Control_ScaleLine_respectZoom (t) { |
|---|
| 97 |
t.plan(5); |
|---|
| 98 |
|
|---|
| 99 |
// ok, switch the units we use for zoomed in values. This will test that we're both |
|---|
| 100 |
// correctly respecting all specified parameters and that we're switching to the |
|---|
| 101 |
// "in" units when zoomed in |
|---|
| 102 |
control = new OpenLayers.Control.ScaleLine({topOutUnits : "mi", bottomOutUnits: "km", topInUnits: 'ft', bottomInUnits: 'm'}); |
|---|
| 103 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 104 |
map = new OpenLayers.Map('map'); |
|---|
| 105 |
layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); |
|---|
| 106 |
map.addLayer(layer); |
|---|
| 107 |
map.zoomTo(0); |
|---|
| 108 |
map.addControl(control); |
|---|
| 109 |
t.eq(control.div.firstChild.innerHTML, "5000 mi", "top scale respects constructor parameter."); |
|---|
| 110 |
t.eq(control.div.lastChild.innerHTML, "10000 km", "bottom scale respects constructor parameter."); |
|---|
| 111 |
map.zoomIn(); |
|---|
| 112 |
map.zoomIn(); |
|---|
| 113 |
map.zoomIn(); |
|---|
| 114 |
map.zoomIn(); |
|---|
| 115 |
map.zoomIn(); |
|---|
| 116 |
map.zoomIn(); |
|---|
| 117 |
map.zoomIn(); |
|---|
| 118 |
map.zoomIn(); |
|---|
| 119 |
map.zoomIn(); |
|---|
| 120 |
map.zoomIn(); |
|---|
| 121 |
map.zoomIn(); |
|---|
| 122 |
|
|---|
| 123 |
t.eq(control.div.firstChild.innerHTML, "10000 ft", "top scale zooms in & respects constructor parameter."); |
|---|
| 124 |
t.eq(control.div.lastChild.innerHTML, "5000 m", "bottom scale zooms in & respects constructor parameter."); |
|---|
| 125 |
} |
|---|
| 126 |
--> |
|---|
| 127 |
</script> |
|---|
| 128 |
</head> |
|---|
| 129 |
<body> |
|---|
| 130 |
<a id="ScaleLine" href="">ScaleLine</a> <br /> |
|---|
| 131 |
<div id="map" style="width: 1024px; height: 512px;"/> |
|---|
| 132 |
</body> |
|---|
| 133 |
</html> |
|---|