| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script> |
|---|
| 4 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 5 |
<script type="text/javascript"> |
|---|
| 6 |
var validkey = (window.location.protocol == "file:") || |
|---|
| 7 |
(window.location.host == "localhost") || |
|---|
| 8 |
(window.location.host == "openlayers.org"); |
|---|
| 9 |
|
|---|
| 10 |
function test_initialize(t) { |
|---|
| 11 |
t.plan(2); |
|---|
| 12 |
var control = new OpenLayers.Control.ScaleLine(); |
|---|
| 13 |
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 14 |
t.eq(control.displayClass, "olControlScaleLine", "displayClass is correct" ); |
|---|
| 15 |
control.destroy(); |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
function test_initwithelem(t) { |
|---|
| 19 |
t.plan(1); |
|---|
| 20 |
var control = new OpenLayers.Control.ScaleLine({"div":OpenLayers.Util.getElement('ScaleLine')}); |
|---|
| 21 |
t.ok(true, "If this happens, then we passed. (FF throws an error above otherwise)"); |
|---|
| 22 |
control.destroy(); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
function test_calcDegrees(t) { |
|---|
| 26 |
t.plan(5); |
|---|
| 27 |
var control = new OpenLayers.Control.ScaleLine(); |
|---|
| 28 |
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 29 |
var map = new OpenLayers.Map('map'); |
|---|
| 30 |
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'}); |
|---|
| 31 |
map.addLayer(layer); |
|---|
| 32 |
map.zoomTo(0); |
|---|
| 33 |
map.addControl(control); |
|---|
| 34 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 35 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 36 |
t.eq(control.div.firstChild.innerHTML, "10000 km", "top scale has correct text."); |
|---|
| 37 |
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text."); |
|---|
| 38 |
map.destroy(); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
function test_calcsOther (t) { |
|---|
| 42 |
t.plan(5); |
|---|
| 43 |
var control = new OpenLayers.Control.ScaleLine(); |
|---|
| 44 |
t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 45 |
var map = new OpenLayers.Map('map'); |
|---|
| 46 |
map.units = "mi"; |
|---|
| 47 |
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'}); |
|---|
| 48 |
map.addLayer(layer); |
|---|
| 49 |
map.zoomTo(0); |
|---|
| 50 |
map.addControl(control); |
|---|
| 51 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 52 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 53 |
t.eq(control.div.firstChild.innerHTML, "100 km", "top scale has correct text."); |
|---|
| 54 |
t.eq(control.div.lastChild.innerHTML, "100 mi", "bottom scale has correct text."); |
|---|
| 55 |
map.destroy(); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
function test_calcMeters (t) { |
|---|
| 59 |
t.plan(5); |
|---|
| 60 |
// this example is taken from the projected-map.html OpenLayers example |
|---|
| 61 |
var lat = 900863; |
|---|
| 62 |
var lon = 235829; |
|---|
| 63 |
var zoom = 6; |
|---|
| 64 |
var map = new OpenLayers.Map( 'map' ); |
|---|
| 65 |
var basemap = new OpenLayers.Layer.WMS( "Boston", |
|---|
| 66 |
"http://boston.freemap.in/cgi-bin/mapserv?", |
|---|
| 67 |
{ |
|---|
| 68 |
map: '/www/freemap.in/boston/map/gmaps.map', |
|---|
| 69 |
layers: 'border,water,roads,rapid_transit,buildings', |
|---|
| 70 |
format: 'png', |
|---|
| 71 |
transparent: 'off' |
|---|
| 72 |
}, |
|---|
| 73 |
|
|---|
| 74 |
{ |
|---|
| 75 |
maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), |
|---|
| 76 |
maxResolution: 296985/1024, |
|---|
| 77 |
projection:"EPSG:2805", // Used in WMS/WFS requests. |
|---|
| 78 |
units: "m" // Only neccesary for working with scales. |
|---|
| 79 |
} ); |
|---|
| 80 |
|
|---|
| 81 |
map.addLayer(basemap); |
|---|
| 82 |
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); |
|---|
| 83 |
map.addControl(new OpenLayers.Control.LayerSwitcher()); |
|---|
| 84 |
var control = new OpenLayers.Control.ScaleLine(); |
|---|
| 85 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 86 |
map.addControl(control); |
|---|
| 87 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 88 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 89 |
t.eq(control.div.firstChild.innerHTML, "200 m", "top scale has correct text."); |
|---|
| 90 |
t.eq(control.div.lastChild.innerHTML, "1000 ft", "bottom scale has correct text."); |
|---|
| 91 |
map.destroy(); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
function test_useArguments (t) { |
|---|
| 95 |
t.plan(5); |
|---|
| 96 |
var control = new OpenLayers.Control.ScaleLine({topOutUnits: 'dd'} ); |
|---|
| 97 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 98 |
var map = new OpenLayers.Map('map'); |
|---|
| 99 |
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'}); |
|---|
| 100 |
map.addLayer(layer); |
|---|
| 101 |
map.zoomTo(0); |
|---|
| 102 |
map.addControl(control); |
|---|
| 103 |
t.eq(control.div.firstChild.style.visibility, "visible", "top scale is present."); |
|---|
| 104 |
t.eq(control.div.lastChild.style.visibility, "visible", "bottom scale is present."); |
|---|
| 105 |
t.eq(control.div.firstChild.innerHTML, "100 dd", "top scale has correct text."); |
|---|
| 106 |
t.eq(control.div.lastChild.innerHTML, "5000 mi", "bottom scale has correct text."); |
|---|
| 107 |
map.destroy(); |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
function test_respectZoom (t) { |
|---|
| 111 |
if(validkey) { |
|---|
| 112 |
t.plan( 4 ); |
|---|
| 113 |
} else { |
|---|
| 114 |
t.plan( 3 ); |
|---|
| 115 |
} |
|---|
| 116 |
// ok, switch the units we use for zoomed in values. This will test that we're both |
|---|
| 117 |
// correctly respecting all specified parameters and that we're switching to the |
|---|
| 118 |
// "in" units when zoomed in |
|---|
| 119 |
var control = new OpenLayers.Control.ScaleLine({topOutUnits : "mi", bottomOutUnits: "km", topInUnits: 'ft', bottomInUnits: 'm'}); |
|---|
| 120 |
t.ok( control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" ); |
|---|
| 121 |
var map = new OpenLayers.Map('map'); |
|---|
| 122 |
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'}); |
|---|
| 123 |
map.addLayer(layer); |
|---|
| 124 |
map.zoomTo(0); |
|---|
| 125 |
map.addControl(control); |
|---|
| 126 |
var widthIsOk = true; |
|---|
| 127 |
for (var i=0; i<map.numZoomLevels && widthIsOk; i++) { |
|---|
| 128 |
map.zoomTo(i); |
|---|
| 129 |
var w1 = parseInt(control.eTop.style.width); |
|---|
| 130 |
var w2 = parseInt(control.eBottom.style.width); |
|---|
| 131 |
widthIsOk = w1 <= control.maxWidth && w2 <= control.maxWidth; |
|---|
| 132 |
} |
|---|
| 133 |
t.ok(widthIsOk, "respects maxWidth at all zoom levels in dd"); |
|---|
| 134 |
|
|---|
| 135 |
widthIsOk = true; |
|---|
| 136 |
control.maxWidth = 200; |
|---|
| 137 |
for (var i=0; i<map.numZoomLevels && widthIsOk; i++) { |
|---|
| 138 |
map.zoomTo(i); |
|---|
| 139 |
var w1 = parseInt(control.eTop.style.width); |
|---|
| 140 |
var w2 = parseInt(control.eBottom.style.width); |
|---|
| 141 |
widthIsOk = w1 <= control.maxWidth && w2 <= control.maxWidth; |
|---|
| 142 |
} |
|---|
| 143 |
t.ok(widthIsOk, "respects modified maxWidth at all zoom levels in dd"); |
|---|
| 144 |
|
|---|
| 145 |
if (validkey) { |
|---|
| 146 |
var map = new OpenLayers.Map('map'); |
|---|
| 147 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 148 |
var control = new OpenLayers.Control.ScaleLine({topOutUnits : "mi", bottomOutUnits: "km", topInUnits: 'ft', bottomInUnits: 'm'}); |
|---|
| 149 |
map.addLayer(layer); |
|---|
| 150 |
map.zoomTo(0); |
|---|
| 151 |
map.addControl(control); |
|---|
| 152 |
var widthIsOk = true; |
|---|
| 153 |
for (var i=0; i<map.numZoomLevels && widthIsOk; i++) { |
|---|
| 154 |
map.zoomTo(i); |
|---|
| 155 |
var w1 = parseInt(control.eTop.style.width); |
|---|
| 156 |
var w2 = parseInt(control.eBottom.style.width); |
|---|
| 157 |
widthIsOk = w1 <= control.maxWidth && w2 <= control.maxWidth; |
|---|
| 158 |
} |
|---|
| 159 |
t.ok(widthIsOk, "respects maxWidth at all zoom levels in m"); |
|---|
| 160 |
} else { |
|---|
| 161 |
t.debug_print("Google tests can't be run from " + |
|---|
| 162 |
window.location.host); |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
var map = new OpenLayers.Map('map'); |
|---|
| 166 |
var layer = new OpenLayers.Layer.Google('Goog Layer'); |
|---|
| 167 |
map.addLayer(layer); |
|---|
| 168 |
|
|---|
| 169 |
map.destroy(); |
|---|
| 170 |
} |
|---|
| 171 |
</script> |
|---|
| 172 |
</head> |
|---|
| 173 |
<body> |
|---|
| 174 |
<a id="ScaleLine" href="">ScaleLine</a> <br /> |
|---|
| 175 |
<div id="map" style="width: 1024px; height: 512px;"/> |
|---|
| 176 |
</body> |
|---|
| 177 |
</html> |
|---|