Merge pull request #274 from tschaub/utfgrid
UTFGrid Tile, Layer, and Control. This adds support for responsive handling of interactions with large numbers of features represented by UTFGrids.
This commit is contained in:
119
tests/Control/UTFGrid.html
Normal file
119
tests/Control/UTFGrid.html
Normal file
@@ -0,0 +1,119 @@
|
||||
<!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, control;
|
||||
var log;
|
||||
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
|
||||
});
|
||||
log = [];
|
||||
control = new OpenLayers.Control.UTFGrid({
|
||||
callback: function(infoLookup, loc, pixel) {
|
||||
log.push([infoLookup, loc, pixel]);
|
||||
}
|
||||
});
|
||||
map.addControl(control);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
map.destroy();
|
||||
map = null;
|
||||
layer = null;
|
||||
control = null;
|
||||
log = [];
|
||||
}
|
||||
|
||||
function test_constructor(t) {
|
||||
t.plan(2);
|
||||
|
||||
var control = new OpenLayers.Control.UTFGrid();
|
||||
t.ok(control instanceof OpenLayers.Control.UTFGrid, "utfgrid instance");
|
||||
t.eq(control.handlerMode, "click", "control mode");
|
||||
|
||||
control.destroy();
|
||||
|
||||
}
|
||||
|
||||
function test_handleEvent(t) {
|
||||
setUp();
|
||||
|
||||
var cases = [{
|
||||
evt: {xy: {x: 100, y: 70}},
|
||||
lookup: {
|
||||
"0": {
|
||||
id: "207",
|
||||
data: {
|
||||
NAME: "United States",
|
||||
POP2005: 299846449
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
evt: {xy: {x: 350, y: 20}},
|
||||
lookup: {
|
||||
"0": {
|
||||
id: "245",
|
||||
data: {
|
||||
NAME: "Russia",
|
||||
POP2005: 143953092
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
var len = cases.length;
|
||||
t.plan(4*len);
|
||||
|
||||
// wait for tile loading to finish
|
||||
t.delay_call(0.5, function() {
|
||||
var c, arg;
|
||||
for (var i=0; i<len; ++i) {
|
||||
c = cases[i];
|
||||
t.eq(log.length, i, i + ": log length before");
|
||||
control.handleEvent(c.evt);
|
||||
t.eq(log.length, i+1, i + ": log length after");
|
||||
t.eq(log[i][0], c.lookup, i + ": callback infoLookup");
|
||||
t.eq(log[i][2], c.evt.xy, i + ": callback pixel");
|
||||
}
|
||||
|
||||
tearDown();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="height: 256px; width: 512px"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1366,6 +1366,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
tests/Layer/UTFGrid.html
Normal file
115
tests/Layer/UTFGrid.html
Normal 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>
|
||||
|
||||
305
tests/Tile/UTFGrid.html
Normal file
305
tests/Tile/UTFGrid.html
Normal file
@@ -0,0 +1,305 @@
|
||||
<!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(7);
|
||||
|
||||
setUp();
|
||||
|
||||
var position = new OpenLayers.Pixel(20, 30);
|
||||
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
|
||||
var url = "http://example.com/";
|
||||
var size = new OpenLayers.Size(5, 6);
|
||||
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
|
||||
|
||||
t.ok(tile instanceof OpenLayers.Tile, "tile instance");
|
||||
t.ok(tile instanceof OpenLayers.Tile.UTFGrid, "UTFGrid tile instance");
|
||||
t.ok(tile.layer === layer, "layer set");
|
||||
t.ok(tile.position.equals(position), "position set");
|
||||
t.ok(tile.bounds.equals(bounds), "bounds set");
|
||||
t.eq(tile.url, url, "url set");
|
||||
t.ok(tile.size.equals(size), "size set");
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
function test_parseData(t) {
|
||||
t.plan(2);
|
||||
setUp();
|
||||
|
||||
var tile = layer.grid[0][0];
|
||||
|
||||
tile.parseData('{"foo": "bar"}');
|
||||
t.eq(tile.json, {foo: "bar"}, "valid json parsed");
|
||||
|
||||
var err, obj;
|
||||
try {
|
||||
obj = tile.parseData('foo bar');
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
// The JSON format doesn't actually throw on IE6, so we also check
|
||||
// for undefined here.
|
||||
t.ok(err instanceof Error || obj === undefined, "throws on invalid json");
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
function test_draw(t) {
|
||||
t.plan(7);
|
||||
setUp();
|
||||
|
||||
var position = new OpenLayers.Pixel(20, 30);
|
||||
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
|
||||
var url = "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json";
|
||||
var size = new OpenLayers.Size(256, 256);
|
||||
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
|
||||
|
||||
var log = [];
|
||||
function logger(event) {
|
||||
log.push(event);
|
||||
}
|
||||
tile.events.on({
|
||||
loadstart: logger,
|
||||
reload: logger,
|
||||
loadend: logger
|
||||
});
|
||||
|
||||
t.eq(log.length, 0, "no events logged");
|
||||
|
||||
// start tile loading
|
||||
tile.draw();
|
||||
t.eq(log.length, 1, "[first draw] one event");
|
||||
t.eq(log[0].type, "loadstart", "[first draw] loadstart");
|
||||
|
||||
// restart tile loading
|
||||
log.length = 0;
|
||||
tile.draw();
|
||||
t.eq(log.length, 1, "[second draw] first event");
|
||||
t.eq(log[0].type, "reload", "[second draw] reload");
|
||||
|
||||
// wait for tile loading to finish
|
||||
t.delay_call(1, function() {
|
||||
t.eq(log.length, 2, "[second draw] second event");
|
||||
t.eq(log[1].type, "loadend", "[second draw] loadend");
|
||||
tearDown();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function test_abortLoading(t) {
|
||||
t.plan(7);
|
||||
setUp();
|
||||
|
||||
var position = new OpenLayers.Pixel(20, 30);
|
||||
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
|
||||
var url = "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json";
|
||||
var size = new OpenLayers.Size(256, 256);
|
||||
var tile = new OpenLayers.Tile.UTFGrid(layer, position, bounds, url, size);
|
||||
|
||||
var log = [];
|
||||
function logger(event) {
|
||||
log.push(event);
|
||||
}
|
||||
tile.events.on({
|
||||
loadstart: logger,
|
||||
reload: logger,
|
||||
loadend: logger
|
||||
});
|
||||
|
||||
t.eq(log.length, 0, "no events logged");
|
||||
|
||||
// start tile loading
|
||||
tile.draw();
|
||||
t.eq(log.length, 1, "[first draw] one event");
|
||||
t.eq(log[0].type, "loadstart", "[first draw] loadstart");
|
||||
|
||||
// abort tile loading
|
||||
log.length = 0;
|
||||
tile.abortLoading();
|
||||
t.eq(log.length, 0, "[first abort] no events logged"); // TODO: does anybody need an abort event?
|
||||
|
||||
// abort again for the heck of it
|
||||
var err;
|
||||
try {
|
||||
tile.abortLoading();
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
t.ok(!err, "[second abort] no trouble");
|
||||
t.eq(log.length, 0, "[second abort] no events");
|
||||
|
||||
// wait to confirm tile loading doesn't happen after abort
|
||||
t.delay_call(1, function() {
|
||||
t.eq(log.length, 0, "[wait] no events");
|
||||
tearDown();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function test_getFeatureId(t) {
|
||||
t.plan(3);
|
||||
setUp();
|
||||
|
||||
var tile = layer.grid[1][1];
|
||||
t.delay_call(0.5, function() {
|
||||
var id = tile.getFeatureId(16, 60);
|
||||
t.eq(id, "238", "feature 238 at 16, 60");
|
||||
t.eq(tile.getFeatureId(18, 63), id, "same feature at 18, 63");
|
||||
|
||||
t.eq(tile.getFeatureId(300, 10), null, "null id outside tile");
|
||||
|
||||
tearDown();
|
||||
});
|
||||
}
|
||||
|
||||
function test_getFeatureInfo(t) {
|
||||
t.plan(3);
|
||||
setUp();
|
||||
|
||||
var tile = layer.grid[1][1];
|
||||
t.delay_call(0.5, function() {
|
||||
var info = tile.getFeatureInfo(16, 60);
|
||||
var exp = {
|
||||
id: "238",
|
||||
data: {
|
||||
NAME: "Svalbard",
|
||||
POP2005: 0
|
||||
}
|
||||
};
|
||||
t.eq(info, exp, "feature info at 16, 60");
|
||||
t.eq(tile.getFeatureInfo(17, 62), exp, "same feature at 17, 62");
|
||||
|
||||
t.eq(tile.getFeatureInfo(300, 10), null, "undefined outside tile");
|
||||
|
||||
tearDown();
|
||||
});
|
||||
}
|
||||
|
||||
// While I dislike committing tests that aren't run, I'd like to make an
|
||||
// exception here. This test (or something like it) should pass. When
|
||||
// https://github.com/mapbox/utfgrid-spec/issues/1 is resolved, we should
|
||||
// either modify this or update demo.json and enable the test.
|
||||
function xtest_getFeatureId_demo(t) {
|
||||
/**
|
||||
* The UTFGrid 1.2 spec (https://github.com/mapbox/utfgrid-spec/blob/master/1.2/utfgrid.md)
|
||||
* links to a demo.json to be used for testing implementations. This
|
||||
* file is constructed with 256x256 data points. Each data point maps
|
||||
* to a "feature id" using this heuristic:
|
||||
*
|
||||
* // x and y are pixel offsets from top left of 256x256 tile
|
||||
* if (y < 255 || x < 222) {
|
||||
* id = (y * 256) + x
|
||||
* } else {
|
||||
* id = 65501; // max number of ids that can be encoded
|
||||
* }
|
||||
*/
|
||||
t.plan(1);
|
||||
setUp();
|
||||
|
||||
// look at this beauty of a constructor
|
||||
var tile = new OpenLayers.Tile.UTFGrid(
|
||||
layer, // layer
|
||||
new OpenLayers.Pixel(0, 0), // position
|
||||
new OpenLayers.Bounds(0, 0, 256, 256), // bounds
|
||||
"../data/utfgrid/demo-1.1.json", // url
|
||||
new OpenLayers.Size(256, 256), // size
|
||||
{utfgridResolution: 1} // options
|
||||
);
|
||||
|
||||
var err;
|
||||
var request = new OpenLayers.Request.GET({
|
||||
url: tile.url,
|
||||
success: function(req) {
|
||||
try {
|
||||
tile.parseData(req.responseText);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
},
|
||||
failure: function(req) {
|
||||
err = new Error("Failed to fetch json. Status: " + req.status);
|
||||
}
|
||||
});
|
||||
|
||||
// wait for response and parsing, then make assertions
|
||||
t.delay_call(1, function() {
|
||||
if (err) {
|
||||
t.fail(err);
|
||||
} else {
|
||||
var got, exp, failure;
|
||||
outer: for (var y=0; y<256; ++y) {
|
||||
for (var x=0; x<256; ++x) {
|
||||
if (y<255 || x<222) {
|
||||
exp = String((y * 256) + x);
|
||||
} else {
|
||||
exp = "65501";
|
||||
}
|
||||
got = tile.getFeatureId(x, y);
|
||||
if (got !== exp) {
|
||||
failure = "Failed to get id for (" + x + ", " + y + "): " +
|
||||
"got " + got + " but expected " + exp;
|
||||
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!failure) {
|
||||
t.ok(true, "resolved feature ids for all data points");
|
||||
} else {
|
||||
t.fail(failure);
|
||||
}
|
||||
}
|
||||
tearDown();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="height:550px;width:500px"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1
tests/data/utfgrid/bio_utfgrid/1/0/0.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/0/0.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/bio_utfgrid/1/0/1.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/0/1.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/bio_utfgrid/1/0/2.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/0/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/bio_utfgrid/1/1/0.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/1/0.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/bio_utfgrid/1/1/1.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/1/1.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/bio_utfgrid/1/1/2.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/1/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/bio_utfgrid/1/2/0.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/2/0.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/bio_utfgrid/1/2/1.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/2/1.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/bio_utfgrid/1/2/2.json
Normal file
1
tests/data/utfgrid/bio_utfgrid/1/2/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/demo-1.1.json
Normal file
1
tests/data/utfgrid/demo-1.1.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/world_utfgrid/1/0/0.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/0/0.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/world_utfgrid/1/0/1.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/0/1.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/world_utfgrid/1/0/2.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/0/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/world_utfgrid/1/1/0.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/1/0.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/world_utfgrid/1/1/1.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/1/1.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/data/utfgrid/world_utfgrid/1/1/2.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/1/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/world_utfgrid/1/2/0.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/2/0.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/world_utfgrid/1/2/1.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/2/1.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
1
tests/data/utfgrid/world_utfgrid/1/2/2.json
Normal file
1
tests/data/utfgrid/world_utfgrid/1/2/2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"keys": [""], "data": {}, "grid": [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]}
|
||||
@@ -41,6 +41,7 @@
|
||||
<li>Control/Split.html</li>
|
||||
<li>Control/TouchNavigation.html</li>
|
||||
<li>Control/TransformFeature.html</li>
|
||||
<li>Control/UTFGrid.html</li>
|
||||
<li>Control/WMSGetFeatureInfo.html</li>
|
||||
<li>Control/WMTSGetFeatureInfo.html</li>
|
||||
<li>Control/PanPanel.html</li>
|
||||
@@ -165,6 +166,7 @@
|
||||
<li>Layer/Text.html</li>
|
||||
<li>Layer/TileCache.html</li>
|
||||
<li>Layer/TMS.html</li>
|
||||
<li>Layer/UTFGrid.html</li>
|
||||
<li>Layer/Vector.html</li>
|
||||
<li>Layer/Vector/RootContainer.html</li>
|
||||
<li>Layer/WMS.html</li>
|
||||
@@ -220,6 +222,7 @@
|
||||
<li>Tile.html</li>
|
||||
<li>Tile/Image.html</li>
|
||||
<li>Tile/Image/IFrame.html</li>
|
||||
<li>Tile/UTFGrid.html</li>
|
||||
<li>Tween.html</li>
|
||||
<li>Kinetic.html</li>
|
||||
<li>Util.html</li>
|
||||
|
||||
Reference in New Issue
Block a user