3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
8 var name = 'Test Layer';
9 var url = "http://boston.freemap.in/tile.php?";
12 'g':'border,water,roads,openspace',
19 function test_Layer_KaMap_constructor (t) {
22 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
23 t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
26 function test_Layer_Grid_moveTo_buffer_calculation (t) {
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} );
35 var layer1 = new OpenLayers.Layer.KaMap( "1 buffer: OpenLayers WMS",
36 "http://labs.metacarta.com/wms/vmap0",
37 {layers: 'basic'}, {'buffer':1} );
40 var layer2 = new OpenLayers.Layer.KaMap( "2 buffer: OpenLayers WMS",
41 "http://labs.metacarta.com/wms/vmap0",
42 {layers: 'basic'}, {'buffer':2} );
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" );
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" );
62 function test_Layer_KaMap_inittiles (t) {
64 var map = new OpenLayers.Map('map');
65 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
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." );
74 function test_Layer_KaMap_clearTiles (t) {
76 var map = new OpenLayers.Map('map');
77 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
80 map.setCenter(new OpenLayers.LonLat(0,0));
82 //grab a reference to one of the tiles
83 var tile = layer.grid[0][0];
87 t.ok( layer.grid != null, "layer.grid does not get nullified" );
92 function test_Layer_KaMap_getKaMapBounds(t) {
95 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
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],
102 var bounds = layer.getTilesBounds();
104 var testBounds = new OpenLayers.Bounds(1,2,3,4);
106 t.ok( bounds.equals(testBounds), "getKaMapBounds() returns correct bounds")
111 function test_Layer_KaMap_getResolution(t) {
114 var map = new OpenLayers.Map('map');
115 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
120 t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
124 function test_Layer_KaMap_getZoomForExtent(t) {
128 var map = new OpenLayers.Map('map');
129 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
132 bounds = new OpenLayers.Bounds(10,10,12,12);
133 zoom = layer.getZoomForExtent(bounds);
135 t.eq( zoom, 8, "getZoomForExtent() returns correct value");
137 bounds = new OpenLayers.Bounds(10,10,100,100);
138 zoom = layer.getZoomForExtent(bounds);
140 t.eq( zoom, 2, "getZoomForExtent() returns correct value");
144 function test_Layer_kaMap_mergeNewParams (t) {
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);
151 var newParams = { layers: 'sooper',
152 chickpeas: 'image/png'};
155 map.zoomToMaxExtent();
156 layer.redraw = function() {
157 t.ok(true, "layer is redrawn after new params merged");
160 layer.mergeNewParams(newParams);
162 t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
163 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
165 newParams.chickpeas = 151;
167 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
172 /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
178 function 07_Layer_KaMap_moveTo(t) {
181 function 08_Layer_KaMap_insertColumn(t) {
184 function 09_Layer_KaMap_insertRow(t) {
190 function test_Layer_KaMap_clone(t) {
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);
198 layer.grid = [ [6, 7],
201 var clone = layer.clone();
203 t.ok( clone.grid != layer.grid, "clone does not copy grid");
205 t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
207 layer.tileSize.w += 40;
209 t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
211 t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
213 t.eq( clone.CLASS_NAME, "OpenLayers.Layer.KaMap", "Clone is a ka-map layer");
219 function test_Layer_KaMap_setMap(t) {
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);
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");
234 function test_Layer_KaMap_getTileBounds(t) {
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);
240 var newParams = { layers: 'sooper',
241 chickpeas: 'image/png'};
244 map.zoomToMaxExtent();
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");
254 function test_Layer_KaMap_destroy (t) {
258 var map = new OpenLayers.Map('map');
259 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
262 t.eq( layer.grid, null, "layer.grid is null after destroy" );
263 t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
266 //test with tile creation
267 layer = new OpenLayers.Layer.KaMap(name, url, params, units);
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];
275 t.ok( layer.grid == null, "tiles appropriately destroyed");
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>