]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Layer/KaMap.html
fixes notices
[syp.git] / openlayers / tests / Layer / KaMap.html
1 <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://boston.freemap.in/tile.php?";
10     var params = {
11                   'map':'boston-new', 
12                   'g':'border,water,roads,openspace', 
13                   'i':'JPEG'
14                  };
15     var units = "meters";
16
17
18
19     function test_Layer_KaMap_constructor (t) {
20         t.plan( 1 );
21                        
22         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
23         t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
24     }
25
26     function test_Layer_Grid_moveTo_buffer_calculation (t) {
27         t.plan(6);
28
29         var map = new OpenLayers.Map( 'map3' ); // odd map size
30         var layer0 = new OpenLayers.Layer.KaMap( "0 buffer: OpenLayers WMS", 
31                     "http://labs.metacarta.com/wms/vmap0",
32                     {layers: 'basic'}, {'buffer':0} );
33         map.addLayer(layer0);
34
35         var layer1 = new OpenLayers.Layer.KaMap( "1 buffer: OpenLayers WMS", 
36                 "http://labs.metacarta.com/wms/vmap0",
37                 {layers: 'basic'}, {'buffer':1} );
38         map.addLayer(layer1);
39
40         var layer2 = new OpenLayers.Layer.KaMap( "2 buffer: OpenLayers WMS", 
41                 "http://labs.metacarta.com/wms/vmap0",
42                 {layers: 'basic'}, {'buffer':2} );
43         map.addLayer(layer2);
44
45         map.setCenter(new OpenLayers.LonLat(0, 0), 4); 
46         t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" );
47         map.setBaseLayer(layer1);
48         t.eq( layer1.grid.length, 4, "Grid rows with buffer:1" );
49         map.setBaseLayer(layer2);
50         t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" );
51
52         // zooming in on Greenland exercises the bug from pre-r4313
53         map.setCenter(new OpenLayers.LonLat(0, 90), 4); 
54         t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" );
55         map.setBaseLayer(layer1);
56         t.eq( layer1.grid.length, 4, "Grid rows with buffer:1" );
57         map.setBaseLayer(layer2);
58         t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" );
59         map.destroy();
60     }
61
62     function test_Layer_KaMap_inittiles (t) {
63         t.plan( 2 );
64         var map = new OpenLayers.Map('map');
65         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
66         map.addLayer(layer);
67         map.setCenter(new OpenLayers.LonLat(0,0),5);
68         t.eq( layer.grid.length, 8, "KaMap rows is correct." );
69         t.eq( layer.grid[0].length, 6, "KaMap cols is correct." );
70         map.destroy();
71         
72     }
73
74     function test_Layer_KaMap_clearTiles (t) {
75         t.plan( 1 );
76         var map = new OpenLayers.Map('map');
77         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
78         map.addLayer(layer);
79
80         map.setCenter(new OpenLayers.LonLat(0,0));
81
82         //grab a reference to one of the tiles
83         var tile = layer.grid[0][0];        
84
85         layer.clearGrid();
86
87         t.ok( layer.grid != null, "layer.grid does not get nullified" );
88         map.destroy();
89     }
90
91
92     function test_Layer_KaMap_getKaMapBounds(t) {
93         t.plan( 1 );
94
95         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
96
97         var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
98         var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
99         layer.grid = [ [6, tr], 
100                        [bl, 7]];
101
102         var bounds = layer.getTilesBounds();
103     
104         var testBounds = new OpenLayers.Bounds(1,2,3,4);
105         
106         t.ok( bounds.equals(testBounds), "getKaMapBounds() returns correct bounds")
107         
108         layer.grid = null;
109     }
110
111     function test_Layer_KaMap_getResolution(t) {
112         t.plan( 1 );
113
114         var map = new OpenLayers.Map('map');
115         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
116         map.addLayer(layer);
117
118         map.zoom = 5;
119
120         t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
121         map.destroy();
122     }
123
124     function test_Layer_KaMap_getZoomForExtent(t) {
125         t.plan( 2 );
126         var bounds, zoom;
127
128         var map = new OpenLayers.Map('map');
129         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
130         map.addLayer(layer);
131
132         bounds = new OpenLayers.Bounds(10,10,12,12);
133         zoom = layer.getZoomForExtent(bounds);
134
135         t.eq( zoom, 8, "getZoomForExtent() returns correct value");
136
137         bounds = new OpenLayers.Bounds(10,10,100,100);
138         zoom = layer.getZoomForExtent(bounds);
139
140         t.eq( zoom, 2, "getZoomForExtent() returns correct value");
141         map.destroy();
142     }   
143     
144     function test_Layer_kaMap_mergeNewParams (t) {
145         t.plan( 4 );
146
147         var map = new OpenLayers.Map("map");
148         var url = "http://octo.metacarta.com/cgi-bin/mapserv";
149         layer = new OpenLayers.Layer.KaMap(name, url, params);
150         
151         var newParams = { layers: 'sooper', 
152                           chickpeas: 'image/png'};
153
154         map.addLayer(layer);
155         map.zoomToMaxExtent();
156         layer.redraw = function() {
157             t.ok(true, "layer is redrawn after new params merged");
158         }
159         
160         layer.mergeNewParams(newParams);
161         
162         t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
163         t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
164
165         newParams.chickpeas = 151;
166
167         t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
168         map.destroy();
169     }
170
171
172     /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR 
173      *     
174      *    -moveTo
175      *    -insertColumn
176      *    -insertRow
177     
178     function 07_Layer_KaMap_moveTo(t) {
179     }
180
181     function 08_Layer_KaMap_insertColumn(t) {
182     }
183
184     function 09_Layer_KaMap_insertRow(t) {
185     }
186
187      * 
188      */
189
190     function test_Layer_KaMap_clone(t) {
191         t.plan(5);
192         
193         var options = {tileSize: new OpenLayers.Size(500,50)};
194         var map = new OpenLayers.Map('map', options);
195         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
196         map.addLayer(layer);
197
198         layer.grid = [ [6, 7], 
199                        [8, 9]];
200
201         var clone = layer.clone();
202
203         t.ok( clone.grid != layer.grid, "clone does not copy grid");
204
205         t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
206
207         layer.tileSize.w += 40;
208
209         t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
210
211         t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
212         
213         t.eq( clone.CLASS_NAME, "OpenLayers.Layer.KaMap", "Clone is a ka-map layer");
214
215         layer.grid = null;
216         map.destroy();
217     }
218
219     function test_Layer_KaMap_setMap(t) {
220
221         t.plan(2);
222         
223         var options = {tileSize: new OpenLayers.Size(500,50)};
224         var map = new OpenLayers.Map('map', options);
225         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
226
227
228         layer.setMap(map);
229         
230         t.ok( layer.tileSize != null, "tileSize has been set");
231         t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
232         map.destroy();
233     }
234     function test_Layer_KaMap_getTileBounds(t) {
235         t.plan(2);
236         var map = new OpenLayers.Map("map");
237         var url = "http://octo.metacarta.com/cgi-bin/mapserv";
238         layer = new OpenLayers.Layer.KaMap(name, url, params);
239         
240         var newParams = { layers: 'sooper', 
241                           chickpeas: 'image/png'};
242
243         map.addLayer(layer);
244         map.zoomToMaxExtent();
245         map.zoomIn();
246         var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200));
247         t.eq(bounds.toBBOX(), "-180,0,0,180", "get tile bounds returns correct bounds"); 
248         map.pan(200,0,{animate:false});
249         var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200));
250         t.eq(bounds.toBBOX(), "0,0,180,180", "get tile bounds returns correct bounds after pan"); 
251         map.destroy();
252     }
253
254     function test_Layer_KaMap_destroy (t) {
255
256         t.plan( 3 );
257
258         var map = new OpenLayers.Map('map');
259         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
260         map.addLayer(layer);
261         layer.destroy();
262         t.eq( layer.grid, null, "layer.grid is null after destroy" );
263         t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
264
265
266     //test with tile creation
267         layer = new OpenLayers.Layer.KaMap(name, url, params, units);
268         map.addLayer(layer);
269         map.setCenter(new OpenLayers.LonLat(0,0), 5);
270         //grab a reference to one of the tiles
271         var tile = layer.grid[0][0];        
272
273         layer.destroy();
274
275         t.ok( layer.grid == null, "tiles appropriately destroyed");
276         map.destroy();
277     }
278     
279
280   </script>
281 </head>
282 <body>
283 <div id="map" style="width:500px;height:550px;display:none"></div>
284 <div id="map2" style="width:500px;height:550px;display:none"></div>
285 <div id="map3" style="width:594px;height:464px;display:none"></div>
286 </body>
287 </html>