1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var layer;
var name = 'Test Layer';
var url = "http://boston.freemap.in/tile.php?";
var params = {
'map':'boston-new',
'g':'border,water,roads,openspace',
'i':'JPEG'
};
var units = "meters";
function test_Layer_KaMap_constructor (t) {
t.plan( 1 );
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
}
function test_Layer_Grid_moveTo_buffer_calculation (t) {
t.plan(6);
var map = new OpenLayers.Map( 'map3' ); // odd map size
var layer0 = new OpenLayers.Layer.KaMap( "0 buffer: OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}, {'buffer':0} );
map.addLayer(layer0);
var layer1 = new OpenLayers.Layer.KaMap( "1 buffer: OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}, {'buffer':1} );
map.addLayer(layer1);
var layer2 = new OpenLayers.Layer.KaMap( "2 buffer: OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}, {'buffer':2} );
map.addLayer(layer2);
map.setCenter(new OpenLayers.LonLat(0, 0), 4);
t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" );
map.setBaseLayer(layer1);
t.eq( layer1.grid.length, 5, "Grid rows with buffer:1" );
map.setBaseLayer(layer2);
t.eq( layer2.grid.length, 7, "Grid rows with buffer:2" );
// zooming in on Greenland exercises the bug from pre-r4313
map.setCenter(new OpenLayers.LonLat(0, 90), 4);
t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" );
map.setBaseLayer(layer1);
t.eq( layer1.grid.length, 5, "Grid rows with buffer:1" );
map.setBaseLayer(layer2);
t.eq( layer2.grid.length, 7, "Grid rows with buffer:2" );
map.destroy();
}
function test_Layer_KaMap_inittiles (t) {
t.plan( 2 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0),5);
t.eq( layer.grid.length, 4, "KaMap rows is correct." );
t.eq( layer.grid[0].length, 3, "KaMap cols is correct." );
map.destroy();
}
function test_Layer_KaMap_clearTiles (t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0));
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.clearGrid();
t.ok( layer.grid != null, "layer.grid does not get nullified" );
map.destroy();
}
function test_Layer_KaMap_getKaMapBounds(t) {
t.plan( 1 );
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
layer.grid = [ [6, tr],
[bl, 7]];
var bounds = layer.getTilesBounds();
var testBounds = new OpenLayers.Bounds(1,2,3,4);
t.ok( bounds.equals(testBounds), "getKaMapBounds() returns correct bounds")
layer.grid = null;
}
function test_Layer_KaMap_getResolution(t) {
t.plan( 1 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.zoom = 5;
t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
map.destroy();
}
function test_Layer_KaMap_getZoomForExtent(t) {
t.plan( 2 );
var bounds, zoom;
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
bounds = new OpenLayers.Bounds(10,10,12,12);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 8, "getZoomForExtent() returns correct value");
bounds = new OpenLayers.Bounds(10,10,100,100);
zoom = layer.getZoomForExtent(bounds);
t.eq( zoom, 2, "getZoomForExtent() returns correct value");
map.destroy();
}
function test_Layer_kaMap_mergeNewParams (t) {
t.plan( 4 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.KaMap(name, url, params);
var newParams = { layers: 'sooper',
chickpeas: 'image/png'};
map.addLayer(layer);
map.zoomToMaxExtent();
layer.redraw = function() {
t.ok(true, "layer is redrawn after new params merged");
}
layer.mergeNewParams(newParams);
t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
newParams.chickpeas = 151;
t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
map.destroy();
}
/** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
*
* -moveTo
* -insertColumn
* -insertRow
function 07_Layer_KaMap_moveTo(t) {
}
function 08_Layer_KaMap_insertColumn(t) {
}
function 09_Layer_KaMap_insertRow(t) {
}
*
*/
function test_Layer_KaMap_clone(t) {
t.plan(5);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
layer.grid = [ [6, 7],
[8, 9]];
var clone = layer.clone();
t.ok( clone.grid != layer.grid, "clone does not copy grid");
t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");
layer.tileSize.w += 40;
t.eq( clone.tileSize.w, 500, "changing layer.tileSize does not change clone.tileSize -- a fresh copy was made, not just copied reference");
t.eq( clone.alpha, layer.alpha, "alpha copied correctly");
t.eq( clone.CLASS_NAME, "OpenLayers.Layer.KaMap", "Clone is a ka-map layer");
layer.grid = null;
map.destroy();
}
function test_Layer_KaMap_setMap(t) {
t.plan(2);
var options = {tileSize: new OpenLayers.Size(500,50)};
var map = new OpenLayers.Map('map', options);
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
layer.setMap(map);
t.ok( layer.tileSize != null, "tileSize has been set");
t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly");
map.destroy();
}
function test_Layer_KaMap_getTileBounds(t) {
t.plan(2);
var map = new OpenLayers.Map("map", {zoomMethod: null});
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.KaMap(name, url, params);
var newParams = { layers: 'sooper',
chickpeas: 'image/png'};
map.addLayer(layer);
map.zoomToMaxExtent();
map.zoomIn();
var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200));
t.eq(bounds.toBBOX(), "-180,0,0,180", "get tile bounds returns correct bounds");
map.pan(200,0,{animate:false});
var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200));
t.eq(bounds.toBBOX(), "0,0,180,180", "get tile bounds returns correct bounds after pan");
map.destroy();
}
function test_Layer_KaMap_destroy (t) {
t.plan( 3 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
layer.destroy();
t.eq( layer.grid, null, "layer.grid is null after destroy" );
t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
//test with tile creation
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0,0), 5);
//grab a reference to one of the tiles
var tile = layer.grid[0][0];
layer.destroy();
t.ok( layer.grid == null, "tiles appropriately destroyed");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px;display:none"></div>
<div id="map2" style="width:500px;height:550px;display:none"></div>
<div id="map3" style="width:594px;height:464px;display:none"></div>
</body>
</html>
|