1 |
3032
|
perry
|
<html>
|
2 |
|
|
<head>
|
3 |
|
|
<script src="../lib/OpenLayers.js"></script>
|
4 |
|
|
<script type="text/javascript"><!--
|
5 |
|
|
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
6 |
|
|
var layer;
|
7 |
|
|
|
8 |
|
|
var name = 'Test Layer';
|
9 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
10 |
|
|
var params = { map: '/mapdata/vmap_wms.map',
|
11 |
|
|
layers: 'basic',
|
12 |
|
|
format: 'image/png'};
|
13 |
|
|
|
14 |
|
|
function test_01_Layer_WMS_constructor (t) {
|
15 |
|
|
t.plan( 4 );
|
16 |
|
|
|
17 |
|
|
layer = new OpenLayers.Layer.WMS();
|
18 |
|
|
|
19 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
20 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
21 |
|
|
t.ok( layer instanceof OpenLayers.Layer.WMS, "new OpenLayers.Layer.WMS returns object" );
|
22 |
|
|
t.eq( layer.url, "http://octo.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );
|
23 |
|
|
t.eq( layer.params.MAP, "/mapdata/vmap_wms.map", "params passed in correctly uppercased" );
|
24 |
|
|
|
25 |
|
|
t.eq( layer.params.SERVICE, "WMS", "default params correclty uppercased and copied");
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
function test_02_Layer_WMS_addtile (t) {
|
31 |
|
|
t.plan( 6 );
|
32 |
|
|
|
33 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
34 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
35 |
|
|
var map = new OpenLayers.Map($('map'));
|
36 |
|
|
map.addLayer(layer);
|
37 |
|
|
var pixel = new OpenLayers.Pixel(5,6);
|
38 |
|
|
var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
|
39 |
|
|
tile.draw();
|
40 |
|
|
|
41 |
|
|
var img = tile.imgDiv;
|
42 |
|
|
|
43 |
|
|
t.eq( img.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "image src is created correctly via addtile" );
|
44 |
|
|
t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" );
|
45 |
|
|
t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" );
|
46 |
|
|
|
47 |
|
|
var firstChild = layer.div.firstChild;
|
48 |
|
|
if (!isMozilla)
|
49 |
|
|
t.ok( true, "skipping element test outside of Mozilla");
|
50 |
|
|
else
|
51 |
|
|
t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
|
52 |
|
|
t.eq( firstChild.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "div first child is correct image object" );
|
53 |
|
|
t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." );
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
function test_03_Layer_WMS_inittiles (t) {
|
57 |
|
|
t.plan( 2 );
|
58 |
|
|
var map = new OpenLayers.Map($('map'));
|
59 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
60 |
|
|
map.addLayer(layer);
|
61 |
|
|
map.setCenter(new OpenLayers.LonLat(0,0),5);
|
62 |
|
|
t.eq( layer.grid.length, 7, "Grid rows is correct." );
|
63 |
|
|
t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
|
64 |
|
|
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
function test_04_Layer_WMS_clone (t) {
|
69 |
|
|
t.plan(4);
|
70 |
|
|
|
71 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
72 |
|
|
var options = {tileSize: new OpenLayers.Size(500,50)};
|
73 |
|
|
var map = new OpenLayers.Map('map', options);
|
74 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
75 |
|
|
map.addLayer(layer);
|
76 |
|
|
|
77 |
|
|
layer.grid = [ [6, 7],
|
78 |
|
|
[8, 9]];
|
79 |
|
|
|
80 |
|
|
var clone = layer.clone();
|
81 |
|
|
|
82 |
|
|
t.ok( clone.grid == null, "clone does not copy grid");
|
83 |
|
|
|
84 |
|
|
t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
|
85 |
|
|
|
86 |
|
|
layer.tileSize.w += 40;
|
87 |
|
|
|
88 |
|
|
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
|
89 |
|
|
|
90 |
|
|
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
function test_05_Layer_WMS_isBaseLayer(t) {
|
94 |
|
|
|
95 |
|
|
t.plan(2);
|
96 |
|
|
|
97 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
98 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
99 |
|
|
|
100 |
|
|
t.ok( layer.isBaseLayer, "baselayer is true by default");
|
101 |
|
|
|
102 |
|
|
var newParams = Object.extend(new Object(), params);
|
103 |
|
|
newParams.transparent = "true";
|
104 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, newParams);
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
function test_06_Layer_WMS_mergeNewParams (t) {
|
114 |
|
|
t.plan( 3 );
|
115 |
|
|
|
116 |
|
|
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
|
117 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
118 |
|
|
|
119 |
|
|
var newParams = { layers: 'sooper',
|
120 |
|
|
chickpeas: 'image/png'};
|
121 |
|
|
|
122 |
|
|
layer.mergeNewParams(newParams);
|
123 |
|
|
|
124 |
|
|
t.eq( layer.params.LAYERS, "sooper", "mergeNewParams() overwrites well");
|
125 |
|
|
t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() adds well");
|
126 |
|
|
|
127 |
|
|
newParams.CHICKPEAS = 151;
|
128 |
|
|
|
129 |
|
|
t.eq( layer.params.CHICKPEAS, "image/png", "mergeNewParams() makes clean copy of hashtable");
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
function test_07_Layer_WMS_getFullRequestString (t) {
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
t.plan( 2 );
|
136 |
|
|
|
137 |
|
|
var map = new OpenLayers.Map('map');
|
138 |
|
|
map.projection = "xx";
|
139 |
|
|
tUrl = "http://octo.metacarta.com/cgi-bin/mapserv";
|
140 |
|
|
tParams = { layers: 'basic',
|
141 |
|
|
format: 'image/png'};
|
142 |
|
|
var tLayer = new OpenLayers.Layer.WMS(name, tUrl, tParams);
|
143 |
|
|
map.addLayer(tLayer);
|
144 |
|
|
str = tLayer.getFullRequestString();
|
145 |
|
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?LAYERS=basic&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=xx", "getFullRequestString() adds SRS value");
|
146 |
|
|
|
147 |
|
|
tLayer.projection = "none";
|
148 |
|
|
str = tLayer.getFullRequestString();
|
149 |
|
|
t.eq(str, "http://octo.metacarta.com/cgi-bin/mapserv?LAYERS=basic&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage", "getFullRequestString() by default does *not* add SRS value if projection is 'none'");
|
150 |
|
|
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
function test_99_Layer_WMS_destroy (t) {
|
154 |
|
|
|
155 |
|
|
t.plan( 1 );
|
156 |
|
|
|
157 |
|
|
var map = new OpenLayers.Map('map');
|
158 |
|
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
159 |
|
|
map.addLayer(layer);
|
160 |
|
|
|
161 |
|
|
map.setCenter(new OpenLayers.LonLat(0,0), 5);
|
162 |
|
|
|
163 |
|
|
//grab a reference to one of the tiles
|
164 |
|
|
var tile = layer.grid[0][0];
|
165 |
|
|
|
166 |
|
|
layer.destroy();
|
167 |
|
|
|
168 |
|
|
// checks to make sure superclass (grid) destroy() was called
|
169 |
|
|
|
170 |
|
|
t.ok( layer.grid == null, "grid set to null");
|
171 |
|
|
}
|
172 |
|
|
// -->
|
173 |
|
|
</script>
|
174 |
|
|
</head>
|
175 |
|
|
<body>
|
176 |
|
|
<div id="map" style="width:500px;height:550px;display:none"></div>
|
177 |
|
|
</body>
|
178 |
|
|
</html>
|