3 <script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script>
4 <script type="text/javascript">window.alert = oldAlert;</script>
5 <script src="../../lib/OpenLayers.js"></script>
6 <script type="text/javascript">
7 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
10 var name = 'Test Layer';
11 var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export";
12 var params = {layers: "show:0,2"};
14 function test_Layer_AGS93_constructor (t) {
15 var params = {layers: "show:0,2"};
18 var trans_format = "png";
19 if (OpenLayers.Util.alphaHack()) { trans_format = "gif"; }
21 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
22 t.ok( layer instanceof OpenLayers.Layer.ArcGIS93Rest, "new OpenLayers.Layer.ArcGIS93Rest returns object" );
23 t.eq( layer.url, url, "layer.url is correct (HTTPRequest inited)" );
24 t.eq( layer.params.LAYERS, "show:0,2", "params passed in correctly uppercased" );
26 t.eq( layer.params.FORMAT, "png", "default params correclty uppercased and copied");
28 t.eq(layer.isBaseLayer, true, "no transparency setting, wms is baselayer");
30 params.format = 'jpg';
31 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
32 t.eq( layer.params.FORMAT, "jpg", "default params correclty uppercased and overridden");
34 params.TRANSPARENT = "true";
35 var layer2 = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
36 t.eq(layer2.isBaseLayer, false, "transparency == 'true', wms is not baselayer");
38 params.TRANSPARENT = "TRUE";
39 var layer3 = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
40 t.eq(layer3.isBaseLayer, false, "transparency == 'TRUE', wms is not baselayer");
41 t.eq(layer3.params.FORMAT, trans_format, "transparent = TRUE causes non-image/jpeg format");
43 params.TRANSPARENT = "TRuE";
44 var layer4 = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
45 t.eq(layer4.isBaseLayer, false, "transparency == 'TRuE', wms is not baselayer");
46 t.eq(layer4.params.FORMAT, trans_format, "transparent = TRuE causes non-image/jpeg format");
48 params.TRANSPARENT = true;
49 var layer5 = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
50 t.eq(layer5.isBaseLayer, false, "transparency == true, wms is not baselayer");
51 t.eq(layer5.params.FORMAT, trans_format, "transparent = true causes non-image/jpeg format");
53 params.TRANSPARENT = false;
54 var layer6 = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
55 t.eq(layer6.isBaseLayer, true, "transparency == false, wms is baselayer");
58 function test_Layer_AGS93_addtile (t) {
59 var params = {layers: "show:0,2"};
62 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
63 var map = new OpenLayers.Map('map');
65 var pixel = new OpenLayers.Pixel(5,6);
66 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
69 var img = tile.imgDiv;
70 var tParams = OpenLayers.Util.extend({},
71 OpenLayers.Util.upperCaseObject(params));
72 tParams = OpenLayers.Util.extend(tParams, {
73 FORMAT: "png", BBOX: "1,2,3,4", SIZE: "256,256", F: "image", BBOXSR: "4326", IMAGESR: "4326"
76 url + "?" + OpenLayers.Util.getParameterString(tParams),
77 "image src is created correctly via addtile" );
78 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" );
79 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" );
81 var firstChild = layer.div.firstChild.firstChild;
83 t.ok( true, "skipping element test outside of Mozilla");
85 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
87 url + "?" + OpenLayers.Util.getParameterString(tParams),
88 "div first child is correct image object" );
89 t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
93 function test_Layer_AGS93_inittiles (t) {
94 var params = {layers: "show:0,2"};
96 var map = new OpenLayers.Map('map');
97 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
99 map.setCenter(new OpenLayers.LonLat(0,0),5);
100 t.eq( layer.grid.length, 7, "Grid rows is correct." );
101 t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
106 function test_Layer_AGS93_clone (t) {
107 var params = {layers: "show:0,2"};
110 var options = {tileSize: new OpenLayers.Size(500,50)};
111 var map = new OpenLayers.Map('map', options);
112 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
115 layer.grid = [ [6, 7],
118 var clone = layer.clone();
120 t.ok( clone.grid != layer.grid, "clone does not copy grid");
122 t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
124 layer.tileSize.w += 40;
126 t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
128 t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
134 function test_Layer_AGS93_isBaseLayer(t) {
135 var params = {layers: "show:0,2"};
138 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
139 t.ok( layer.isBaseLayer, "baselayer is true by default");
141 var newParams = OpenLayers.Util.extend({}, params);
142 newParams.transparent = "true";
143 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, newParams);
144 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
146 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params, {isBaseLayer: false});
147 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
150 function test_Layer_AGS93_mergeNewParams (t) {
151 var params = {layers: "show:0,2"};
154 var map = new OpenLayers.Map("map");
155 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
157 var newParams = { layers: 'sooper',
161 map.zoomToMaxExtent();
163 layer.redraw = function() {
164 t.ok(true, "layer is redrawn after new params merged");
167 layer.mergeNewParams(newParams);
169 t.eq( layer.params.LAYERS, "sooper", "mergeNewParams() overwrites well");
170 t.eq( layer.params.CHICKPEAS, "png", "mergeNewParams() adds well");
172 newParams.CHICKPEAS = 151;
174 t.eq( layer.params.CHICKPEAS, "png", "mergeNewParams() makes clean copy of hashtable");
178 function test_Layer_AGS93_getFullRequestString (t) {
179 var params = {layers: "show:0,2"};
181 var map = new OpenLayers.Map('map');
182 map.projection = "xx";
183 tParams = { layers: 'show:0,2',
185 var tLayer = new OpenLayers.Layer.ArcGIS93Rest(name, url, tParams);
186 map.addLayer(tLayer);
187 str = tLayer.getFullRequestString();
189 LAYERS: "show:0,2", FORMAT: "png"
192 url + "?" + OpenLayers.Util.getParameterString(tParams),
193 "getFullRequestString() adds SRS value");
198 function test_Layer_AGS93_setOpacity (t) {
199 var params = {layers: "show:0,2"};
202 var map = new OpenLayers.Map('map');
203 map.projection = "xx";
204 tParams = { layers: 'show:0,2',
206 tOptions = { 'opacity': '0.5' };
207 var tLayer = new OpenLayers.Layer.ArcGIS93Rest(name, url, tParams, tOptions);
208 map.addLayer(tLayer);
209 map.zoomToMaxExtent();
210 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly");
211 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct");
212 tLayer.setOpacity("0.6");
213 t.eq(tLayer.opacity, "0.6", "setOpacity works properly");
214 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly");
215 var pixel = new OpenLayers.Pixel(5,6);
216 var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
218 t.eq(parseFloat(tile.imgDiv.style.opacity), 0.6, "Tile opacity is set correctly");
223 function test_Layer_AGS93_noGutters (t) {
225 var map = new OpenLayers.Map('map');
226 var layer = new OpenLayers.Layer.ArcGIS93Rest("no gutter layer", url, params, {gutter: 0});
228 map.setCenter(new OpenLayers.LonLat(0,0), 5);
229 var tile = layer.grid[0][0];
230 var request = layer.getURL(tile.bounds);
231 var args = OpenLayers.Util.getParameters(request);
232 t.eq(parseInt(args['SIZE'].split(",")[0]),
234 "layer without gutter requests images that are as wide as the tile");
235 t.eq(parseInt(args['SIZE'].split(",")[1]),
237 "layer without gutter requests images that are as tall as the tile");
243 function test_Layer_AGS93_gutters (t) {
244 var params = {layers: "show:0,2"};
247 var map = new OpenLayers.Map('map');
248 var layer = new OpenLayers.Layer.ArcGIS93Rest("gutter layer", url, params, {gutter: gutter});
250 map.setCenter(new OpenLayers.LonLat(0,0), 5);
251 var tile = layer.grid[0][0];
252 var request = layer.getURL(tile.bounds);
253 var args = OpenLayers.Util.getParameters(request);
254 t.eq(parseInt(args['SIZE'].split(",")[0]),
255 tile.size.w + (2 * gutter),
256 "layer with gutter requests images that are wider by twice the gutter");
257 t.eq(parseInt(args['SIZE'].split(",")[1]),
258 tile.size.h + (2 * gutter),
259 "layer with gutter requests images that are taller by twice the gutter");
266 function test_Layer_AGS93_destroy (t) {
270 var map = new OpenLayers.Map('map');
271 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
274 map.setCenter(new OpenLayers.LonLat(0,0), 5);
276 //grab a reference to one of the tiles
277 var tile = layer.grid[0][0];
281 // checks to make sure superclass (grid) destroy() was called
283 t.ok( layer.grid == null, "grid set to null");
286 function test_Layer_ADG93_Filter(t) {
287 var params = {layers: "show:0,2"};
290 layer = new OpenLayers.Layer.ArcGIS93Rest(name, url, params);
291 var map = new OpenLayers.Map('map');
293 var pixel = new OpenLayers.Pixel(5,6);
294 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
295 // Set up basic params.
296 var tParams = OpenLayers.Util.extend({}, OpenLayers.Util.upperCaseObject(params));
297 tParams = OpenLayers.Util.extend(tParams, {
298 FORMAT: "png", BBOX: "1,2,3,4", SIZE: "256,256", F: "image", BBOXSR: "4326", IMAGESR: "4326"
301 // We need to actually set the "correct" url on a dom element, because doing so encodes things not encoded by getParameterString.
302 var encodingHack = document.createElement("img");
305 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
306 t.eq( tile.imgDiv.src, encodingHack.src, "image src no filter" );
308 layer.setLayerFilter('1', "MR_TOAD = 'FLYING'");
309 tParams["LAYERDEFS"] = "1:MR_TOAD = 'FLYING';";
311 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
312 t.eq( tile.imgDiv.src, encodingHack.src, "image src one filter" );
314 layer.setLayerFilter('1', "MR_TOAD = 'NOT FLYING'");
315 tParams["LAYERDEFS"] = "1:MR_TOAD = 'NOT FLYING';";
317 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
318 t.eq( tile.imgDiv.src, encodingHack.src, "image src change one filter" );
320 layer.setLayerFilter('2', "true = false");
321 tParams["LAYERDEFS"] = "1:MR_TOAD = 'NOT FLYING';2:true = false;";
323 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
324 t.eq( tile.imgDiv.src, encodingHack.src, "image src two filters" );
326 layer.setLayerFilter('99', "some_col > 5");
327 tParams["LAYERDEFS"] = "1:MR_TOAD = 'NOT FLYING';2:true = false;99:some_col > 5;";
329 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
330 t.eq( tile.imgDiv.src, encodingHack.src, "image src three filters" );
332 layer.clearLayerFilter('2');
333 tParams["LAYERDEFS"] = "1:MR_TOAD = 'NOT FLYING';99:some_col > 5;";
335 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
336 t.eq( tile.imgDiv.src, encodingHack.src, "image src removed middle filter" );
338 layer.clearLayerFilter('2');
339 tParams["LAYERDEFS"] = "1:MR_TOAD = 'NOT FLYING';99:some_col > 5;";
341 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
342 t.eq( tile.imgDiv.src, encodingHack.src, "image src removed missing filter (no change)" );
344 layer.clearLayerFilter();
345 delete tParams["LAYERDEFS"];
347 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
348 t.eq( tile.imgDiv.src, encodingHack.src, "image src removed all filters" );
350 layer.clearLayerFilter();
352 encodingHack.src = (url + "?" + OpenLayers.Util.getParameterString(tParams));
353 t.eq( tile.imgDiv.src, encodingHack.src, "image src removed all (no) filters" );
361 <div id="map" style="width:500px;height:550px"></div>