From 5bd67e13256da98db00ce70387e371b46566d01c Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 9 Apr 2013 15:28:49 +0200 Subject: [PATCH] Re-use ol.TileCoord objects --- src/ol/source/wmtssource.js | 7 +++++-- src/ol/source/xyzsource.js | 7 +++++-- src/ol/tilegrid/tilegrid.js | 10 ++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 51cdbd037d..0f94d03dff 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -113,6 +113,7 @@ ol.source.WMTS = function(options) { })); } + var tmpTileCoord = new ol.TileCoord(0, 0, 0); tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform( function(tileCoord, projection) { var tileGrid = this.getTileGrid(); @@ -134,8 +135,10 @@ ol.source.WMTS = function(options) { (extent.maxX - extent.minX) / (tileExtent.maxX - tileExtent.minX)); x = goog.math.modulo(x, numCols); - tileExtent = tileGrid.getTileCoordExtent( - new ol.TileCoord(tileCoord.z, x, tileCoord.y)); + tmpTileCoord.z = tileCoord.z; + tmpTileCoord.x = x; + tmpTileCoord.y = tileCoord.y; + tileExtent = tileGrid.getTileCoordExtent(tmpTileCoord); } if (!tileExtent.intersects(extent)) { return null; diff --git a/src/ol/source/xyzsource.js b/src/ol/source/xyzsource.js index 8ee937578d..508a8a501c 100644 --- a/src/ol/source/xyzsource.js +++ b/src/ol/source/xyzsource.js @@ -61,6 +61,7 @@ ol.source.XYZ = function(options) { var extent = options.extent; if (goog.isDefAndNotNull(extent)) { + var tmpTileCoord = new ol.TileCoord(0, 0, 0); tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform( function(tileCoord) { if (options.maxZoom < tileCoord.z) { @@ -72,8 +73,10 @@ ol.source.XYZ = function(options) { return null; } var x = goog.math.modulo(tileCoord.x, n); - var tileExtent = tileGrid.getTileCoordExtent( - new ol.TileCoord(tileCoord.z, x, tileCoord.y)); + tmpTileCoord.z = tileCoord.z; + tmpTileCoord.x = x; + tmpTileCoord.y = tileCoord.y; + var tileExtent = tileGrid.getTileCoordExtent(tmpTileCoord); // FIXME we shouldn't need a typecast here if (!tileExtent.intersects(/** @type {ol.Extent} */ (extent))) { return null; diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 60df10b90d..91863a9540 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -205,11 +205,13 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) { */ ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function( extent, resolution) { - var min = this.getTileCoordForXYAndResolution_( + var tileCoord = this.getTileCoordForXYAndResolution_( 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); + var minX = tileCoord.x; + var minY = tileCoord.y; + tileCoord = this.getTileCoordForXYAndResolution_( + extent.maxX, extent.maxY, resolution, true, tileCoord); + return new ol.TileRange(minX, minY, tileCoord.x, tileCoord.y); };