Re-use ol.TileCoord objects

This commit is contained in:
Tom Payne
2013-04-09 15:28:49 +02:00
parent 5a4033db7a
commit 5bd67e1325
3 changed files with 16 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;