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://labs.metacarta.com/wms-c/Basic.py/";
10 var options = {'layername':'basic', 'type':'png'};
13 function test_Layer_TMS_constructor (t) {
16 layer = new OpenLayers.Layer.TMS(name, url, options);
17 t.ok( layer instanceof OpenLayers.Layer.TMS, "returns OpenLayers.Layer.TMS object" );
22 function test_Layer_TMS_clearTiles (t) {
24 var map = new OpenLayers.Map('map');
25 layer = new OpenLayers.Layer.TMS(name, url, options);
28 map.setCenter(new OpenLayers.LonLat(0,0));
30 //grab a reference to one of the tiles
31 var tile = layer.grid[0][0];
35 t.ok( layer.grid != null, "layer.grid does not get nullified" );
40 function test_Layer_TMS_getTMSBounds(t) {
43 layer = new OpenLayers.Layer.TMS(name, url, options);
45 var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
46 var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
47 layer.grid = [ [6, tr],
50 var bounds = layer.getTilesBounds();
52 var testBounds = new OpenLayers.Bounds(1,2,3,4);
54 t.ok( bounds.equals(testBounds), "getTMSBounds() returns correct bounds");
59 function test_Layer_TMS_getResolution(t) {
62 var map = new OpenLayers.Map('map');
63 layer = new OpenLayers.Layer.TMS(name, url, options);
68 t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
72 function test_Layer_TMS_getZoomForExtent(t) {
76 var map = new OpenLayers.Map('map');
77 layer = new OpenLayers.Layer.TMS(name, url, options);
80 bounds = new OpenLayers.Bounds(10,10,12,12);
81 zoom = layer.getZoomForExtent(bounds);
83 t.eq( zoom, 8, "getZoomForExtent() returns correct value");
85 bounds = new OpenLayers.Bounds(10,10,100,100);
86 zoom = layer.getZoomForExtent(bounds);
88 t.eq( zoom, 2, "getZoomForExtent() returns correct value");
93 /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
99 function 07_Layer_TMS_moveTo(t) {
102 function 08_Layer_TMS_insertColumn(t) {
105 function 09_Layer_TMS_insertRow(t) {
110 function test_Layer_TMS_getURL(t) {
114 var map = new OpenLayers.Map('map', options);
115 var options = {'layername':'basic', 'type':'png'};
116 layer = new OpenLayers.Layer.TMS(name, url, options);
118 map.setCenter(new OpenLayers.LonLat(0,0), 9);
119 var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
120 t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/basic/9/261/192.png", "Tile URL is correct");
122 var layer2 = layer.clone();
123 layer2.serviceVersion = "1.2.3";
124 map.addLayer(layer2);
125 tileurl = layer2.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
126 t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/1.2.3/basic/9/261/192.png", "TMS serviceVersion is correct");
128 layer.url = ["http://tilecache1/", "http://tilecache2/", "http://tilecache3/"];
129 tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
130 t.eq(tileurl, "http://tilecache1/1.0.0/basic/9/261/192.png", "Tile URL is deterministic");
133 function test_Layer_TMS_Rounding(t) {
135 m = new OpenLayers.Map("map", {'maxExtent':new OpenLayers.Bounds(-122.6579,37.4901,-122.0738,37.8795)});
136 layer = new OpenLayers.Layer.TMS( "TMS",
137 "http://labs.metacarta.com/wms-c/Basic.py/", {layername: 'basic', type:'png', resolutions:[0.000634956337608418]} );
140 t.eq(layer.getURL(layer.grid[3][3].bounds), "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/basic/0/1/1.png", "TMS tiles around rounded properly.");
144 function test_Layer_TMS_serverResolutions(t) {
147 var map = new OpenLayers.Map('map', {
151 var layer = new OpenLayers.Layer.TMS('tc layer', '', options);
153 map.setCenter(new OpenLayers.LonLat(0,0), 1);
155 var tileurl = layer.getURL(new OpenLayers.Bounds(0,0,0,0));
156 var level = parseInt(tileurl.split('/')[2]);
157 t.eq(map.getZoom(), level, "Tile zoom level is correct without serverResolutions");
159 layer.serverResolutions = [14,13,12,11,10];
160 tileurl = layer.getURL(new OpenLayers.Bounds(0,0,0,0));
161 level = parseInt(tileurl.split('/')[2]);
162 var res = map.getResolution();
163 var gotLevel = OpenLayers.Util.indexOf(layer.serverResolutions, res);
164 t.eq(gotLevel, level, "Tile zoom level is correct with serverResolutions");
169 function test_Layer_TMS_setMap(t) {
173 var map = new OpenLayers.Map('map', options);
174 layer = new OpenLayers.Layer.TMS(name, url, options);
176 t.eq(layer.tileOrigin, null, "Tile origin starts out null");
179 t.eq(layer.tileOrigin.lat, -90, "lat is -90");
180 t.eq(layer.tileOrigin.lon, -180, "lon is -180");
184 function test_Layer_TMS_destroy (t) {
188 var map = new OpenLayers.Map('map');
189 layer = new OpenLayers.Layer.TMS(name, url, options);
192 t.eq( layer.grid, null, "layer.grid is null after destroy" );
193 t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
196 //test with tile creation
197 layer = new OpenLayers.Layer.TMS(name, url, options);
199 map.setCenter(new OpenLayers.LonLat(0,0), 5);
200 //grab a reference to one of the tiles
201 var tile = layer.grid[0][0];
205 t.ok( layer.grid == null, "tiles appropriately destroyed");
213 <div id="map" style="width:500px;height:550px;"></div>