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>
6 <script src="../../lib/OpenLayers.js"></script>
7 <script type="text/javascript">
8 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
11 var name = 'Test Layer';
12 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
13 var params = { map: '/mapdata/vmap_wms.map',
15 format: 'image/jpeg'};
17 function test_Layer_WMS_constructor (t) {
20 var trans_format = "image/png";
21 if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; }
23 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
24 layer = new OpenLayers.Layer.WMS(name, url, params);
25 t.ok( layer instanceof OpenLayers.Layer.WMS, "new OpenLayers.Layer.WMS returns object" );
26 t.eq( layer.url, "http://octo.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );
27 t.eq( layer.params.MAP, "/mapdata/vmap_wms.map", "params passed in correctly uppercased" );
29 t.eq( layer.params.SERVICE, "WMS", "default params correclty uppercased and copied");
31 t.eq(layer.isBaseLayer, true, "no transparency setting, wms is baselayer");
33 params.TRANSPARENT = "true";
34 var layer2 = new OpenLayers.Layer.WMS(name, url, params);
35 t.eq(layer2.isBaseLayer, false, "transparency == 'true', wms is not baselayer");
37 params.TRANSPARENT = "TRUE";
38 var layer3 = new OpenLayers.Layer.WMS(name, url, params);
39 t.eq(layer3.isBaseLayer, false, "transparency == 'TRUE', wms is not baselayer");
40 t.eq(layer3.params.FORMAT, trans_format, "transparent = TRUE causes non-image/jpeg format");
42 params.TRANSPARENT = "TRuE";
43 var layer4 = new OpenLayers.Layer.WMS(name, url, params);
44 t.eq(layer4.isBaseLayer, false, "transparency == 'TRuE', wms is not baselayer");
45 t.eq(layer4.params.FORMAT, trans_format, "transparent = TRuE causes non-image/jpeg format");
47 params.TRANSPARENT = true;
48 var layer5 = new OpenLayers.Layer.WMS(name, url, params);
49 t.eq(layer5.isBaseLayer, false, "transparency == true, wms is not baselayer");
50 t.eq(layer5.params.FORMAT, trans_format, "transparent = true causes non-image/jpeg format");
52 params.TRANSPARENT = false;
53 var layer6 = new OpenLayers.Layer.WMS(name, url, params);
54 t.eq(layer6.isBaseLayer, true, "transparency == false, wms is baselayer");
56 params.TRANSPARENT = true;
57 var layer7 = new OpenLayers.Layer.WMS(name, url, params, {noMagic: true});
58 t.eq(layer7.params.FORMAT, "image/jpeg", "When using noMagic true image/jpeg will not be automagically switched to image/png or image/gif if transparent");
60 params.TRANSPARENT = true;
61 var layer8 = new OpenLayers.Layer.WMS(name, url, params, {noMagic: true});
62 t.eq(layer8.isBaseLayer, true, "When using noMagic then transparent means the wms layer is not automagically changed to not being a baselayer");
64 params.TRANSPARENT = false;
68 function test_Layer_WMS_addtile (t) {
71 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
72 layer = new OpenLayers.Layer.WMS(name, url, params);
73 var map = new OpenLayers.Map('map');
75 var pixel = new OpenLayers.Pixel(5,6);
76 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
79 var img = tile.imgDiv;
80 var tParams = OpenLayers.Util.extend({},
81 OpenLayers.Util.upperCaseObject(params));
82 tParams = OpenLayers.Util.extend(tParams, {
83 SERVICE: "WMS", VERSION: "1.1.1",
84 REQUEST: "GetMap", STYLES: "",
85 EXCEPTIONS: "application/vnd.ogc.se_inimage",
86 SRS: "EPSG:4326", BBOX: [1,2,3,4],
87 WIDTH: "256", HEIGHT: "256"
90 url + "?" + OpenLayers.Util.getParameterString(tParams),
91 "image src is created correctly via addtile" );
92 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" );
93 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" );
95 var firstChild = layer.div.firstChild.firstChild;
97 t.ok( true, "skipping element test outside of Mozilla");
99 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
100 t.eq( firstChild.src,
101 url + "?" + OpenLayers.Util.getParameterString(tParams),
102 "div first child is correct image object" );
103 t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
107 function test_Layer_WMS_bboxEncoding (t) {
110 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
111 layer = new OpenLayers.Layer.WMS(name, url, params, {encodeBBOX:true});
112 var map = new OpenLayers.Map('map');
114 var pixel = new OpenLayers.Pixel(5,6);
115 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
118 var img = tile.imgDiv;
119 var tParams = OpenLayers.Util.extend({},
120 OpenLayers.Util.upperCaseObject(params));
121 tParams = OpenLayers.Util.extend(tParams, {
122 SERVICE: "WMS", VERSION: "1.1.1",
123 REQUEST: "GetMap", STYLES: "",
124 EXCEPTIONS: "application/vnd.ogc.se_inimage",
125 SRS: "EPSG:4326", BBOX: "1,2,3,4",
126 WIDTH: "256", HEIGHT: "256"
129 url + "?" + OpenLayers.Util.getParameterString(tParams),
130 "image src is created correctly via addtile" );
131 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" );
132 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" );
134 var firstChild = layer.div.firstChild.firstChild;
136 t.ok( true, "skipping element test outside of Mozilla");
138 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
139 t.eq( firstChild.src,
140 url + "?" + OpenLayers.Util.getParameterString(tParams),
141 "div first child is correct image object" );
142 t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
146 function test_Layer_WMS_inittiles (t) {
148 var map = new OpenLayers.Map('map');
149 layer = new OpenLayers.Layer.WMS(name, url, params);
151 map.setCenter(new OpenLayers.LonLat(0,0),5);
152 t.eq( layer.grid.length, 7, "Grid rows is correct." );
153 t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
158 function test_Layer_WMS_clone (t) {
161 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
162 var options = {tileSize: new OpenLayers.Size(500,50)};
163 var map = new OpenLayers.Map('map', options);
164 layer = new OpenLayers.Layer.WMS(name, url, params);
167 layer.grid = [ [6, 7],
170 var clone = layer.clone();
172 t.ok( clone.grid != layer.grid, "clone does not copy grid");
174 t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
176 layer.tileSize.w += 40;
178 t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
180 t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
186 function test_Layer_WMS_isBaseLayer(t) {
189 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
190 layer = new OpenLayers.Layer.WMS(name, url, params);
191 t.ok( layer.isBaseLayer, "baselayer is true by default");
193 var newParams = OpenLayers.Util.extend({}, params);
194 newParams.transparent = "true";
195 layer = new OpenLayers.Layer.WMS(name, url, newParams);
196 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
198 layer = new OpenLayers.Layer.WMS(name, url, params, {isBaseLayer: false});
199 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
202 function test_Layer_WMS_mergeNewParams (t) {
205 var map = new OpenLayers.Map("map");
206 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
207 layer = new OpenLayers.Layer.WMS(name, url, params);
209 var newParams = { layers: 'sooper',
210 chickpeas: 'image/png'};
213 map.zoomToMaxExtent();
215 layer.redraw = function() {
216 t.ok(true, "layer is redrawn after new params merged");
219 layer.mergeNewParams(newParams);
221 t.eq( layer.params.LAYERS, "sooper", "mergeNewParams() overwrites well");
222 t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() adds well");
224 newParams.CHICKPEAS = 151;
226 t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() makes clean copy of hashtable");
230 function test_Layer_WMS_getFullRequestString (t) {
234 var map = new OpenLayers.Map('map');
235 map.projection = "xx";
236 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
237 tParams = { layers: 'basic',
238 format: 'image/png'};
239 var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams);
240 map.addLayer(tLayer);
241 str = tLayer.getFullRequestString();
243 LAYERS: "basic", FORMAT: "image/png", SERVICE: "WMS",
244 VERSION: "1.1.1", REQUEST: "GetMap", STYLES: "",
245 EXCEPTIONS: "application/vnd.ogc.se_inimage", SRS: "xx"
248 tUrl + "?" + OpenLayers.Util.getParameterString(tParams),
249 "getFullRequestString() adds SRS value");
251 map.removeLayer(tLayer);
252 tLayer.projection = "none";
253 map.addLayer(tLayer);
254 str = tLayer.getFullRequestString();
255 delete tParams['SRS'];
257 tUrl + "?" + OpenLayers.Util.getParameterString(tParams),
258 "getFullRequestString() by default does *not* add SRS value if projection is 'none'");
263 function test_Layer_WMS_setOpacity (t) {
266 var map = new OpenLayers.Map('map');
267 map.projection = "xx";
268 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
269 tParams = { layers: 'basic',
270 format: 'image/png'};
271 tOptions = { 'opacity': '0.5' };
272 var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams, tOptions);
273 map.addLayer(tLayer);
274 map.zoomToMaxExtent();
275 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly");
276 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct");
277 tLayer.setOpacity("0.6");
278 t.eq(tLayer.opacity, "0.6", "setOpacity works properly");
279 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly");
280 var pixel = new OpenLayers.Pixel(5,6);
281 var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
283 t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly");
288 function test_Layer_WMS_Reproject (t) {
289 var validkey = (window.location.protocol == "file:") ||
290 (window.location.host == "localhost") ||
291 (window.location.host == "openlayers.org");
292 if (OpenLayers.Util.getBrowserName() == "opera" || OpenLayers.Util.getBrowserName() == "safari") {
294 t.debug_print("Can't test google reprojection in Opera or Safari.");
295 } else if(validkey) {
298 var map = new OpenLayers.Map('map');
299 var layer = new OpenLayers.Layer.Google("Google");
301 var wmslayer = new OpenLayers.Layer.WMS(name, url, params,
302 {isBaseLayer: false, reproject:true});
303 wmslayer.isBaseLayer=false;
304 map.addLayer(wmslayer);
305 map.setCenter(new OpenLayers.LonLat(0,0), 5);
306 var tile = wmslayer.grid[0][0];
307 t.eq( tile.bounds.left, -22.5, "left side matches" );
308 t.eq( tile.bounds.right, -11.25, "right side matches" );
309 t.eq( tile.bounds.bottom.toFixed(6), '11.178402', "bottom side matches" );
310 t.eq( tile.bounds.top.toFixed(6), '21.943046', "top side matches" );
314 t.debug_print("can't test google layer from " +
315 window.location.host);
318 var map = new OpenLayers.Map('map');
319 layer = new OpenLayers.Layer.WMS(name, url, params);
321 map.setCenter(new OpenLayers.LonLat(0,0), 5);
322 var tile = layer.grid[0][0];
323 t.ok( tile.bounds.equals(new OpenLayers.Bounds(-33.75, 33.75, -22.5, 45)), "okay");
328 function test_Layer_WMS_noGutters (t) {
330 var map = new OpenLayers.Map('map');
331 var layer = new OpenLayers.Layer.WMS("no gutter layer", url, params, {gutter: 0});
333 map.setCenter(new OpenLayers.LonLat(0,0), 5);
334 var tile = layer.grid[0][0];
335 var request = layer.getURL(tile.bounds);
336 var args = OpenLayers.Util.getParameters(request);
337 t.eq(parseInt(args['WIDTH']),
339 "layer without gutter requests images that are as wide as the tile");
340 t.eq(parseInt(args['HEIGHT']),
342 "layer without gutter requests images that are as tall as the tile");
348 function test_Layer_WMS_gutters (t) {
351 var map = new OpenLayers.Map('map');
352 var layer = new OpenLayers.Layer.WMS("gutter layer", url, params, {gutter: gutter});
354 map.setCenter(new OpenLayers.LonLat(0,0), 5);
355 var tile = layer.grid[0][0];
356 var request = layer.getURL(tile.bounds);
357 var args = OpenLayers.Util.getParameters(request);
358 t.eq(parseInt(args['WIDTH']),
359 tile.size.w + (2 * gutter),
360 "layer with gutter requests images that are wider by twice the gutter");
361 t.eq(parseInt(args['HEIGHT']),
362 tile.size.h + (2 * gutter),
363 "layer with gutter requests images that are taller by twice the gutter");
370 // DEPRECATED -- REMOVE IN 3.0
371 function test_Layer_Untiled_WMS(t) {
374 var layer = new OpenLayers.Layer.WMS.Untiled();
376 var clone = layer.clone();
378 t.ok(clone.singleTile, "regression test: clone works. this is for #1013");
381 function test_Layer_WMS_destroy (t) {
385 var map = new OpenLayers.Map('map');
386 layer = new OpenLayers.Layer.WMS(name, url, params);
389 map.setCenter(new OpenLayers.LonLat(0,0), 5);
391 //grab a reference to one of the tiles
392 var tile = layer.grid[0][0];
396 // checks to make sure superclass (grid) destroy() was called
398 t.ok( layer.grid == null, "grid set to null");
405 <div id="map" style="width:500px;height:550px"></div>