3 <script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script>
4 <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
5 <script type="text/javascript">window.alert = oldAlert;</script>
8 <script src="../../lib/OpenLayers.js"></script>
9 <script type="text/javascript">
10 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
13 var name = 'Test Layer';
14 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
15 var params = { map: '/mapdata/vmap_wms.map',
18 function test_Layer_MapServer_constructor (t) {
21 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
22 layer = new OpenLayers.Layer.MapServer(name, url, params);
23 t.ok( layer instanceof OpenLayers.Layer.MapServer, "new OpenLayers.Layer.MapServer returns object" );
24 t.eq( layer.url, "http://labs.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );
26 t.eq( layer.params.mode, "map", "default mode param correctly copied");
27 t.eq( layer.params.map_imagetype, "png", "default imagetype correctly copied");
32 function test_Layer_MapServer_addtile (t) {
35 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
36 layer = new OpenLayers.Layer.MapServer(name, url, params);
37 var map = new OpenLayers.Map('map');
39 var pixel = new OpenLayers.Pixel(5,6);
40 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
43 var img = tile.imgDiv;
44 var tParams = OpenLayers.Util.extend({},params);
45 tParams = OpenLayers.Util.extend(tParams, {
57 url + "?" + OpenLayers.Util.getParameterString(tParams).replace(/,/g, "+"),
58 "image src is created correctly via addtile" );
59 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" );
60 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" );
62 var firstChild = layer.div.firstChild.firstChild;
64 t.ok( true, "skipping element test outside of Mozilla");
66 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
68 url + "?" + OpenLayers.Util.getParameterString(tParams).replace(/,/g, "+"),
69 "div first child is correct image object" );
70 t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
74 function test_Layer_MapServer_inittiles (t) {
76 var map = new OpenLayers.Map('map');
77 layer = new OpenLayers.Layer.MapServer(name, url, params);
79 map.setCenter(new OpenLayers.LonLat(0,0),5);
80 t.eq( layer.grid.length, 7, "Grid rows is correct." );
81 t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
87 function test_Layer_MapServer_clone (t) {
90 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
91 var options = {tileSize: new OpenLayers.Size(500,50)};
92 var map = new OpenLayers.Map('map', options);
93 layer = new OpenLayers.Layer.MapServer(name, url, params);
96 layer.grid = [ [6, 7],
99 var clone = layer.clone();
101 t.ok( clone.grid != layer.grid, "clone does not copy grid");
103 t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
105 layer.tileSize.w += 40;
107 t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
109 t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
115 function test_Layer_MapServer_isBaseLayer(t) {
118 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
119 layer = new OpenLayers.Layer.MapServer(name, url, params);
120 t.ok( layer.isBaseLayer, "baselayer is true by default");
122 var newParams = OpenLayers.Util.extend({}, params);
123 newParams.transparent = "true";
124 layer = new OpenLayers.Layer.MapServer(name, url, newParams);
125 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
127 layer = new OpenLayers.Layer.MapServer(name, url, params, {isBaseLayer: false});
128 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
131 function test_Layer_MapServer_mergeNewParams (t) {
134 var map = new OpenLayers.Map("map");
135 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
136 layer = new OpenLayers.Layer.MapServer(name, url, params);
138 var newParams = { layers: 'sooper',
139 chickpeas: 'image/png'};
142 map.zoomToMaxExtent();
144 layer.redraw = function() {
145 t.ok(true, "layer is redrawn after new params merged");
147 layer.mergeNewParams(newParams);
149 t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
150 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
152 newParams.chickpeas = 151;
154 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
158 function test_Layer_MapServer_getFullRequestString (t) {
160 var map = new OpenLayers.Map('map');
161 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
162 tParams = { layers: 'basic',
164 var tLayer = new OpenLayers.Layer.MapServer(name, tUrl, tParams);
165 map.addLayer(tLayer);
166 str = tLayer.getFullRequestString();
174 var sStr = tUrl + "?" + OpenLayers.Util.getParameterString(tParams);
175 sStr = sStr.replace(/,/g, "+");
177 t.eq(str, sStr , "getFullRequestString() works");
180 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"];
181 layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null);
182 str = layer.getFullRequestString({'c':'d'});
183 t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'c':'d'})), "getFullRequestString() works for list of two urls and is deterministic");
191 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"];
192 layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null);
193 str = layer.getFullRequestString({'a':'b'});
194 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'b'})), "getFullRequestString() works for list of two urls and is deterministic");
199 function test_Layer_MapServer_setOpacity (t) {
202 var map = new OpenLayers.Map('map');
203 map.projection = "xx";
204 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
205 tParams = { layers: 'basic',
206 format: 'image/png'};
207 tOptions = { 'opacity': '0.5' };
208 var tLayer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, tOptions);
209 map.addLayer(tLayer);
210 map.zoomToMaxExtent();
211 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly");
212 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct");
213 tLayer.setOpacity("0.6");
214 t.eq(tLayer.opacity, "0.6", "setOpacity works properly");
215 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly");
216 var pixel = new OpenLayers.Pixel(5,6);
217 var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
219 t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly");
224 function test_Layer_MapServer_Reproject (t) {
225 var validkey = (window.location.protocol == "file:") ||
226 (window.location.host == "localhost") ||
227 (window.location.host == "openlayers.org");
229 if (OpenLayers.Util.getBrowserName() == "opera" || OpenLayers.Util.getBrowserName() == "safari") {
231 t.debug_print("Can't test google reprojection in Opera or Safari.");
232 } else if(validkey) {
234 var map = new OpenLayers.Map('map');
235 var layer = new OpenLayers.Layer.Google("Google");
237 layer = new OpenLayers.Layer.MapServer(name, url, params, {isBaseLayer: false, reproject: true});
238 layer.isBaseLayer=false;
240 map.setCenter(new OpenLayers.LonLat(0,0), 5);
241 var tile = layer.grid[0][0];
242 t.eq( tile.bounds.left, -22.5, "left side matches" );
243 t.eq( tile.bounds.right, -11.25, "top side matches" );
244 t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );
245 t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );
249 t.debug_print("can't test google layer from " +
250 window.location.host);
253 var map = new OpenLayers.Map('map');
254 layer = new OpenLayers.Layer.MapServer(name, url, params);
256 map.setCenter(new OpenLayers.LonLat(0,0), 5);
257 var tile = layer.grid[0][0];
258 t.ok( tile.bounds.equals(new OpenLayers.Bounds(-33.75, 33.75, -22.5, 45)), "okay");
262 function test_Layer_MapServer_singleTile (t) {
264 var map = new OpenLayers.Map('map');
265 layer = new OpenLayers.Layer.MapServer(name, url, params, {singleTile: true});
267 map.setCenter(new OpenLayers.LonLat(0,0),5);
268 t.eq( layer.singleTile, true, "layer has singleTile property, great!" );
269 t.eq( layer.grid.length, 1, "Grid has only a single row, good enough!" );
270 t.eq( layer.grid[0].length, 1, "Grid has only a single column, good enough!" );
271 t.eq( layer.tileSize.w, 750, "Image width is correct" );
272 t.eq( layer.tileSize.h, 825, "Image height is correct" );
278 function test_Layer_MapServer_destroy (t) {
282 var map = new OpenLayers.Map('map');
283 layer = new OpenLayers.Layer.MapServer(name, url, params);
286 map.setCenter(new OpenLayers.LonLat(0,0), 5);
288 //grab a reference to one of the tiles
289 var tile = layer.grid[0][0];
293 // checks to make sure superclass (grid) destroy() was called
295 t.ok( layer.grid == null, "grid set to null");
301 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
304 var name = 'Test Layer';
305 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
306 var params = { map: '/mapdata/vmap_wms.map',
309 function test_Layer_MapServer_Untiled_constructor (t) {
312 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
313 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
314 t.ok( layer instanceof OpenLayers.Layer.MapServer.Untiled, "new OpenLayers.Layer.MapServer returns object" );
315 t.eq( layer.url, "http://labs.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );
317 t.eq( layer.params.mode, "map", "default mode param correctly copied");
318 t.eq( layer.params.map_imagetype, "png", "default imagetype correctly copied");
323 function test_Layer_MapServer_Untiled_clone (t) {
326 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
327 var map = new OpenLayers.Map('map', {});
328 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
331 var clone = layer.clone();
332 layer.tile = [[1,2],[3,4]];
334 t.ok( clone.tile != layer.tile, "clone does not copy tile");
338 t.eq( clone.ratio, 1.5, "changing layer.ratio does not change clone.ratio -- a fresh copy was made, not just copied reference");
340 t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
346 function test_Layer_MapServer_Untiled_isBaseLayer(t) {
349 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
350 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
351 t.ok( layer.isBaseLayer, "baselayer is true by default");
353 var newParams = OpenLayers.Util.extend({}, params);
354 newParams.transparent = "true";
355 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, newParams);
356 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
358 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params, {isBaseLayer: false});
359 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
362 function test_Layer_MapServer_Untiled_mergeNewParams (t) {
365 var map = new OpenLayers.Map("map");
366 var url = "http://labs.metacarta.com/cgi-bin/mapserv";
367 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
369 var newParams = { layers: 'sooper',
370 chickpeas: 'image/png'};
373 map.zoomToMaxExtent();
374 t.ok( !layer.grid[0][0].url.match("chickpeas"), "chickpeas is not in URL of first tile in grid" );
376 layer.mergeNewParams(newParams);
378 t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
379 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
380 t.ok( layer.grid[0][0].url.match("chickpeas"), "chickpeas is in URL of first tile in grid" );
382 newParams.chickpeas = 151;
384 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
388 function test_Layer_MapServer_Untiled_getFullRequestString (t) {
392 var map = new OpenLayers.Map('map');
393 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
394 tParams = { layers: 'basic',
396 var tLayer = new OpenLayers.Layer.MapServer.Untiled(name, tUrl, tParams);
397 map.addLayer(tLayer);
398 str = tLayer.getFullRequestString();
406 var sStr = tUrl + "?" + OpenLayers.Util.getParameterString(tParams);
407 sStr = sStr.replace(/,/g, "+");
409 t.eq(str, sStr , "getFullRequestString() works");
414 function test_Layer_MapServer_Untiled_setOpacity (t) {
417 var map = new OpenLayers.Map('map');
418 map.projection = "xx";
419 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
420 tParams = { layers: 'basic',
421 format: 'image/png'};
422 tOptions = { 'opacity': '0.5' };
423 var tLayer = new OpenLayers.Layer.MapServer.Untiled(name, tUrl, tParams, tOptions);
424 map.addLayer(tLayer);
425 map.zoomToMaxExtent();
426 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly");
427 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct");
428 tLayer.setOpacity("0.6");
429 t.eq(tLayer.opacity, "0.6", "setOpacity works properly");
430 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly");
435 // DEPRECATED -- REMOVE IN 3.0
436 function test_Layer_Untiled_MapServer(t) {
439 var layer = new OpenLayers.Layer.MapServer.Untiled();
441 var clone = layer.clone();
443 t.ok(clone.singleTile, "regression test: clone works. this is for #1013");
446 function test_Layer_MapServer_Untiled_destroy (t) {
450 var map = new OpenLayers.Map('map');
451 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
454 map.setCenter(new OpenLayers.LonLat(0,0), 5);
456 //grab a reference to one of the tiles
457 var tile = layer.tile;
461 // checks to make sure superclass (grid) destroy() was called
463 t.ok( layer.tile == null, "tile set to null");
470 <div id="map" style="width:500px;height:550px"></div>