Project

General

Profile

1 3032 perry
<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://octo.metacarta.com/cgi-bin/mapserv";
10
    var params = { map: '/mapdata/vmap_wms.map',
11
                   layers: 'basic',
12
                   format: 'image/png'};
13
14
    /**
15
     *  NOTE TO READER:
16
     *
17
     *    Some of the tests on the Grid class actually use the WMS class.
18
     *    This is because WMS is a subclass of Grid and it implements the
19
     *    core functions which are necessary to test the tile-generation
20
     *    mechanism.
21
     *
22
     */
23
24
25
    function test_01_Layer_Grid_constructor (t) {
26
        t.plan( 1 );
27
28
        layer = new OpenLayers.Layer.Grid(name, url, params, null);
29
        t.ok( layer instanceof OpenLayers.Layer.Grid, "returns OpenLayers.Layer.Grid object" );
30
    }
31
32
33
    function test_02_Layer_Grid_inittiles (t) {
34
        t.plan( 2 );
35
        var map = new OpenLayers.Map($('map'));
36
        layer = new OpenLayers.Layer.WMS(name, url, params);
37
        map.addLayer(layer);
38
        map.setCenter(new OpenLayers.LonLat(0,0),5);
39
        t.eq( layer.grid.length, 7, "Grid rows is correct." );
40
        t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
41
42
    }
43
44
    function test_03_Layer_Grid_clearTiles (t) {
45
        t.plan(1);
46
        var map = new OpenLayers.Map('map');
47
        layer = new OpenLayers.Layer.WMS(name, url, params);
48
        map.addLayer(layer);
49
50
        map.setCenter(new OpenLayers.LonLat(0,0));
51
52
53
        //grab a reference to one of the tiles
54
        var tile = layer.grid[0][0];
55
56
        layer.clearGrid();
57
58
        t.ok( layer.grid != null, "layer.grid does not get nullified" );
59
    }
60
61
62
    function test_04_Layer_Grid_getGridBounds(t) {
63
        t.plan( 1 );
64
65
        layer = new OpenLayers.Layer.WMS(name, url, params);
66
67
        var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
68
        var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
69
        layer.grid = [ [6, tr],
70
                       [bl, 7]];
71
72
        var bounds = layer.getGridBounds();
73
74
        var testBounds = new OpenLayers.Bounds(1,2,3,4);
75
76
        t.ok( bounds.equals(testBounds), "getGridBounds() returns correct bounds")
77
    }
78
79
    function test_05_Layer_Grid_getResolution(t) {
80
        t.plan( 1 );
81
82
        var map = new OpenLayers.Map('map');
83
        layer = new OpenLayers.Layer.WMS(name, url, params);
84
        map.addLayer(layer);
85
86
        map.zoom = 5;
87
88
        t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
89
    }
90
91
    function test_06_Layer_Grid_getZoomForExtent(t) {
92
        t.plan( 2 );
93
        var bounds, zoom;
94
95
        var map = new OpenLayers.Map('map');
96
        layer = new OpenLayers.Layer.WMS(name, url, params);
97
        map.addLayer(layer);
98
99
        bounds = new OpenLayers.Bounds(10,10,12,12);
100
        zoom = layer.getZoomForExtent(bounds);
101
102
        t.eq( zoom, 8, "getZoomForExtent() returns correct value");
103
104
        bounds = new OpenLayers.Bounds(10,10,100,100);
105
        zoom = layer.getZoomForExtent(bounds);
106
107
        t.eq( zoom, 3, "getZoomForExtent() returns correct value");
108
    }
109
110
111
    /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
112
     *
113
     *    -moveTo
114
     *    -insertColumn
115
     *    -insertRow
116
117
    function 07_Layer_Grid_moveTo(t) {
118
    }
119
120
    function 08_Layer_Grid_insertColumn(t) {
121
    }
122
123
    function 09_Layer_Grid_insertRow(t) {
124
    }
125
126
     *
127
     */
128
129
    function test_10_Layer_Grid_clone(t) {
130
        t.plan(4);
131
132
        var options = {tileSize: new OpenLayers.Size(500,50)};
133
        var map = new OpenLayers.Map('map', options);
134
        layer = new OpenLayers.Layer.Grid(name, url, params);
135
        map.addLayer(layer);
136
137
        layer.grid = [ [6, 7],
138
                       [8, 9]];
139
140
        var clone = layer.clone();
141
142
        t.ok( clone.grid == null, "clone does not copy grid");
143
144
        t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
145
146
        layer.tileSize.w += 40;
147
148
        t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
149
150
        t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
151
    }
152
153
    function test_11_Layer_Grid_setMap(t) {
154
155
        t.plan(2);
156
157
        var options = {tileSize: new OpenLayers.Size(500,50)};
158
        var map = new OpenLayers.Map('map', options);
159
        layer = new OpenLayers.Layer.Grid(name, url, params);
160
161
162
        layer.setMap(map);
163
164
        t.ok( layer.tileSize != null, "tileSize has been set");
165
        t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
166
    }
167
168
169
    function test_99_Layer_Grid_destroy (t) {
170
171
        t.plan( 3 );
172
173
        var map = new OpenLayers.Map('map');
174
        layer = new OpenLayers.Layer.Grid(name, url, params);
175
        map.addLayer(layer);
176
        layer.destroy();
177
        t.eq( layer.grid, null, "layer.grid is null after destroy" );
178
        t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
179
180
181
    //test with tile creation
182
        layer = new OpenLayers.Layer.WMS(name, url, params);
183
        map.addLayer(layer);
184
185
        map.setCenter(new OpenLayers.LonLat(0,0), 5);
186
187
        //grab a reference to one of the tiles
188
        var tile = layer.grid[0][0];
189
190
        layer.destroy();
191
192
        t.ok( layer.grid == null, "tiles appropriately destroyed")
193
    }
194
195
       // -->
196
  </script>
197
</head>
198
<body>
199
<div id="map" style="width:500px;height:550px;display:none"></div>
200
</body>
201
</html>