Removing logic that assumes occasionally stretched tiles

When the dom renderer included logic to stretch tiles so that gaps were properly filled for fractional zoom levels, we needed to take this into account when getting a tile coordinate for a given coordinate and resolution.  This was never the proper logic for a renderer that wasn't stretching occassional tiles (e.g. the WebGL renderer, the Canvas renderer, or the new DOM renderer).
This commit is contained in:
Tim Schaub
2013-02-18 15:55:27 -07:00
parent 4c2463dd91
commit 0d6c54847b
2 changed files with 3 additions and 121 deletions

View File

@@ -251,28 +251,10 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
tileSize = new ol.Size(tileSize.width / scale,
tileSize.height / scale);
var x, y;
x = Math.floor(offsetFromOrigin.x / tileSize.width);
y = Math.floor(offsetFromOrigin.y / tileSize.height);
var x = Math.floor(offsetFromOrigin.x / tileSize.width);
var y = Math.floor(offsetFromOrigin.y / tileSize.height);
var tileCoord = new ol.TileCoord(z, x, y);
var tileCoordPixelBounds = this.getPixelBoundsForTileCoordAndResolution(
tileCoord, resolution);
// adjust x to allow for stretched tiles
if (offsetFromOrigin.x < tileCoordPixelBounds.minX) {
tileCoord.x -= 1;
} else if (offsetFromOrigin.x >= tileCoordPixelBounds.maxX) {
tileCoord.x += 1;
}
// adjust y to allow for stretched tiles
if (offsetFromOrigin.y < tileCoordPixelBounds.minY) {
tileCoord.y -= 1;
} else if (offsetFromOrigin.y >= tileCoordPixelBounds.maxY) {
tileCoord.y += 1;
}
return tileCoord;
return new ol.TileCoord(z, x, y);
};

View File

@@ -258,106 +258,6 @@ describe('ol.tilegrid.TileGrid', function() {
});
});
describe('getTileCoordForCoordAndResolution fractional', function() {
it('returns the expected TileCoord', function() {
var tileSize = new ol.Size(256, 256);
var tileGrid = new ol.tilegrid.TileGrid({
resolutions: [1 / 3],
extent: extent,
origin: origin,
tileSize: tileSize
});
var coordinate;
var tileCoord;
// 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.)
// gets the first tile at the origin
coordinate = new ol.Coordinate(0, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(0);
expect(tileCoord.y).toEqual(0);
// gets the 1,0 tile at 256/3,0
coordinate = new ol.Coordinate(256 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(1);
expect(tileCoord.y).toEqual(0);
// still gets the 1,0 tile at 512/3,0 - wider tile
coordinate = new ol.Coordinate(512 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(1);
expect(tileCoord.y).toEqual(0);
// gets the 2,0 tile at 513/3,0
coordinate = new ol.Coordinate(513 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(2);
expect(tileCoord.y).toEqual(0);
// gets the 3,0 tile at 768/3,0
coordinate = new ol.Coordinate(768 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(3);
expect(tileCoord.y).toEqual(0);
// gets the 4,0 tile at 1024/3,0
coordinate = new ol.Coordinate(1024 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(4);
expect(tileCoord.y).toEqual(0);
// still gets the 4,0 tile at 1280/3,0 - wider tile
coordinate = new ol.Coordinate(1280 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(4);
expect(tileCoord.y).toEqual(0);
// gets the 5,0 tile at 1281/3,0
coordinate = new ol.Coordinate(1281 / 3, 0);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(5);
expect(tileCoord.y).toEqual(0);
// gets the 0,1 tile at 0,-256/3
coordinate = new ol.Coordinate(0, -256 / 3);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(0);
expect(tileCoord.y).toEqual(-2);
// still gets the 0,1 tile at 0,-512/3 - taller tile
coordinate = new ol.Coordinate(0, -512 / 3);
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
coordinate, 1);
expect(tileCoord.z).toEqual(0);
expect(tileCoord.x).toEqual(0);
expect(tileCoord.y).toEqual(-2);
});
});
describe('getTileCoordCenter', function() {
it('returns the expected center', function() {
var tileGrid = new ol.tilegrid.TileGrid({