3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
8 function test_Layer_TileCache_constructor (t) {
11 var name = 'Test Layer';
12 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
13 var layername = "basic";
14 var options = {'type':'png'};
16 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
17 t.ok( layer instanceof OpenLayers.Layer.TileCache, "returns OpenLayers.Layer.TileCache object" );
21 function test_Layer_TileCache_clone(t) {
24 var name = 'Test Layer';
25 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
26 var layername = "basic";
27 var options = {'type':'png'};
28 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
30 var clone = layer.clone();
31 t.eq(layer.name, clone.name, "clone() correctly copy the 'name' property");
32 t.eq(layer.url, clone.url, "clone() correctly copy the 'url' property");
33 t.eq(layer.layername, clone.layername, "clone() correctly copy the 'layername' property");
38 function test_Layer_TileCache_clearTiles (t) {
40 var name = 'Test Layer';
41 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
42 var layername = "basic";
43 var options = {'type':'png'};
44 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
45 var map = new OpenLayers.Map('map');
48 map.setCenter(new OpenLayers.LonLat(0,0));
50 //grab a reference to one of the tiles
51 var tile = layer.grid[0][0];
55 t.ok( layer.grid != null, "layer.grid does not get nullified" );
60 function test_Layer_TileCache_getTileCacheBounds(t) {
63 var name = 'Test Layer';
64 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
65 var layername = "basic";
66 var options = {'type':'png'};
67 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
69 var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
70 var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
71 layer.grid = [ [6, tr],
74 var bounds = layer.getGridBounds();
76 var testBounds = new OpenLayers.Bounds(1,2,3,4);
78 t.ok( bounds.equals(testBounds), "getTileCacheBounds() returns correct bounds")
82 function test_Layer_TileCache_getResolution(t) {
85 var name = 'Test Layer';
86 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
87 var layername = "basic";
88 var options = {'type':'png', maxResolution: 180/256};
89 var map = new OpenLayers.Map('map');
90 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
95 t.eq( layer.getResolution(), 0.02197265625, "getResolution() returns correct value");
99 function test_Layer_TileCache_getZoomForExtent(t) {
103 var name = 'Test Layer';
104 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
105 var layername = "basic";
106 var options = {'type':'png', maxResolution: 180/256};
107 var map = new OpenLayers.Map('map');
108 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
111 bounds = new OpenLayers.Bounds(10,10,12,12);
112 zoom = layer.getZoomForExtent(bounds);
114 t.eq( zoom, 7, "getZoomForExtent() returns correct value");
116 bounds = new OpenLayers.Bounds(10,10,100,100);
117 zoom = layer.getZoomForExtent(bounds);
119 t.eq( zoom, 1, "getZoomForExtent() returns correct value");
123 function test_Layer_TileCache_getURL(t) {
127 var map = new OpenLayers.Map('map');
128 var name = 'Test Layer';
129 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
130 var layername = "basic";
131 var options = {'layername':'basic', 'format':'image/jpg', maxResolution: 180/256};
132 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
134 map.setCenter(new OpenLayers.LonLat(0,0), 9);
135 var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
136 t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/basic/09/000/000/522/000/000/384.jpeg", "Tile URL is correct");
138 layer.url = ["http://tilecache1/", "http://tilecache2/", "http://tilecache3/"];
139 tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
140 t.eq(tileurl, "http://tilecache2/basic/09/000/000/522/000/000/384.jpeg", "Tile URL is deterministic");
144 function test_Layer_TileCache_serverResolutions(t) {
147 var map = new OpenLayers.Map('map', {
151 var layer = new OpenLayers.Layer.TileCache('tc layer', '', 'basic');
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 gotLevel = OpenLayers.Util.indexOf(layer.serverResolutions, map.getResolution());
163 t.eq(gotLevel, level, "Tile zoom level is correct with serverResolutions");
168 function test_Layer_TileCache_destroy (t) {
172 var name = 'Test Layer';
173 var url = "http://labs.metacarta.com/wms-c/Basic.py/";
174 var layername = "basic";
175 var options = {'layername':'basic', 'format':'image/jpg', maxResolution: 180/256};
176 var map = new OpenLayers.Map('map');
177 var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
180 t.eq( layer.grid, null, "layer.grid is null after destroy" );
181 t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
184 //test with tile creation
185 layer = new OpenLayers.Layer.TileCache(name, url, options);
187 map.setCenter(new OpenLayers.LonLat(0,0), 5);
188 //grab a reference to one of the tiles
189 var tile = layer.grid[0][0];
193 t.ok( layer.grid == null, "tiles appropriately destroyed");
201 <div id="map" style="width:500px;height:550px"></div>