From 0d6c54847bb6d3556455dd57c6016a9d5ffac74b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 18 Feb 2013 15:55:27 -0700 Subject: [PATCH] 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). --- src/ol/tilegrid/tilegrid.js | 24 +------- test/spec/ol/tilegrid.test.js | 100 ---------------------------------- 2 files changed, 3 insertions(+), 121 deletions(-) diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 58dfaacfda..ba9e6ff441 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -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); }; diff --git a/test/spec/ol/tilegrid.test.js b/test/spec/ol/tilegrid.test.js index bcaba344f6..63451a1668 100644 --- a/test/spec/ol/tilegrid.test.js +++ b/test/spec/ol/tilegrid.test.js @@ -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({