From 5771057ae18d2fc5c49ea750a427331c447637a6 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 24 Mar 2013 13:46:23 +0100 Subject: [PATCH 1/8] Reuse ol.TileRange object in forEachTileCoordParentTileRange --- src/ol/tilegrid/xyztilegrid.js | 17 +++++------------ src/ol/tilerange.js | 8 ++++++++ test/spec/ol/source/xyz.test.js | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ol/tilegrid/xyztilegrid.js b/src/ol/tilegrid/xyztilegrid.js index 25270ec0eb..985bf67001 100644 --- a/src/ol/tilegrid/xyztilegrid.js +++ b/src/ol/tilegrid/xyztilegrid.js @@ -39,18 +39,11 @@ goog.inherits(ol.tilegrid.XYZ, ol.tilegrid.TileGrid); */ ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange = function(tileCoord, callback, opt_obj) { - var x = tileCoord.x; - var y = tileCoord.y; - var z = tileCoord.z; - var tileRange; - while (true) { - z -= 1; - if (z < 0) { - break; - } - x >>= 1; - y >>= 1; - tileRange = new ol.TileRange(x, y, x, y); + var tileRange = new ol.TileRange(0, 0, tileCoord.x, tileCoord.y); + var z; + for (z = tileCoord.z - 1; z >= 0; --z) { + tileRange.minX = tileRange.maxX >>= 1; + tileRange.minY = tileRange.maxY >>= 1; if (callback.call(opt_obj, z, tileRange)) { break; } diff --git a/src/ol/tilerange.js b/src/ol/tilerange.js index 76d3d7437c..ad788a7736 100644 --- a/src/ol/tilerange.js +++ b/src/ol/tilerange.js @@ -64,6 +64,14 @@ ol.TileRange.boundingTileRange = function(var_args) { }; +/** + * @return {ol.TileRange} Clone. + */ +ol.TileRange.prototype.clone = function() { + return new ol.TileRange(this.minX, this.minY, this.maxX, this.maxY); +}; + + /** * @param {ol.TileCoord} tileCoord Tile coordinate. * @return {boolean} Contains tile coordinate. diff --git a/test/spec/ol/source/xyz.test.js b/test/spec/ol/source/xyz.test.js index fd7560f566..5b143beb0d 100644 --- a/test/spec/ol/source/xyz.test.js +++ b/test/spec/ol/source/xyz.test.js @@ -86,7 +86,7 @@ describe('ol.source.XYZ', function() { tileCoord, function(z, tileRange) { zs.push(z); - tileRanges.push(tileRange); + tileRanges.push(tileRange.clone()); return false; }); From e023e6fa2fb4ded375a2bb93bb1e67ff75ef26d2 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 24 Mar 2013 13:49:47 +0100 Subject: [PATCH 2/8] Avoid creating extra ol.Size object in getPixelBoundsForTileCoordAndResolution --- src/ol/tilegrid/tilegrid.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 182b5d7dd3..b2dfed3ae8 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -137,13 +137,12 @@ ol.tilegrid.TileGrid.prototype.getPixelBoundsForTileCoordAndResolution = function(tileCoord, resolution) { var scale = resolution / this.getResolution(tileCoord.z); var tileSize = this.getTileSize(tileCoord.z); - tileSize = new ol.Size(tileSize.width / scale, - tileSize.height / scale); - var minX, maxX, minY, maxY; - minX = Math.round(tileCoord.x * tileSize.width); - maxX = Math.round((tileCoord.x + 1) * tileSize.width); - minY = Math.round(tileCoord.y * tileSize.height); - maxY = Math.round((tileCoord.y + 1) * tileSize.height); + var tileWidth = tileSize.width / scale; + var tileHeight = tileSize.height / scale; + var minX = Math.round(tileCoord.x * tileWidth); + var minY = Math.round(tileCoord.y * tileHeight); + var maxX = Math.round((tileCoord.x + 1) * tileWidth); + var maxY = Math.round((tileCoord.y + 1) * tileHeight); return new ol.PixelBounds(minX, minY, maxX, maxY); }; From aeeaa79393f0e0b1ecf50e4587116c88de7b7706 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 24 Mar 2013 13:56:23 +0100 Subject: [PATCH 3/8] Avoid creating ol.Coordinate objects to call getTileCoordForCoordAndResolution_ --- src/ol/tilegrid/tilegrid.js | 35 ++++++++++++++------------ test/spec/ol/tilegrid/tilegrid.test.js | 24 +++++++----------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index b2dfed3ae8..5438b90be0 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -189,10 +189,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) { */ ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function( extent, resolution) { - var min = this.getTileCoordForCoordAndResolution_( - new ol.Coordinate(extent.minX, extent.minY), resolution); - var max = this.getTileCoordForCoordAndResolution_( - new ol.Coordinate(extent.maxX, extent.maxY), resolution, true); + var min = this.getTileCoordForXYAndResolution_( + extent.minX, extent.minY, resolution); + var max = this.getTileCoordForXYAndResolution_( + extent.maxX, extent.maxY, resolution, true); return new ol.TileRange(min.x, min.y, max.x, max.y); }; @@ -249,12 +249,14 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) { */ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function( coordinate, resolution) { - return this.getTileCoordForCoordAndResolution_(coordinate, resolution); + return this.getTileCoordForXYAndResolution_( + coordinate.x, coordinate.y, resolution); }; /** - * @param {ol.Coordinate} coordinate Coordinate. + * @param {number} x X. + * @param {number} y Y. * @param {number} resolution Resolution. * @param {boolean=} opt_reverseIntersectionPolicy Instead of letting edge * intersections go to the higher tile coordinate, let edge intersections @@ -262,25 +264,25 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function( * @return {ol.TileCoord} Tile coordinate. * @private */ -ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function( - coordinate, resolution, opt_reverseIntersectionPolicy) { +ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function( + x, y, resolution, opt_reverseIntersectionPolicy) { var z = this.getZForResolution(resolution); var scale = resolution / this.getResolution(z); var origin = this.getOrigin(z); var tileSize = this.getTileSize(z); - var x = scale * (coordinate.x - origin.x) / (resolution * tileSize.width); - var y = scale * (coordinate.y - origin.y) / (resolution * tileSize.height); + var tileCoordX = scale * (x - origin.x) / (resolution * tileSize.width); + var tileCoordY = scale * (y - origin.y) / (resolution * tileSize.height); if (!opt_reverseIntersectionPolicy) { - x = Math.floor(x); - y = Math.floor(y); + tileCoordX = Math.floor(tileCoordX); + tileCoordY = Math.floor(tileCoordY); } else { - x = Math.ceil(x) - 1; - y = Math.ceil(y) - 1; + tileCoordX = Math.ceil(tileCoordX) - 1; + tileCoordY = Math.ceil(tileCoordY) - 1; } - return new ol.TileCoord(z, x, y); + return new ol.TileCoord(z, tileCoordX, tileCoordY); }; @@ -292,7 +294,8 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function( ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z) { var resolution = this.getResolution(z); - return this.getTileCoordForCoordAndResolution_(coordinate, resolution); + return this.getTileCoordForXYAndResolution_( + coordinate.x, coordinate.y, resolution); }; diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index 507b170a8d..00ff0f8ce9 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -379,7 +379,7 @@ describe('ol.tilegrid.TileGrid', function() { }); - describe('getTileCoordForCoordAndResolution_', function() { + describe('getTileCoordForXYAndResolution_', function() { it('returns higher tile coord for intersections by default', function() { var tileGrid = new ol.tilegrid.TileGrid({ resolutions: resolutions, @@ -388,21 +388,18 @@ describe('ol.tilegrid.TileGrid', function() { tileSize: tileSize }); - var coordinate; var tileCoord; // gets higher tile for edge intersection - coordinate = new ol.Coordinate(0, 0); - tileCoord = tileGrid.getTileCoordForCoordAndResolution_( - coordinate, 100); + tileCoord = tileGrid.getTileCoordForXYAndResolution_( + 0, 0, 100); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(0); expect(tileCoord.y).to.eql(0); // gets higher tile for edge intersection - coordinate = new ol.Coordinate(100000, 100000); - tileCoord = tileGrid.getTileCoordForCoordAndResolution_( - coordinate, 100); + tileCoord = tileGrid.getTileCoordForXYAndResolution_( + 100000, 100000, 100); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(10); expect(tileCoord.y).to.eql(10); @@ -417,21 +414,18 @@ describe('ol.tilegrid.TileGrid', function() { tileSize: tileSize }); - var coordinate; var tileCoord; // can get lower tile for edge intersection - coordinate = new ol.Coordinate(0, 0); - tileCoord = tileGrid.getTileCoordForCoordAndResolution_( - coordinate, 100, true); + tileCoord = tileGrid.getTileCoordForXYAndResolution_( + 0, 0, 100, true); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(-1); expect(tileCoord.y).to.eql(-1); // gets higher tile for edge intersection - coordinate = new ol.Coordinate(100000, 100000); - tileCoord = tileGrid.getTileCoordForCoordAndResolution_( - coordinate, 100, true); + tileCoord = tileGrid.getTileCoordForXYAndResolution_( + 100000, 100000, 100, true); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(9); expect(tileCoord.y).to.eql(9); From 247fc8f031c76efb39f32ee3a5ad25e2d8879f8b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 24 Mar 2013 13:59:35 +0100 Subject: [PATCH 4/8] Make reverseIntersection argument mandatory --- src/ol/tilegrid/tilegrid.js | 18 +++++++++--------- test/spec/ol/tilegrid/tilegrid.test.js | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 5438b90be0..0c1d0fbbb2 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -190,7 +190,7 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) { ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function( extent, resolution) { var min = this.getTileCoordForXYAndResolution_( - extent.minX, extent.minY, resolution); + extent.minX, extent.minY, resolution, false); var max = this.getTileCoordForXYAndResolution_( extent.maxX, extent.maxY, resolution, true); return new ol.TileRange(min.x, min.y, max.x, max.y); @@ -250,7 +250,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) { ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function( coordinate, resolution) { return this.getTileCoordForXYAndResolution_( - coordinate.x, coordinate.y, resolution); + coordinate.x, coordinate.y, resolution, false); }; @@ -258,14 +258,14 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function( * @param {number} x X. * @param {number} y Y. * @param {number} resolution Resolution. - * @param {boolean=} opt_reverseIntersectionPolicy Instead of letting edge + * @param {boolean} reverseIntersectionPolicy Instead of letting edge * intersections go to the higher tile coordinate, let edge intersections * go to the lower tile coordinate. * @return {ol.TileCoord} Tile coordinate. * @private */ ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function( - x, y, resolution, opt_reverseIntersectionPolicy) { + x, y, resolution, reverseIntersectionPolicy) { var z = this.getZForResolution(resolution); var scale = resolution / this.getResolution(z); var origin = this.getOrigin(z); @@ -274,12 +274,12 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function( var tileCoordX = scale * (x - origin.x) / (resolution * tileSize.width); var tileCoordY = scale * (y - origin.y) / (resolution * tileSize.height); - if (!opt_reverseIntersectionPolicy) { - tileCoordX = Math.floor(tileCoordX); - tileCoordY = Math.floor(tileCoordY); - } else { + if (reverseIntersectionPolicy) { tileCoordX = Math.ceil(tileCoordX) - 1; tileCoordY = Math.ceil(tileCoordY) - 1; + } else { + tileCoordX = Math.floor(tileCoordX); + tileCoordY = Math.floor(tileCoordY); } return new ol.TileCoord(z, tileCoordX, tileCoordY); @@ -295,7 +295,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z) { var resolution = this.getResolution(z); return this.getTileCoordForXYAndResolution_( - coordinate.x, coordinate.y, resolution); + coordinate.x, coordinate.y, resolution, false); }; diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index 00ff0f8ce9..4fe9b1f232 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -392,14 +392,14 @@ describe('ol.tilegrid.TileGrid', function() { // gets higher tile for edge intersection tileCoord = tileGrid.getTileCoordForXYAndResolution_( - 0, 0, 100); + 0, 0, 100, false); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(0); expect(tileCoord.y).to.eql(0); // gets higher tile for edge intersection tileCoord = tileGrid.getTileCoordForXYAndResolution_( - 100000, 100000, 100); + 100000, 100000, 100, false); expect(tileCoord.z).to.eql(3); expect(tileCoord.x).to.eql(10); expect(tileCoord.y).to.eql(10); From dfb631a08ffb150af659613a4575f0f85d8cced9 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 24 Mar 2013 14:51:54 +0100 Subject: [PATCH 5/8] Replace getTile with getTileZXY This massively reduces the number of temporary ol.TileCoord objects. Previously an ol.TileCoord object was generated for every potentially visible tile at the current zoom level and lower, every frame. This commit eliminates all of those. Now new ol.TileCoord objects are only allocated when a new tile is created. --- .../canvas/canvastilelayerrenderer.js | 14 +++---- src/ol/renderer/dom/domtilelayerrenderer.js | 9 ++-- src/ol/renderer/layerrenderer.js | 19 ++++----- .../renderer/webgl/webgltilelayerrenderer.js | 13 +++--- src/ol/source/debugtilesource.js | 12 +++--- src/ol/source/imagetilesource.js | 17 ++++---- src/ol/source/tilesource.js | 23 +++++----- src/ol/tilecoord.js | 13 +++++- test/spec/ol/source/tilesource.test.js | 42 +++++++++---------- 9 files changed, 87 insertions(+), 75 deletions(-) diff --git a/src/ol/renderer/canvas/canvastilelayerrenderer.js b/src/ol/renderer/canvas/canvastilelayerrenderer.js index c2fbb13e9b..365500021a 100644 --- a/src/ol/renderer/canvas/canvastilelayerrenderer.js +++ b/src/ol/renderer/canvas/canvastilelayerrenderer.js @@ -155,22 +155,21 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame = tilesToDrawByZ, getTileIfLoaded); var allTilesLoaded = true; - var tile, tileCoord, tileState, x, y; + var tile, tileState, x, y; for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tileCoord = new ol.TileCoord(z, x, y); - tile = tileSource.getTile(tileCoord, tileGrid, projection); + tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED || tileState == ol.TileState.EMPTY) { - tilesToDrawByZ[z][tileCoord.toString()] = tile; + tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; continue; } else if (tileState == ol.TileState.ERROR) { continue; } allTilesLoaded = false; - tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); + tileGrid.forEachTileCoordParentTileRange(tile.tileCoord, findLoadedTiles); } } @@ -191,9 +190,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame = if (currentZ == z) { for (tileCoordKey in tilesToDraw) { tile = tilesToDraw[tileCoordKey]; - tileCoord = tile.tileCoord; - index = (tileCoord.y - tileRange.minY) * tileRangeWidth + - (tileCoord.x - tileRange.minX); + index = (tile.tileCoord.y - tileRange.minY) * tileRangeWidth + + (tile.tileCoord.x - tileRange.minX); if (this.renderedTiles_[index] != tile) { x = tileSize.width * (tile.tileCoord.x - tileRange.minX); y = tileSize.height * (tileRange.maxY - tile.tileCoord.y); diff --git a/src/ol/renderer/dom/domtilelayerrenderer.js b/src/ol/renderer/dom/domtilelayerrenderer.js index ba3d1e3be5..832eb96539 100644 --- a/src/ol/renderer/dom/domtilelayerrenderer.js +++ b/src/ol/renderer/dom/domtilelayerrenderer.js @@ -112,15 +112,14 @@ ol.renderer.dom.TileLayer.prototype.renderFrame = tilesToDrawByZ, getTileIfLoaded); var allTilesLoaded = true; - var tile, tileCoord, tileState, x, y; + var tile, tileState, x, y; for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tileCoord = new ol.TileCoord(z, x, y); - tile = tileSource.getTile(tileCoord, tileGrid, projection); + tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED) { - tilesToDrawByZ[z][tileCoord.toString()] = tile; + tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; continue; } else if (tileState == ol.TileState.ERROR || tileState == ol.TileState.EMPTY) { @@ -128,7 +127,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame = } allTilesLoaded = false; - tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); + tileGrid.forEachTileCoordParentTileRange(tile.tileCoord, findLoadedTiles); } diff --git a/src/ol/renderer/layerrenderer.js b/src/ol/renderer/layerrenderer.js index 7e08147cf8..66b4375ec5 100644 --- a/src/ol/renderer/layerrenderer.js +++ b/src/ol/renderer/layerrenderer.js @@ -9,7 +9,6 @@ goog.require('ol.Image'); goog.require('ol.ImageState'); goog.require('ol.Object'); goog.require('ol.Tile'); -goog.require('ol.TileCoord'); goog.require('ol.TileRange'); goog.require('ol.TileState'); goog.require('ol.layer.Layer'); @@ -258,12 +257,13 @@ ol.renderer.Layer.prototype.updateUsedTiles = * @param {ol.source.TileSource} tileSource Tile source. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid. * @param {ol.Projection} projection Projection. - * @return {function(ol.TileCoord): ol.Tile} Returns a tile if it is loaded. + * @return {function(number, number, number): ol.Tile} Returns a tile if it is + * loaded. */ ol.renderer.Layer.prototype.createGetTileIfLoadedFunction = function(isLoadedFunction, tileSource, tileGrid, projection) { - return function(tileCoord) { - var tile = tileSource.getTile(tileCoord, tileGrid, projection); + return function(z, x, y) { + var tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); return isLoadedFunction(tile) ? tile : null; }; }; @@ -307,7 +307,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = } var wantedTiles = frameState.wantedTiles[tileSourceKey]; var tileQueue = frameState.tileQueue; - var tile, tileCenter, tileCoord, tileRange, tileResolution, x, y, z; + var tile, tileCenter, tileRange, tileResolution, x, y, z; // FIXME this should loop up to tileGrid's minZ when implemented for (z = currentZ; z >= 0; --z) { tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z); @@ -315,15 +315,14 @@ ol.renderer.Layer.prototype.manageTilePyramid = for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { if (ol.PREEMPTIVELY_LOAD_LOW_RESOLUTION_TILES || z == currentZ) { - tileCoord = new ol.TileCoord(z, x, y); - tile = tileSource.getTile(tileCoord, tileGrid, projection); + tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); if (tile.getState() == ol.TileState.IDLE) { - tileCenter = tileGrid.getTileCoordCenter(tileCoord); - wantedTiles[tileCoord.toString()] = true; + tileCenter = tileGrid.getTileCoordCenter(tile.tileCoord); + wantedTiles[tile.tileCoord.toString()] = true; tileQueue.enqueue(tile, tileSourceKey, tileCenter, tileResolution); } } else { - tileSource.useTile(z + '/' + x + '/' + y); + tileSource.useTileZXY(z, x, y); } } } diff --git a/src/ol/renderer/webgl/webgltilelayerrenderer.js b/src/ol/renderer/webgl/webgltilelayerrenderer.js index c9b0f69bfb..419eebf909 100644 --- a/src/ol/renderer/webgl/webgltilelayerrenderer.js +++ b/src/ol/renderer/webgl/webgltilelayerrenderer.js @@ -13,7 +13,6 @@ goog.require('goog.webgl'); goog.require('ol.Extent'); goog.require('ol.Size'); goog.require('ol.Tile'); -goog.require('ol.TileCoord'); goog.require('ol.TileRange'); goog.require('ol.TileState'); goog.require('ol.layer.TileLayer'); @@ -264,19 +263,18 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame = var tilesToLoad = new goog.structs.PriorityQueue(); var allTilesLoaded = true; - var deltaX, deltaY, priority, tile, tileCenter, tileCoord, tileState, x, y; + var deltaX, deltaY, priority, tile, tileCenter, tileState, x, y; for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tileCoord = new ol.TileCoord(z, x, y); - tile = tileSource.getTile(tileCoord, tileGrid, projection); + tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED) { if (mapRenderer.isTileTextureLoaded(tile)) { - tilesToDrawByZ[z][tileCoord.toString()] = tile; + tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; continue; } else { - tileCenter = tileGrid.getTileCoordCenter(tileCoord); + tileCenter = tileGrid.getTileCoordCenter(tile.tileCoord); deltaX = tileCenter.x - center.x; deltaY = tileCenter.y - center.y; priority = Math.sqrt(deltaX * deltaX + deltaY * deltaY); @@ -288,7 +286,8 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame = } allTilesLoaded = false; - tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); + tileGrid.forEachTileCoordParentTileRange( + tile.tileCoord, findLoadedTiles); } diff --git a/src/ol/source/debugtilesource.js b/src/ol/source/debugtilesource.js index 5b93fac9e5..24c4f70168 100644 --- a/src/ol/source/debugtilesource.js +++ b/src/ol/source/debugtilesource.js @@ -122,13 +122,13 @@ ol.source.DebugTileSource.prototype.expireCache = function(usedTiles) { /** * @inheritDoc */ -ol.source.DebugTileSource.prototype.getTile = function(tileCoord) { - var key = tileCoord.toString(); - if (this.tileCache_.containsKey(key)) { - return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(key)); +ol.source.DebugTileSource.prototype.getTileZXY = function(z, x, y) { + var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); + if (this.tileCache_.containsKey(tileCoordKey)) { + return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(tileCoordKey)); } else { - var tile = new ol.DebugTile_(tileCoord, this.tileGrid); - this.tileCache_.set(key, tile); + var tile = new ol.DebugTile_(new ol.TileCoord(z, x, y), this.tileGrid); + this.tileCache_.set(tileCoordKey, tile); return tile; } }; diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index bd69af2d87..65732a2402 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -7,6 +7,7 @@ goog.require('ol.ImageTile'); goog.require('ol.Projection'); goog.require('ol.Tile'); goog.require('ol.TileCache'); +goog.require('ol.TileCoord'); goog.require('ol.TileState'); goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunctionType'); @@ -86,21 +87,22 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) { /** * @inheritDoc */ -ol.source.ImageTileSource.prototype.getTile = - function(tileCoord, tileGrid, projection) { - var key = tileCoord.toString(); - if (this.tileCache_.containsKey(key)) { - return /** @type {!ol.Tile} */ (this.tileCache_.get(key)); +ol.source.ImageTileSource.prototype.getTileZXY = + function(z, x, y, tileGrid, projection) { + var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); + if (this.tileCache_.containsKey(tileCoordKey)) { + return /** @type {!ol.Tile} */ (this.tileCache_.get(tileCoordKey)); } else { goog.asserts.assert(tileGrid); goog.asserts.assert(projection); + var tileCoord = new ol.TileCoord(z, x, y); var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection); var tile = new ol.ImageTile( tileCoord, goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY, goog.isDef(tileUrl) ? tileUrl : '', this.crossOrigin_); - this.tileCache_.set(key, tile); + this.tileCache_.set(tileCoordKey, tile); return tile; } }; @@ -109,7 +111,8 @@ ol.source.ImageTileSource.prototype.getTile = /** * @inheritDoc */ -ol.source.ImageTileSource.prototype.useTile = function(tileCoordKey) { +ol.source.ImageTileSource.prototype.useTileZXY = function(z, x, y) { + var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); if (this.tileCache_.containsKey(tileCoordKey)) { this.tileCache_.get(tileCoordKey); } diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index d9dc144248..77b28d66b3 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -72,8 +72,8 @@ ol.source.TileSource.prototype.expireCache = goog.abstractMethod; * * @param {Object.>} loadedTilesByZ A lookup of * loaded tiles by zoom level. - * @param {function(ol.TileCoord): ol.Tile} getTileIfLoaded A function that - * returns the tile only if it is fully loaded. + * @param {function(number, number, number): ol.Tile} getTileIfLoaded A function + * that returns the tile only if it is fully loaded. * @param {number} z Zoom level. * @param {ol.TileRange} tileRange Tile range. * @return {boolean} The tile range is fully covered with loaded tiles. @@ -82,15 +82,14 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ, getTileIfLoaded, z, tileRange) { // FIXME this could be more efficient about filling partial holes var fullyCovered = true; - var tile, tileCoord, tileCoordKey, x, y; + var tile, tileCoordKey, x, y; for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tileCoord = new ol.TileCoord(z, x, y); - tileCoordKey = tileCoord.toString(); + tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) { continue; } - tile = getTileIfLoaded(tileCoord); + tile = getTileIfLoaded(z, x, y); if (!goog.isNull(tile)) { if (!loadedTilesByZ[z]) { loadedTilesByZ[z] = {}; @@ -122,12 +121,14 @@ ol.source.TileSource.prototype.getResolutions = function() { /** - * @param {ol.TileCoord} tileCoord Tile coordinate. + * @param {number} z Tile coordinate z. + * @param {number} x Tile coordinate x. + * @param {number} y Tile coordinate y. * @param {ol.tilegrid.TileGrid=} opt_tileGrid Tile grid. * @param {ol.Projection=} opt_projection Projection. * @return {!ol.Tile} Tile. */ -ol.source.TileSource.prototype.getTile = goog.abstractMethod; +ol.source.TileSource.prototype.getTileZXY = goog.abstractMethod; /** @@ -140,6 +141,8 @@ ol.source.TileSource.prototype.getTileGrid = function() { /** * Marks a tile coord as being used, without triggering a load. - * @param {string} tileCoordKey Tile coordinate key. + * @param {number} z Tile coordinate z. + * @param {number} x Tile coordinate x. + * @param {number} y Tile coordinate y. */ -ol.source.TileSource.prototype.useTile = goog.nullFunction; +ol.source.TileSource.prototype.useTileZXY = goog.nullFunction; diff --git a/src/ol/tilecoord.js b/src/ol/tilecoord.js index 974c9ed593..9b98af0051 100644 --- a/src/ol/tilecoord.js +++ b/src/ol/tilecoord.js @@ -78,6 +78,17 @@ ol.TileCoord.createFromString = function(str) { }; +/** + * @param {number} z Z. + * @param {number} x X. + * @param {number} y Y. + * @return {string} Key. + */ +ol.TileCoord.getKeyZXY = function(z, x, y) { + return [z, x, y].join('/'); +}; + + /** * @return {number} Hash. */ @@ -112,5 +123,5 @@ ol.TileCoord.prototype.quadKey = function() { * @return {string} String. */ ol.TileCoord.prototype.toString = function() { - return [this.z, this.x, this.y].join('/'); + return ol.TileCoord.getKeyZXY(this.z, this.x, this.y); }; diff --git a/test/spec/ol/source/tilesource.test.js b/test/spec/ol/source/tilesource.test.js index 90b176e7b2..e42d6fb67f 100644 --- a/test/spec/ol/source/tilesource.test.js +++ b/test/spec/ol/source/tilesource.test.js @@ -22,8 +22,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -44,8 +44,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -68,8 +68,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -93,8 +93,8 @@ describe('ol.source.TileSource', function() { var loadedTilesByZ = {}; var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -119,8 +119,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -142,8 +142,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -167,8 +167,8 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); - function getTileIfLoaded(tileCoord) { - var tile = source.getTile(tileCoord, null, null); + function getTileIfLoaded(z, x, y) { + var tile = source.getTileZXY(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -219,10 +219,10 @@ goog.inherits(ol.test.source.MockTileSource, ol.source.TileSource); /** * @inheritDoc */ -ol.test.source.MockTileSource.prototype.getTile = function(tileCoord) { - var key = tileCoord.toString(); +ol.test.source.MockTileSource.prototype.getTileZXY = function(z, x, y) { + var key = ol.TileCoord.getKeyZXY(z, x, y); var tileState = this.loaded_[key] ? ol.TileState.LOADED : ol.TileState.IDLE; - return new ol.Tile(tileCoord, tileState); + return new ol.Tile(new ol.TileCoord(z, x, y), tileState); }; @@ -236,7 +236,7 @@ describe('ol.test.source.MockTileSource', function() { }); }); - describe('#getTile()', function() { + describe('#getTileZXY()', function() { it('returns a tile with state based on constructor arg', function() { var source = new ol.test.source.MockTileSource({ '0/0/0': true, @@ -245,17 +245,17 @@ describe('ol.test.source.MockTileSource', function() { var tile; // check a loaded tile - tile = source.getTile(new ol.TileCoord(0, 0, 0)); + tile = source.getTileZXY(0, 0, 0); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.LOADED); // check a tile that is not loaded - tile = source.getTile(new ol.TileCoord(1, 0, -1)); + tile = source.getTileZXY(1, 0, -1); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.IDLE); // check another loaded tile - tile = source.getTile(new ol.TileCoord(1, 0, 0)); + tile = source.getTileZXY(1, 0, 0); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.LOADED); From 65e6ed348521966e1cb469729b2302a3c7b3214c Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 25 Mar 2013 10:10:03 +0100 Subject: [PATCH 6/8] Rename getTileZXY to getTile --- .../canvas/canvastilelayerrenderer.js | 2 +- src/ol/renderer/dom/domtilelayerrenderer.js | 2 +- src/ol/renderer/layerrenderer.js | 4 ++-- .../renderer/webgl/webgltilelayerrenderer.js | 2 +- src/ol/source/debugtilesource.js | 2 +- src/ol/source/imagetilesource.js | 2 +- src/ol/source/tilesource.js | 2 +- test/spec/ol/source/tilesource.test.js | 24 +++++++++---------- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ol/renderer/canvas/canvastilelayerrenderer.js b/src/ol/renderer/canvas/canvastilelayerrenderer.js index 365500021a..a6e5519ec2 100644 --- a/src/ol/renderer/canvas/canvastilelayerrenderer.js +++ b/src/ol/renderer/canvas/canvastilelayerrenderer.js @@ -159,7 +159,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame = for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); + tile = tileSource.getTile(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED || tileState == ol.TileState.EMPTY) { tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; diff --git a/src/ol/renderer/dom/domtilelayerrenderer.js b/src/ol/renderer/dom/domtilelayerrenderer.js index 832eb96539..8c056742bd 100644 --- a/src/ol/renderer/dom/domtilelayerrenderer.js +++ b/src/ol/renderer/dom/domtilelayerrenderer.js @@ -116,7 +116,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame = for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); + tile = tileSource.getTile(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED) { tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; diff --git a/src/ol/renderer/layerrenderer.js b/src/ol/renderer/layerrenderer.js index 66b4375ec5..e7c1d68eea 100644 --- a/src/ol/renderer/layerrenderer.js +++ b/src/ol/renderer/layerrenderer.js @@ -263,7 +263,7 @@ ol.renderer.Layer.prototype.updateUsedTiles = ol.renderer.Layer.prototype.createGetTileIfLoadedFunction = function(isLoadedFunction, tileSource, tileGrid, projection) { return function(z, x, y) { - var tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); + var tile = tileSource.getTile(z, x, y, tileGrid, projection); return isLoadedFunction(tile) ? tile : null; }; }; @@ -315,7 +315,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { if (ol.PREEMPTIVELY_LOAD_LOW_RESOLUTION_TILES || z == currentZ) { - tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); + tile = tileSource.getTile(z, x, y, tileGrid, projection); if (tile.getState() == ol.TileState.IDLE) { tileCenter = tileGrid.getTileCoordCenter(tile.tileCoord); wantedTiles[tile.tileCoord.toString()] = true; diff --git a/src/ol/renderer/webgl/webgltilelayerrenderer.js b/src/ol/renderer/webgl/webgltilelayerrenderer.js index 419eebf909..c80abb568a 100644 --- a/src/ol/renderer/webgl/webgltilelayerrenderer.js +++ b/src/ol/renderer/webgl/webgltilelayerrenderer.js @@ -267,7 +267,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame = for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { - tile = tileSource.getTileZXY(z, x, y, tileGrid, projection); + tile = tileSource.getTile(z, x, y, tileGrid, projection); tileState = tile.getState(); if (tileState == ol.TileState.LOADED) { if (mapRenderer.isTileTextureLoaded(tile)) { diff --git a/src/ol/source/debugtilesource.js b/src/ol/source/debugtilesource.js index 24c4f70168..a2f22cbc18 100644 --- a/src/ol/source/debugtilesource.js +++ b/src/ol/source/debugtilesource.js @@ -122,7 +122,7 @@ ol.source.DebugTileSource.prototype.expireCache = function(usedTiles) { /** * @inheritDoc */ -ol.source.DebugTileSource.prototype.getTileZXY = function(z, x, y) { +ol.source.DebugTileSource.prototype.getTile = function(z, x, y) { var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); if (this.tileCache_.containsKey(tileCoordKey)) { return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(tileCoordKey)); diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index 65732a2402..5257ff97fa 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -87,7 +87,7 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) { /** * @inheritDoc */ -ol.source.ImageTileSource.prototype.getTileZXY = +ol.source.ImageTileSource.prototype.getTile = function(z, x, y, tileGrid, projection) { var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); if (this.tileCache_.containsKey(tileCoordKey)) { diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index 77b28d66b3..7fbb772a7d 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -128,7 +128,7 @@ ol.source.TileSource.prototype.getResolutions = function() { * @param {ol.Projection=} opt_projection Projection. * @return {!ol.Tile} Tile. */ -ol.source.TileSource.prototype.getTileZXY = goog.abstractMethod; +ol.source.TileSource.prototype.getTile = goog.abstractMethod; /** diff --git a/test/spec/ol/source/tilesource.test.js b/test/spec/ol/source/tilesource.test.js index e42d6fb67f..c5f75eac4b 100644 --- a/test/spec/ol/source/tilesource.test.js +++ b/test/spec/ol/source/tilesource.test.js @@ -23,7 +23,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -45,7 +45,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -69,7 +69,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -94,7 +94,7 @@ describe('ol.source.TileSource', function() { var grid = source.getTileGrid(); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -120,7 +120,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -143,7 +143,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -168,7 +168,7 @@ describe('ol.source.TileSource', function() { var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); function getTileIfLoaded(z, x, y) { - var tile = source.getTileZXY(z, x, y, null, null); + var tile = source.getTile(z, x, y, null, null); return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? tile : null; } @@ -219,7 +219,7 @@ goog.inherits(ol.test.source.MockTileSource, ol.source.TileSource); /** * @inheritDoc */ -ol.test.source.MockTileSource.prototype.getTileZXY = function(z, x, y) { +ol.test.source.MockTileSource.prototype.getTile = function(z, x, y) { var key = ol.TileCoord.getKeyZXY(z, x, y); var tileState = this.loaded_[key] ? ol.TileState.LOADED : ol.TileState.IDLE; return new ol.Tile(new ol.TileCoord(z, x, y), tileState); @@ -236,7 +236,7 @@ describe('ol.test.source.MockTileSource', function() { }); }); - describe('#getTileZXY()', function() { + describe('#getTile()', function() { it('returns a tile with state based on constructor arg', function() { var source = new ol.test.source.MockTileSource({ '0/0/0': true, @@ -245,17 +245,17 @@ describe('ol.test.source.MockTileSource', function() { var tile; // check a loaded tile - tile = source.getTileZXY(0, 0, 0); + tile = source.getTile(0, 0, 0); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.LOADED); // check a tile that is not loaded - tile = source.getTileZXY(1, 0, -1); + tile = source.getTile(1, 0, -1); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.IDLE); // check another loaded tile - tile = source.getTileZXY(1, 0, 0); + tile = source.getTile(1, 0, 0); expect(tile).to.be.a(ol.Tile); expect(tile.state).to.be(ol.TileState.LOADED); From f7cc8fa7389acaccd86833dd7c512f70ab153204 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 25 Mar 2013 11:29:01 +0100 Subject: [PATCH 7/8] Remove ol.TileRange.clone --- src/ol/tilerange.js | 8 -------- test/spec/ol/source/xyz.test.js | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ol/tilerange.js b/src/ol/tilerange.js index ad788a7736..76d3d7437c 100644 --- a/src/ol/tilerange.js +++ b/src/ol/tilerange.js @@ -64,14 +64,6 @@ ol.TileRange.boundingTileRange = function(var_args) { }; -/** - * @return {ol.TileRange} Clone. - */ -ol.TileRange.prototype.clone = function() { - return new ol.TileRange(this.minX, this.minY, this.maxX, this.maxY); -}; - - /** * @param {ol.TileCoord} tileCoord Tile coordinate. * @return {boolean} Contains tile coordinate. diff --git a/test/spec/ol/source/xyz.test.js b/test/spec/ol/source/xyz.test.js index 5b143beb0d..f58b399c36 100644 --- a/test/spec/ol/source/xyz.test.js +++ b/test/spec/ol/source/xyz.test.js @@ -86,7 +86,9 @@ describe('ol.source.XYZ', function() { tileCoord, function(z, tileRange) { zs.push(z); - tileRanges.push(tileRange.clone()); + tileRanges.push(new ol.TileRange( + tileRange.minX, tileRange.minY, + tileRange.maxX, tileRange.maxY)); return false; }); @@ -129,5 +131,6 @@ describe('ol.source.XYZ', function() { goog.require('ol.Coordinate'); goog.require('ol.TileCoord'); +goog.require('ol.TileRange'); goog.require('ol.tilegrid.XYZ'); goog.require('ol.source.XYZ'); From 9906c518a75f2e5121d068df48f3ed792f927ec8 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 25 Mar 2013 11:45:20 +0100 Subject: [PATCH 8/8] Rename useTileZXY to useTile --- src/ol/renderer/layerrenderer.js | 2 +- src/ol/source/imagetilesource.js | 2 +- src/ol/source/tilesource.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ol/renderer/layerrenderer.js b/src/ol/renderer/layerrenderer.js index e7c1d68eea..6484c01a3e 100644 --- a/src/ol/renderer/layerrenderer.js +++ b/src/ol/renderer/layerrenderer.js @@ -322,7 +322,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = tileQueue.enqueue(tile, tileSourceKey, tileCenter, tileResolution); } } else { - tileSource.useTileZXY(z, x, y); + tileSource.useTile(z, x, y); } } } diff --git a/src/ol/source/imagetilesource.js b/src/ol/source/imagetilesource.js index 5257ff97fa..11e0f96d37 100644 --- a/src/ol/source/imagetilesource.js +++ b/src/ol/source/imagetilesource.js @@ -111,7 +111,7 @@ ol.source.ImageTileSource.prototype.getTile = /** * @inheritDoc */ -ol.source.ImageTileSource.prototype.useTileZXY = function(z, x, y) { +ol.source.ImageTileSource.prototype.useTile = function(z, x, y) { var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y); if (this.tileCache_.containsKey(tileCoordKey)) { this.tileCache_.get(tileCoordKey); diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index 7fbb772a7d..7811ebe233 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -145,4 +145,4 @@ ol.source.TileSource.prototype.getTileGrid = function() { * @param {number} x Tile coordinate x. * @param {number} y Tile coordinate y. */ -ol.source.TileSource.prototype.useTileZXY = goog.nullFunction; +ol.source.TileSource.prototype.useTile = goog.nullFunction;