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://boston.freemap.in/tile.php?";
10
    var params = {
11
                  'map':'boston-new',
12
                  'g':'border,water,roads,openspace',
13
                  'i':'JPEG'
14
                 };
15
    var units = "meters";
16
17
18
19
    function test_01_Layer_KaMap_constructor (t) {
20
        t.plan( 1 );
21
22
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
23
        t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
24
    }
25
26
27
    function test_02_Layer_KaMap_inittiles (t) {
28
        t.plan( 2 );
29
        var map = new OpenLayers.Map($('map'));
30
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
31
        map.addLayer(layer);
32
        map.setCenter(new OpenLayers.LonLat(0,0),5);
33
        t.eq( layer.grid.length, 6, "KaMap rows is correct." );
34
        t.eq( layer.grid[0].length, 4, "KaMap cols is correct." );
35
36
    }
37
38
    function test_03_Layer_KaMap_clearTiles (t) {
39
        t.plan( 1 );
40
        var map = new OpenLayers.Map('map');
41
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
42
        map.addLayer(layer);
43
44
        map.setCenter(new OpenLayers.LonLat(0,0));
45
46
        //grab a reference to one of the tiles
47
        var tile = layer.grid[0][0];
48
49
        layer.clearGrid();
50
51
        t.ok( layer.grid != null, "layer.grid does not get nullified" );
52
    }
53
54
55
    function test_04_Layer_KaMap_getKaMapBounds(t) {
56
        t.plan( 1 );
57
58
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
59
60
        var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
61
        var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
62
        layer.grid = [ [6, tr],
63
                       [bl, 7]];
64
65
        var bounds = layer.getGridBounds();
66
67
        var testBounds = new OpenLayers.Bounds(1,2,3,4);
68
69
        t.ok( bounds.equals(testBounds), "getKaMapBounds() returns correct bounds")
70
    }
71
72
    function test_05_Layer_KaMap_getResolution(t) {
73
        t.plan( 1 );
74
75
        var map = new OpenLayers.Map('map');
76
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
77
        map.addLayer(layer);
78
79
        map.zoom = 5;
80
81
        t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
82
    }
83
84
    function test_06_Layer_KaMap_getZoomForExtent(t) {
85
        t.plan( 2 );
86
        var bounds, zoom;
87
88
        var map = new OpenLayers.Map('map');
89
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
90
        map.addLayer(layer);
91
92
        bounds = new OpenLayers.Bounds(10,10,12,12);
93
        zoom = layer.getZoomForExtent(bounds);
94
95
        t.eq( zoom, 8, "getZoomForExtent() returns correct value");
96
97
        bounds = new OpenLayers.Bounds(10,10,100,100);
98
        zoom = layer.getZoomForExtent(bounds);
99
100
        t.eq( zoom, 3, "getZoomForExtent() returns correct value");
101
    }
102
103
104
    /** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
105
     *
106
     *    -moveTo
107
     *    -insertColumn
108
     *    -insertRow
109
110
    function 07_Layer_KaMap_moveTo(t) {
111
    }
112
113
    function 08_Layer_KaMap_insertColumn(t) {
114
    }
115
116
    function 09_Layer_KaMap_insertRow(t) {
117
    }
118
119
     *
120
     */
121
122
    function test_10_Layer_KaMap_clone(t) {
123
        t.plan(4);
124
125
        var options = {tileSize: new OpenLayers.Size(500,50)};
126
        var map = new OpenLayers.Map('map', options);
127
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
128
        map.addLayer(layer);
129
130
        layer.grid = [ [6, 7],
131
                       [8, 9]];
132
133
        var clone = layer.clone();
134
135
        t.ok( clone.grid == null, "clone does not copy grid");
136
137
        t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
138
139
        layer.tileSize.w += 40;
140
141
        t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
142
143
        t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
144
    }
145
146
    function test_11_Layer_KaMap_setMap(t) {
147
148
        t.plan(2);
149
150
        var options = {tileSize: new OpenLayers.Size(500,50)};
151
        var map = new OpenLayers.Map('map', options);
152
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
153
154
155
        layer.setMap(map);
156
157
        t.ok( layer.tileSize != null, "tileSize has been set");
158
        t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
159
    }
160
161
    function test_99_Layer_KaMap_destroy (t) {
162
163
        t.plan( 3 );
164
165
        var map = new OpenLayers.Map('map');
166
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
167
        map.addLayer(layer);
168
        layer.destroy();
169
        t.eq( layer.grid, null, "layer.grid is null after destroy" );
170
        t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
171
172
173
    //test with tile creation
174
        layer = new OpenLayers.Layer.KaMap(name, url, params, units);
175
        map.addLayer(layer);
176
        map.setCenter(new OpenLayers.LonLat(0,0), 5);
177
        //grab a reference to one of the tiles
178
        var tile = layer.grid[0][0];
179
180
        layer.destroy();
181
182
        t.ok( layer.grid == null, "tiles appropriately destroyed");
183
    }
184
185
       // -->
186
  </script>
187
</head>
188
<body>
189
<div id="map" style="width:500px;height:550px;display:none"></div>
190
</body>
191
</html>