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");
10 function test_initialize(t) {
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" );
18 function test_initwithelem(t) {
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)");
25 function test_calcDegrees(t) {
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'});
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.");
41 function test_calcsOther (t) {
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');
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'});
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.");
58 function test_calcMeters (t) {
60 // this example is taken from the projected-map.html OpenLayers example
64 var map = new OpenLayers.Map( 'map' );
65 var basemap = new OpenLayers.Layer.WMS( "Boston",
66 "http://boston.freemap.in/cgi-bin/mapserv?",
68 map: '/www/freemap.in/boston/map/gmaps.map',
69 layers: 'border,water,roads,rapid_transit,buildings',
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.
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.");
94 function test_useArguments (t) {
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'});
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.");
110 function test_respectZoom (t) {
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'});
125 map.addControl(control);
126 var widthIsOk = true;
127 for (var i=0; i<map.numZoomLevels && widthIsOk; 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;
133 t.ok(widthIsOk, "respects maxWidth at all zoom levels in dd");
136 control.maxWidth = 200;
137 for (var i=0; i<map.numZoomLevels && widthIsOk; 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;
143 t.ok(widthIsOk, "respects modified maxWidth at all zoom levels in dd");
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'});
151 map.addControl(control);
152 var widthIsOk = true;
153 for (var i=0; i<map.numZoomLevels && widthIsOk; 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;
159 t.ok(widthIsOk, "respects maxWidth at all zoom levels in m");
161 t.debug_print("Google tests can't be run from " +
162 window.location.host);
165 var map = new OpenLayers.Map('map');
166 var layer = new OpenLayers.Layer.Google('Goog Layer');
171 function test_ie_oneunit(t) {
173 var control = new OpenLayers.Control.ScaleLine({bottomOutUnits:'',bottomInUnits:'',maxWidth:150});
174 t.ok(control instanceof OpenLayers.Control.ScaleLine, "new OpenLayers.Control returns object" );
175 var map = new OpenLayers.Map('map');
176 var layer = new OpenLayers.Layer.WMS('Test Layer', "bogus", {});
179 map.addControl(control);
180 t.ok(true, "invisible bottom scale doesn't cause scaleline failure (IE only)");
186 <a id="ScaleLine" href="">ScaleLine</a> <br />
187 <div id="map" style="width: 1024px; height: 512px;"/>