Merge pull request #428 from twpayne/gc-optimizations

GC optimizations
This commit is contained in:
Tom Payne
2013-03-25 03:54:15 -07:00
13 changed files with 128 additions and 124 deletions

View File

@@ -155,22 +155,21 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
tilesToDrawByZ, getTileIfLoaded); tilesToDrawByZ, getTileIfLoaded);
var allTilesLoaded = true; var allTilesLoaded = true;
var tile, tileCoord, tileState, x, y; var tile, tileState, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y); tile = tileSource.getTile(z, x, y, tileGrid, projection);
tile = tileSource.getTile(tileCoord, tileGrid, projection);
tileState = tile.getState(); tileState = tile.getState();
if (tileState == ol.TileState.LOADED || tileState == ol.TileState.EMPTY) { if (tileState == ol.TileState.LOADED || tileState == ol.TileState.EMPTY) {
tilesToDrawByZ[z][tileCoord.toString()] = tile; tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
continue; continue;
} else if (tileState == ol.TileState.ERROR) { } else if (tileState == ol.TileState.ERROR) {
continue; continue;
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); tileGrid.forEachTileCoordParentTileRange(tile.tileCoord, findLoadedTiles);
} }
} }
@@ -191,9 +190,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
if (currentZ == z) { if (currentZ == z) {
for (tileCoordKey in tilesToDraw) { for (tileCoordKey in tilesToDraw) {
tile = tilesToDraw[tileCoordKey]; tile = tilesToDraw[tileCoordKey];
tileCoord = tile.tileCoord; index = (tile.tileCoord.y - tileRange.minY) * tileRangeWidth +
index = (tileCoord.y - tileRange.minY) * tileRangeWidth + (tile.tileCoord.x - tileRange.minX);
(tileCoord.x - tileRange.minX);
if (this.renderedTiles_[index] != tile) { if (this.renderedTiles_[index] != tile) {
x = tileSize.width * (tile.tileCoord.x - tileRange.minX); x = tileSize.width * (tile.tileCoord.x - tileRange.minX);
y = tileSize.height * (tileRange.maxY - tile.tileCoord.y); y = tileSize.height * (tileRange.maxY - tile.tileCoord.y);

View File

@@ -112,15 +112,14 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
tilesToDrawByZ, getTileIfLoaded); tilesToDrawByZ, getTileIfLoaded);
var allTilesLoaded = true; var allTilesLoaded = true;
var tile, tileCoord, tileState, x, y; var tile, tileState, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y); tile = tileSource.getTile(z, x, y, tileGrid, projection);
tile = tileSource.getTile(tileCoord, tileGrid, projection);
tileState = tile.getState(); tileState = tile.getState();
if (tileState == ol.TileState.LOADED) { if (tileState == ol.TileState.LOADED) {
tilesToDrawByZ[z][tileCoord.toString()] = tile; tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
continue; continue;
} else if (tileState == ol.TileState.ERROR || } else if (tileState == ol.TileState.ERROR ||
tileState == ol.TileState.EMPTY) { tileState == ol.TileState.EMPTY) {
@@ -128,7 +127,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); tileGrid.forEachTileCoordParentTileRange(tile.tileCoord, findLoadedTiles);
} }

View File

@@ -9,7 +9,6 @@ goog.require('ol.Image');
goog.require('ol.ImageState'); goog.require('ol.ImageState');
goog.require('ol.Object'); goog.require('ol.Object');
goog.require('ol.Tile'); goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.TileState'); goog.require('ol.TileState');
goog.require('ol.layer.Layer'); goog.require('ol.layer.Layer');
@@ -258,12 +257,13 @@ ol.renderer.Layer.prototype.updateUsedTiles =
* @param {ol.source.TileSource} tileSource Tile source. * @param {ol.source.TileSource} tileSource Tile source.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid. * @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {ol.Projection} projection Projection. * @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 = ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
function(isLoadedFunction, tileSource, tileGrid, projection) { function(isLoadedFunction, tileSource, tileGrid, projection) {
return function(tileCoord) { return function(z, x, y) {
var tile = tileSource.getTile(tileCoord, tileGrid, projection); var tile = tileSource.getTile(z, x, y, tileGrid, projection);
return isLoadedFunction(tile) ? tile : null; return isLoadedFunction(tile) ? tile : null;
}; };
}; };
@@ -307,7 +307,7 @@ ol.renderer.Layer.prototype.manageTilePyramid =
} }
var wantedTiles = frameState.wantedTiles[tileSourceKey]; var wantedTiles = frameState.wantedTiles[tileSourceKey];
var tileQueue = frameState.tileQueue; 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 // FIXME this should loop up to tileGrid's minZ when implemented
for (z = currentZ; z >= 0; --z) { for (z = currentZ; z >= 0; --z) {
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z); tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
@@ -315,15 +315,14 @@ ol.renderer.Layer.prototype.manageTilePyramid =
for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
if (ol.PREEMPTIVELY_LOAD_LOW_RESOLUTION_TILES || z == currentZ) { if (ol.PREEMPTIVELY_LOAD_LOW_RESOLUTION_TILES || z == currentZ) {
tileCoord = new ol.TileCoord(z, x, y); tile = tileSource.getTile(z, x, y, tileGrid, projection);
tile = tileSource.getTile(tileCoord, tileGrid, projection);
if (tile.getState() == ol.TileState.IDLE) { if (tile.getState() == ol.TileState.IDLE) {
tileCenter = tileGrid.getTileCoordCenter(tileCoord); tileCenter = tileGrid.getTileCoordCenter(tile.tileCoord);
wantedTiles[tileCoord.toString()] = true; wantedTiles[tile.tileCoord.toString()] = true;
tileQueue.enqueue(tile, tileSourceKey, tileCenter, tileResolution); tileQueue.enqueue(tile, tileSourceKey, tileCenter, tileResolution);
} }
} else { } else {
tileSource.useTile(z + '/' + x + '/' + y); tileSource.useTile(z, x, y);
} }
} }
} }

View File

@@ -12,7 +12,6 @@ goog.require('goog.webgl');
goog.require('ol.Extent'); goog.require('ol.Extent');
goog.require('ol.Size'); goog.require('ol.Size');
goog.require('ol.Tile'); goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.TileState'); goog.require('ol.TileState');
goog.require('ol.layer.TileLayer'); goog.require('ol.layer.TileLayer');
@@ -214,19 +213,18 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
var tilesToLoad = new goog.structs.PriorityQueue(); var tilesToLoad = new goog.structs.PriorityQueue();
var allTilesLoaded = true; 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 (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y); tile = tileSource.getTile(z, x, y, tileGrid, projection);
tile = tileSource.getTile(tileCoord, tileGrid, projection);
tileState = tile.getState(); tileState = tile.getState();
if (tileState == ol.TileState.LOADED) { if (tileState == ol.TileState.LOADED) {
if (mapRenderer.isTileTextureLoaded(tile)) { if (mapRenderer.isTileTextureLoaded(tile)) {
tilesToDrawByZ[z][tileCoord.toString()] = tile; tilesToDrawByZ[z][tile.tileCoord.toString()] = tile;
continue; continue;
} else { } else {
tileCenter = tileGrid.getTileCoordCenter(tileCoord); tileCenter = tileGrid.getTileCoordCenter(tile.tileCoord);
deltaX = tileCenter.x - center.x; deltaX = tileCenter.x - center.x;
deltaY = tileCenter.y - center.y; deltaY = tileCenter.y - center.y;
priority = Math.sqrt(deltaX * deltaX + deltaY * deltaY); priority = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
@@ -238,7 +236,8 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
} }
allTilesLoaded = false; allTilesLoaded = false;
tileGrid.forEachTileCoordParentTileRange(tileCoord, findLoadedTiles); tileGrid.forEachTileCoordParentTileRange(
tile.tileCoord, findLoadedTiles);
} }

View File

@@ -122,13 +122,13 @@ ol.source.DebugTileSource.prototype.expireCache = function(usedTiles) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.source.DebugTileSource.prototype.getTile = function(tileCoord) { ol.source.DebugTileSource.prototype.getTile = function(z, x, y) {
var key = tileCoord.toString(); var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(key)) { if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(key)); return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(tileCoordKey));
} else { } else {
var tile = new ol.DebugTile_(tileCoord, this.tileGrid); var tile = new ol.DebugTile_(new ol.TileCoord(z, x, y), this.tileGrid);
this.tileCache_.set(key, tile); this.tileCache_.set(tileCoordKey, tile);
return tile; return tile;
} }
}; };

View File

@@ -7,6 +7,7 @@ goog.require('ol.ImageTile');
goog.require('ol.Projection'); goog.require('ol.Projection');
goog.require('ol.Tile'); goog.require('ol.Tile');
goog.require('ol.TileCache'); goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileState'); goog.require('ol.TileState');
goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType'); goog.require('ol.TileUrlFunctionType');
@@ -87,20 +88,21 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) {
* @inheritDoc * @inheritDoc
*/ */
ol.source.ImageTileSource.prototype.getTile = ol.source.ImageTileSource.prototype.getTile =
function(tileCoord, tileGrid, projection) { function(z, x, y, tileGrid, projection) {
var key = tileCoord.toString(); var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(key)) { if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache_.get(key)); return /** @type {!ol.Tile} */ (this.tileCache_.get(tileCoordKey));
} else { } else {
goog.asserts.assert(tileGrid); goog.asserts.assert(tileGrid);
goog.asserts.assert(projection); goog.asserts.assert(projection);
var tileCoord = new ol.TileCoord(z, x, y);
var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection); var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection);
var tile = new ol.ImageTile( var tile = new ol.ImageTile(
tileCoord, tileCoord,
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY, goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
goog.isDef(tileUrl) ? tileUrl : '', goog.isDef(tileUrl) ? tileUrl : '',
this.crossOrigin_); this.crossOrigin_);
this.tileCache_.set(key, tile); this.tileCache_.set(tileCoordKey, tile);
return tile; return tile;
} }
}; };
@@ -109,7 +111,8 @@ ol.source.ImageTileSource.prototype.getTile =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.source.ImageTileSource.prototype.useTile = function(tileCoordKey) { ol.source.ImageTileSource.prototype.useTile = function(z, x, y) {
var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) { if (this.tileCache_.containsKey(tileCoordKey)) {
this.tileCache_.get(tileCoordKey); this.tileCache_.get(tileCoordKey);
} }

View File

@@ -72,8 +72,8 @@ ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
* *
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of * @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
* loaded tiles by zoom level. * loaded tiles by zoom level.
* @param {function(ol.TileCoord): ol.Tile} getTileIfLoaded A function that * @param {function(number, number, number): ol.Tile} getTileIfLoaded A function
* returns the tile only if it is fully loaded. * that returns the tile only if it is fully loaded.
* @param {number} z Zoom level. * @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range. * @param {ol.TileRange} tileRange Tile range.
* @return {boolean} The tile range is fully covered with loaded tiles. * @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) { getTileIfLoaded, z, tileRange) {
// FIXME this could be more efficient about filling partial holes // FIXME this could be more efficient about filling partial holes
var fullyCovered = true; var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y; var tile, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y); tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
tileCoordKey = tileCoord.toString();
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) { if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
continue; continue;
} }
tile = getTileIfLoaded(tileCoord); tile = getTileIfLoaded(z, x, y);
if (!goog.isNull(tile)) { if (!goog.isNull(tile)) {
if (!loadedTilesByZ[z]) { if (!loadedTilesByZ[z]) {
loadedTilesByZ[z] = {}; loadedTilesByZ[z] = {};
@@ -122,7 +121,9 @@ 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.tilegrid.TileGrid=} opt_tileGrid Tile grid.
* @param {ol.Projection=} opt_projection Projection. * @param {ol.Projection=} opt_projection Projection.
* @return {!ol.Tile} Tile. * @return {!ol.Tile} Tile.
@@ -140,6 +141,8 @@ ol.source.TileSource.prototype.getTileGrid = function() {
/** /**
* Marks a tile coord as being used, without triggering a load. * 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.useTile = goog.nullFunction;

View File

@@ -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. * @return {number} Hash.
*/ */
@@ -112,5 +123,5 @@ ol.TileCoord.prototype.quadKey = function() {
* @return {string} String. * @return {string} String.
*/ */
ol.TileCoord.prototype.toString = function() { ol.TileCoord.prototype.toString = function() {
return [this.z, this.x, this.y].join('/'); return ol.TileCoord.getKeyZXY(this.z, this.x, this.y);
}; };

View File

@@ -137,13 +137,12 @@ ol.tilegrid.TileGrid.prototype.getPixelBoundsForTileCoordAndResolution =
function(tileCoord, resolution) { function(tileCoord, resolution) {
var scale = resolution / this.getResolution(tileCoord.z); var scale = resolution / this.getResolution(tileCoord.z);
var tileSize = this.getTileSize(tileCoord.z); var tileSize = this.getTileSize(tileCoord.z);
tileSize = new ol.Size(tileSize.width / scale, var tileWidth = tileSize.width / scale;
tileSize.height / scale); var tileHeight = tileSize.height / scale;
var minX, maxX, minY, maxY; var minX = Math.round(tileCoord.x * tileWidth);
minX = Math.round(tileCoord.x * tileSize.width); var minY = Math.round(tileCoord.y * tileHeight);
maxX = Math.round((tileCoord.x + 1) * tileSize.width); var maxX = Math.round((tileCoord.x + 1) * tileWidth);
minY = Math.round(tileCoord.y * tileSize.height); var maxY = Math.round((tileCoord.y + 1) * tileHeight);
maxY = Math.round((tileCoord.y + 1) * tileSize.height);
return new ol.PixelBounds(minX, minY, maxX, maxY); return new ol.PixelBounds(minX, minY, maxX, maxY);
}; };
@@ -190,10 +189,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
*/ */
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function( ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
extent, resolution) { extent, resolution) {
var min = this.getTileCoordForCoordAndResolution_( var min = this.getTileCoordForXYAndResolution_(
new ol.Coordinate(extent.minX, extent.minY), resolution); extent.minX, extent.minY, resolution, false);
var max = this.getTileCoordForCoordAndResolution_( var max = this.getTileCoordForXYAndResolution_(
new ol.Coordinate(extent.maxX, extent.maxY), resolution, true); extent.maxX, extent.maxY, resolution, true);
return new ol.TileRange(min.x, min.y, max.x, max.y); return new ol.TileRange(min.x, min.y, max.x, max.y);
}; };
@@ -250,38 +249,40 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
*/ */
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function( ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
coordinate, resolution) { coordinate, resolution) {
return this.getTileCoordForCoordAndResolution_(coordinate, resolution); return this.getTileCoordForXYAndResolution_(
coordinate.x, coordinate.y, resolution, false);
}; };
/** /**
* @param {ol.Coordinate} coordinate Coordinate. * @param {number} x X.
* @param {number} y Y.
* @param {number} resolution Resolution. * @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 * intersections go to the higher tile coordinate, let edge intersections
* go to the lower tile coordinate. * go to the lower tile coordinate.
* @return {ol.TileCoord} Tile coordinate. * @return {ol.TileCoord} Tile coordinate.
* @private * @private
*/ */
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function( ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
coordinate, resolution, opt_reverseIntersectionPolicy) { x, y, resolution, reverseIntersectionPolicy) {
var z = this.getZForResolution(resolution); var z = this.getZForResolution(resolution);
var scale = resolution / this.getResolution(z); var scale = resolution / this.getResolution(z);
var origin = this.getOrigin(z); var origin = this.getOrigin(z);
var tileSize = this.getTileSize(z); var tileSize = this.getTileSize(z);
var x = scale * (coordinate.x - origin.x) / (resolution * tileSize.width); var tileCoordX = scale * (x - origin.x) / (resolution * tileSize.width);
var y = scale * (coordinate.y - origin.y) / (resolution * tileSize.height); var tileCoordY = scale * (y - origin.y) / (resolution * tileSize.height);
if (!opt_reverseIntersectionPolicy) { if (reverseIntersectionPolicy) {
x = Math.floor(x); tileCoordX = Math.ceil(tileCoordX) - 1;
y = Math.floor(y); tileCoordY = Math.ceil(tileCoordY) - 1;
} else { } else {
x = Math.ceil(x) - 1; tileCoordX = Math.floor(tileCoordX);
y = Math.ceil(y) - 1; tileCoordY = Math.floor(tileCoordY);
} }
return new ol.TileCoord(z, x, y); return new ol.TileCoord(z, tileCoordX, tileCoordY);
}; };
@@ -293,7 +294,8 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function(
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ = ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
function(coordinate, z) { function(coordinate, z) {
var resolution = this.getResolution(z); var resolution = this.getResolution(z);
return this.getTileCoordForCoordAndResolution_(coordinate, resolution); return this.getTileCoordForXYAndResolution_(
coordinate.x, coordinate.y, resolution, false);
}; };

View File

@@ -39,18 +39,11 @@ goog.inherits(ol.tilegrid.XYZ, ol.tilegrid.TileGrid);
*/ */
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange = ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
function(tileCoord, callback, opt_obj) { function(tileCoord, callback, opt_obj) {
var x = tileCoord.x; var tileRange = new ol.TileRange(0, 0, tileCoord.x, tileCoord.y);
var y = tileCoord.y; var z;
var z = tileCoord.z; for (z = tileCoord.z - 1; z >= 0; --z) {
var tileRange; tileRange.minX = tileRange.maxX >>= 1;
while (true) { tileRange.minY = tileRange.maxY >>= 1;
z -= 1;
if (z < 0) {
break;
}
x >>= 1;
y >>= 1;
tileRange = new ol.TileRange(x, y, x, y);
if (callback.call(opt_obj, z, tileRange)) { if (callback.call(opt_obj, z, tileRange)) {
break; break;
} }

View File

@@ -22,8 +22,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 3);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -44,8 +44,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 0);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -68,8 +68,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -93,8 +93,8 @@ describe('ol.source.TileSource', function() {
var loadedTilesByZ = {}; var loadedTilesByZ = {};
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -119,8 +119,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -142,8 +142,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -167,8 +167,8 @@ describe('ol.source.TileSource', function() {
var grid = source.getTileGrid(); var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1); var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
function getTileIfLoaded(tileCoord) { function getTileIfLoaded(z, x, y) {
var tile = source.getTile(tileCoord, null, null); var tile = source.getTile(z, x, y, null, null);
return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ? return (!goog.isNull(tile) && tile.getState() === ol.TileState.LOADED) ?
tile : null; tile : null;
} }
@@ -219,10 +219,10 @@ goog.inherits(ol.test.source.MockTileSource, ol.source.TileSource);
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.test.source.MockTileSource.prototype.getTile = function(tileCoord) { ol.test.source.MockTileSource.prototype.getTile = function(z, x, y) {
var key = tileCoord.toString(); var key = ol.TileCoord.getKeyZXY(z, x, y);
var tileState = this.loaded_[key] ? ol.TileState.LOADED : ol.TileState.IDLE; 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);
}; };
@@ -245,17 +245,17 @@ describe('ol.test.source.MockTileSource', function() {
var tile; var tile;
// check a loaded tile // check a loaded tile
tile = source.getTile(new ol.TileCoord(0, 0, 0)); tile = source.getTile(0, 0, 0);
expect(tile).to.be.a(ol.Tile); expect(tile).to.be.a(ol.Tile);
expect(tile.state).to.be(ol.TileState.LOADED); expect(tile.state).to.be(ol.TileState.LOADED);
// check a tile that is not loaded // check a tile that is not loaded
tile = source.getTile(new ol.TileCoord(1, 0, -1)); tile = source.getTile(1, 0, -1);
expect(tile).to.be.a(ol.Tile); expect(tile).to.be.a(ol.Tile);
expect(tile.state).to.be(ol.TileState.IDLE); expect(tile.state).to.be(ol.TileState.IDLE);
// check another loaded tile // check another loaded tile
tile = source.getTile(new ol.TileCoord(1, 0, 0)); tile = source.getTile(1, 0, 0);
expect(tile).to.be.a(ol.Tile); expect(tile).to.be.a(ol.Tile);
expect(tile.state).to.be(ol.TileState.LOADED); expect(tile.state).to.be(ol.TileState.LOADED);

View File

@@ -86,7 +86,9 @@ describe('ol.source.XYZ', function() {
tileCoord, tileCoord,
function(z, tileRange) { function(z, tileRange) {
zs.push(z); zs.push(z);
tileRanges.push(tileRange); tileRanges.push(new ol.TileRange(
tileRange.minX, tileRange.minY,
tileRange.maxX, tileRange.maxY));
return false; return false;
}); });
@@ -129,5 +131,6 @@ describe('ol.source.XYZ', function() {
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.TileCoord'); goog.require('ol.TileCoord');
goog.require('ol.TileRange');
goog.require('ol.tilegrid.XYZ'); goog.require('ol.tilegrid.XYZ');
goog.require('ol.source.XYZ'); goog.require('ol.source.XYZ');

View File

@@ -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() { it('returns higher tile coord for intersections by default', function() {
var tileGrid = new ol.tilegrid.TileGrid({ var tileGrid = new ol.tilegrid.TileGrid({
resolutions: resolutions, resolutions: resolutions,
@@ -388,21 +388,18 @@ describe('ol.tilegrid.TileGrid', function() {
tileSize: tileSize tileSize: tileSize
}); });
var coordinate;
var tileCoord; var tileCoord;
// gets higher tile for edge intersection // gets higher tile for edge intersection
coordinate = new ol.Coordinate(0, 0); tileCoord = tileGrid.getTileCoordForXYAndResolution_(
tileCoord = tileGrid.getTileCoordForCoordAndResolution_( 0, 0, 100, false);
coordinate, 100);
expect(tileCoord.z).to.eql(3); expect(tileCoord.z).to.eql(3);
expect(tileCoord.x).to.eql(0); expect(tileCoord.x).to.eql(0);
expect(tileCoord.y).to.eql(0); expect(tileCoord.y).to.eql(0);
// gets higher tile for edge intersection // gets higher tile for edge intersection
coordinate = new ol.Coordinate(100000, 100000); tileCoord = tileGrid.getTileCoordForXYAndResolution_(
tileCoord = tileGrid.getTileCoordForCoordAndResolution_( 100000, 100000, 100, false);
coordinate, 100);
expect(tileCoord.z).to.eql(3); expect(tileCoord.z).to.eql(3);
expect(tileCoord.x).to.eql(10); expect(tileCoord.x).to.eql(10);
expect(tileCoord.y).to.eql(10); expect(tileCoord.y).to.eql(10);
@@ -417,21 +414,18 @@ describe('ol.tilegrid.TileGrid', function() {
tileSize: tileSize tileSize: tileSize
}); });
var coordinate;
var tileCoord; var tileCoord;
// can get lower tile for edge intersection // can get lower tile for edge intersection
coordinate = new ol.Coordinate(0, 0); tileCoord = tileGrid.getTileCoordForXYAndResolution_(
tileCoord = tileGrid.getTileCoordForCoordAndResolution_( 0, 0, 100, true);
coordinate, 100, true);
expect(tileCoord.z).to.eql(3); expect(tileCoord.z).to.eql(3);
expect(tileCoord.x).to.eql(-1); expect(tileCoord.x).to.eql(-1);
expect(tileCoord.y).to.eql(-1); expect(tileCoord.y).to.eql(-1);
// gets higher tile for edge intersection // gets higher tile for edge intersection
coordinate = new ol.Coordinate(100000, 100000); tileCoord = tileGrid.getTileCoordForXYAndResolution_(
tileCoord = tileGrid.getTileCoordForCoordAndResolution_( 100000, 100000, 100, true);
coordinate, 100, true);
expect(tileCoord.z).to.eql(3); expect(tileCoord.z).to.eql(3);
expect(tileCoord.x).to.eql(9); expect(tileCoord.x).to.eql(9);
expect(tileCoord.y).to.eql(9); expect(tileCoord.y).to.eql(9);