Merge branch 'master' into singleTile

This commit is contained in:
Matt Priour
2012-03-09 14:04:21 -06:00
75 changed files with 1882 additions and 1 deletions
+126
View File
@@ -1404,6 +1404,132 @@
map.destroy();
});
}
function test_getGridData(t) {
t.plan(12);
var layer = new OpenLayers.Layer.Grid(null, null, null, {
isBaseLayer: true, getURL: function() {
return "/bogus/path/to/tile";
}
});
var map = new OpenLayers.Map({
div: "map",
layers: [layer],
controls: [],
center: [0, 0],
zoom: 1
});
// get tile data for [0, 0]
var data = layer.getTileData({lon: 0, lat: 0});
t.ok(data && data.tile, "[0, 0]: got tile data");
t.eq(data.i, 0, "[0, 0]: i");
t.eq(data.j, 128, "[0, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[0, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [-110, 45]
data = layer.getTileData({lon: -110, lat: 45});
t.ok(data && data.tile, "[-110, 45]: got tile data");
t.eq(data.i, 99, "[-110, 45]: i");
t.eq(data.j, 64, "[-110, 45]: j");
t.ok(
data.tile.bounds.equals({left: -180, bottom: -90, right: 0, top: 90}),
"[-110, 45]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, 300] (north of grid)
data = layer.getTileData({lon: 0, lat: 300})
t.eq(data, null, "[0, 300]: north of grid");
// get tile data for [400, 0] (east of grid)
data = layer.getTileData({lon: 400, lat: 0})
t.eq(data, null, "[400, 0]: east of grid");
// get tile data for [0, -500] (south of grid)
data = layer.getTileData({lon: 0, lat: -500})
t.eq(data, null, "[0, -500]: south of grid");
// get tile data for [-200, 0] (west of grid)
data = layer.getTileData({lon: -200, lat: 0})
t.eq(data, null, "[-200, 0]: west of grid");
map.destroy();
}
function test_getGridData_wrapped(t) {
t.plan(18);
var layer = new OpenLayers.Layer.Grid(null, null, null, {
isBaseLayer: true, getURL: function() {
return "/bogus/path/to/tile";
},
wrapDateLine: true
});
var map = new OpenLayers.Map({
div: "map",
layers: [layer],
controls: [],
center: [-50, 0],
zoom: 1
});
// get tile data for [0, 0]
var data = layer.getTileData({lon: 0, lat: 0});
t.ok(data && data.tile, "[0, 0]: got tile data");
t.eq(data.i, 0, "[0, 0]: i");
t.eq(data.j, 128, "[0, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[0, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [-110, 45]
data = layer.getTileData({lon: -110, lat: 45});
t.ok(data && data.tile, "[-110, 45]: got tile data");
t.eq(data.i, 99, "[-110, 45]: i");
t.eq(data.j, 64, "[-110, 45]: j");
t.ok(
data.tile.bounds.equals({left: -180, bottom: -90, right: 0, top: 90}),
"[-110, 45]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, 300] (north of grid)
data = layer.getTileData({lon: 0, lat: 300})
t.eq(data, null, "[0, 300]: north of grid");
// get tile data for [400, 0] (equivalent to [40, 0] and visible on map)
data = layer.getTileData({lon: 400, lat: 0})
t.ok(data && data.tile, "[400, 0]: got tile data");
t.eq(data.i, 56, "[400, 0]: i");
t.eq(data.j, 128, "[400, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[400, 0]: tile bounds " + data.tile.bounds.toString()
);
// get tile data for [0, -500] (south of grid)
data = layer.getTileData({lon: 0, lat: -500})
t.eq(data, null, "[0, -500]: south of grid");
// get tile data for [-200, 0] (equivalent to [160, 0] and wrapped to west side map)
data = layer.getTileData({lon: -200, lat: 0})
t.ok(data && data.tile, "[-200, 0]: got tile data");
t.eq(data.i, 227, "[-200, 0]: i");
t.eq(data.j, 128, "[-200, 0]: j");
t.ok(
data.tile.bounds.equals({left: 0, bottom: -90, right: 180, top: 90}),
"[-200, 0]: tile bounds " + data.tile.bounds.toString()
);
map.destroy();
}
</script>
</head>
<body>
+115
View File
@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning). The panTo tests
* here will test the fallback setTimeout implementation for animation.
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, layer;
function setUp() {
layer = new OpenLayers.Layer.UTFGrid({
url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json",
isBaseLayer: true,
utfgridResolution: 4
});
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
layers: [layer],
center: [0, 0],
zoom: 1
});
}
function tearDown() {
map.destroy();
map = null;
layer = null;
}
function test_constructor(t) {
t.plan(4);
var layer = new OpenLayers.Layer.UTFGrid({
name: "foo",
url: "path/to/tiles/${z}/${x}/${y}",
utfgridResolution: 8
});
t.ok(layer instanceof OpenLayers.Layer.UTFGrid, "utfgrid instance");
t.eq(layer.name, "foo", "layer name");
t.eq(layer.url, "path/to/tiles/${z}/${x}/${y}", "layer url");
t.eq(layer.utfgridResolution, 8, "layer utfgridResolution");
layer.destroy();
}
function test_clone(t) {
t.plan(3);
setUp();
var clone = layer.clone();
t.ok(layer instanceof OpenLayers.Layer.UTFGrid, "utfgrid instance");
t.eq(layer.url, "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json", "layer url");
t.eq(layer.utfgridResolution, 4, "layer utfgridResolution");
clone.destroy();
tearDown();
}
function test_getFeatureInfo(t) {
t.plan(2);
setUp();
// wait for tile loading to finish
t.delay_call(0.5, function() {
var loc = new OpenLayers.LonLat(-110, 45).transform("EPSG:4326", "EPSG:900913");
var info = layer.getFeatureInfo(loc);
t.eq(info.id, "207", "feature id");
t.eq(info.data, {POP2005: 299846449, NAME: "United States"}, "feature data");
tearDown();
});
}
function test_getFeatureId(t) {
t.plan(2);
setUp();
// wait for tile loading to finish
t.delay_call(0.5, function() {
var ca = new OpenLayers.LonLat(-110, 55).transform("EPSG:4326", "EPSG:900913");
var ru = new OpenLayers.LonLat(90, 75).transform("EPSG:4326", "EPSG:900913");
t.eq(layer.getFeatureId(ca), "24", "feature id for ca");
t.eq(layer.getFeatureId(ru), "245", "feature id for ru");
tearDown();
});
}
</script>
</head>
<body>
<div id="map" style="height: 256px; width: 512px"></div>
</body>
</html>