Specs for getting tile coords.

This commit is contained in:
Tim Schaub
2012-07-09 01:04:01 -06:00
parent 7f594364ca
commit 1dd2512765

View File

@@ -73,6 +73,156 @@ describe("ol.renderer.TileLayerRenderer", function() {
});
describe("getNormalizedTileCoord_", function() {
var container = document.createElement("div");
function str(coord) {
return coord.x + "," + coord.y;
}
describe("simple cases", function() {
var layer = new ol.layer.TileLayer();
layer.setResolutions([10]);
layer.setTileOrigin(0, 0);
var renderer = new ol.renderer.TileLayerRenderer(container, layer);
var loc, coord;
it("gets the first tile at the origin", function() {
loc = new ol.Loc(0, 0);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,0");
});
it("gets one tile northwest of the origin", function() {
loc = new ol.Loc(-1280, 1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("-1,-1");
});
it("gets one tile northeast of the origin", function() {
loc = new ol.Loc(1280, 1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,-1");
});
it("gets one tile southeast of the origin", function() {
loc = new ol.Loc(1280, -1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,0");
});
it("gets one tile southwest of the origin", function() {
loc = new ol.Loc(-1280, -1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("-1,0");
});
it("gets the tile to the east when on the edge", function() {
loc = new ol.Loc(2560, -1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("1,0");
});
it("gets the tile to the south when on the edge", function() {
loc = new ol.Loc(1280, -2560);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,1");
});
it("pixels are top aligned to the origin", function() {
loc = new ol.Loc(1280, -2559.999);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,0");
});
it("pixels are left aligned to the origin", function() {
loc = new ol.Loc(2559.999, -1280);
coord = renderer.getNormalizedTileCoord_(loc, 10);
expect(str(coord)).toBe("0,0");
});
});
describe("fractional zoom", function() {
var layer = new ol.layer.TileLayer();
layer.setResolutions([1/3]);
layer.setTileOrigin(0, 0);
var renderer = new ol.renderer.TileLayerRenderer(container, layer);
var loc, coord;
/**
These tests render at a resolution of 1. Because the layer's
closest resolution is 1/3, the images are scaled by 1/3.
In this scenario, every third tile will be one pixel wider when
rendered (0,0 is normal; 1,0 is wider; 0,1 is taller; etc.)
*/
it("gets the first tile at the origin", function() {
loc = new ol.Loc(0, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("0,0");
});
it("gets the 1,0 tile at 256/3,0", function() {
loc = new ol.Loc(256/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("1,0");
});
it("still gets the 1,0 tile at 512/3,0 - wider tile", function() {
loc = new ol.Loc(512/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("1,0");
});
it("gets the 2,0 tile at 513/3,0", function() {
loc = new ol.Loc(513/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("2,0");
});
it("gets the 3,0 tile at 768/3,0", function() {
loc = new ol.Loc(768/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("3,0");
});
it("gets the 4,0 tile at 1024/3,0", function() {
loc = new ol.Loc(1024/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("4,0");
});
it("still gets the 4,0 tile at 1280/3,0 - wider tile", function() {
loc = new ol.Loc(1280/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("4,0");
});
it("gets the 5,0 tile at 1281/3,0", function() {
loc = new ol.Loc(1281/3, 0);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("5,0");
});
it("gets the 0,1 tile at 0,-256/3", function() {
loc = new ol.Loc(0,-256/3);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("0,1");
});
it("still gets the 0,1 tile at 0,-512/3 - taller tile", function() {
loc = new ol.Loc(0,-512/3);
coord = renderer.getNormalizedTileCoord_(loc, 1);
expect(str(coord)).toBe("0,1");
});
});
});
});