OpenLayers OpenLayers

root/trunk/openlayers/tests/Layer/TMS.html

Revision 6724, 5.8 kB (checked in by euzuro, 9 months ago)

fix up tests, remove _01_. (Closes #1387)

  • Property svn:eol-style set to native
Line 
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://labs.metacarta.com/wms-c/Basic.py/";
10     var options = {'layername':'basic', 'type':'png'};
11
12
13     function test_Layer_TMS_constructor (t) {
14         t.plan( 1 );
15                        
16         layer = new OpenLayers.Layer.TMS(name, url, options);
17         t.ok( layer instanceof OpenLayers.Layer.TMS, "returns OpenLayers.Layer.TMS object" );
18     }
19
20
21
22     function test_Layer_TMS_clearTiles (t) {
23         t.plan( 1 );
24         var map = new OpenLayers.Map('map');
25         layer = new OpenLayers.Layer.TMS(name, url, options);
26         map.addLayer(layer);
27
28         map.setCenter(new OpenLayers.LonLat(0,0));
29
30         //grab a reference to one of the tiles
31         var tile = layer.grid[0][0];       
32
33         layer.clearGrid();
34
35         t.ok( layer.grid != null, "layer.grid does not get nullified" );
36         map.destroy();
37     }
38
39
40     function test_Layer_TMS_getTMSBounds(t) {
41         t.plan( 1 );
42
43         layer = new OpenLayers.Layer.TMS(name, url, options);
44
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],
48                        [bl, 7]];
49
50         var bounds = layer.getTilesBounds();
51    
52         var testBounds = new OpenLayers.Bounds(1,2,3,4);
53        
54         t.ok( bounds.equals(testBounds), "getTMSBounds() returns correct bounds")
55        
56         layer.grid = null;
57     }
58
59     function test_Layer_TMS_getResolution(t) {
60         t.plan( 1 );
61
62         var map = new OpenLayers.Map('map');
63         layer = new OpenLayers.Layer.TMS(name, url, options);
64         map.addLayer(layer);
65
66         map.zoom = 5;
67
68         t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
69         map.destroy();
70     }
71
72     function test_Layer_TMS_getZoomForExtent(t) {
73         t.plan( 2 );
74         var bounds, zoom;
75
76         var map = new OpenLayers.Map('map');
77         layer = new OpenLayers.Layer.TMS(name, url, options);
78         map.addLayer(layer);
79
80         bounds = new OpenLayers.Bounds(10,10,12,12);
81         zoom = layer.getZoomForExtent(bounds);
82
83         t.eq( zoom, 8, "getZoomForExtent() returns correct value");
84
85         bounds = new OpenLayers.Bounds(10,10,100,100);
86         zoom = layer.getZoomForExtent(bounds);
87
88         t.eq( zoom, 2, "getZoomForExtent() returns correct value");
89         map.destroy();
90     }   
91
92
93     /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
94      *     
95      *    -moveTo
96      *    -insertColumn
97      *    -insertRow
98     
99     function 07_Layer_TMS_moveTo(t) {
100     }
101
102     function 08_Layer_TMS_insertColumn(t) {
103     }
104
105     function 09_Layer_TMS_insertRow(t) {
106     }
107
108      *
109      */
110     function test_Layer_TMS_getURL(t) {
111
112         t.plan(3);
113        
114         var map = new OpenLayers.Map('map', options);
115         var options = {'layername':'basic', 'type':'png'};
116         layer = new OpenLayers.Layer.TMS(name, url, options);
117         map.addLayer(layer);
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");
121    
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");
127
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");
131         map.destroy();
132     }
133     function test_Layer_TMS_Rounding(t) {
134         t.plan(1);
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]} );
138             m.addLayer(layer);
139             m.zoomToMaxExtent()
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.");
141         m.destroy();
142     }       
143            
144
145     function test_Layer_TMS_setMap(t) {
146
147         t.plan(3);
148        
149         var map = new OpenLayers.Map('map', options);
150         layer = new OpenLayers.Layer.TMS(name, url, options);
151
152         t.eq(layer.tileOrigin, null, "Tile origin starts out null");
153         layer.setMap(map);
154        
155         t.eq(layer.tileOrigin.lat, -90, "lat is -90");
156         t.eq(layer.tileOrigin.lon, -180, "lon is -180");
157         map.destroy();
158     }
159
160     function test_Layer_TMS_destroy (t) {
161
162         t.plan( 3 );
163
164         var map = new OpenLayers.Map('map');
165         layer = new OpenLayers.Layer.TMS(name, url, options);
166         map.addLayer(layer);
167         layer.destroy();
168         t.eq( layer.grid, null, "layer.grid is null after destroy" );
169         t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
170
171
172     //test with tile creation
173         layer = new OpenLayers.Layer.TMS(name, url, options);
174         map.addLayer(layer);
175         map.setCenter(new OpenLayers.LonLat(0,0), 5);
176         //grab a reference to one of the tiles
177         var tile = layer.grid[0][0];       
178
179         layer.destroy();
180
181         t.ok( layer.grid == null, "tiles appropriately destroyed");
182         map.destroy();
183     }
184    
185
186   </script>
187 </head>
188 <body>
189 <div id="map" style="width:500px;height:550px"></div>
190 </body>
191 </html>
Note: See TracBrowser for help on using the browser.