Premptively load low resolution tiles

This commit is contained in:
Tom Payne
2013-03-12 18:04:28 +01:00
parent e3abe376f1
commit 80df629319
6 changed files with 86 additions and 46 deletions

View File

@@ -18,6 +18,12 @@ goog.require('ol.layer.LayerState');
goog.require('ol.source.TileSource');
/**
* @define {boolean} Preemptively load low resolution tiles.
*/
ol.PREEMPTIVELY_LOAD_LOW_RESOLUTION_TILES = true;
/**
* @constructor
@@ -246,23 +252,6 @@ ol.renderer.Layer.prototype.updateUsedTiles =
};
/**
* @protected
* @param {Object.<string, Object.<string, boolean>>} wantedTiles Wanted tiles.
* @param {ol.source.TileSource} tileSource Tile source.
* @param {ol.TileCoord} tileCoord Tile coordinate.
*/
ol.renderer.Layer.prototype.updateWantedTiles =
function(wantedTiles, tileSource, tileCoord) {
var tileSourceKey = goog.getUid(tileSource).toString();
var coordKey = tileCoord.toString();
if (!(tileSourceKey in wantedTiles)) {
wantedTiles[tileSourceKey] = {};
}
wantedTiles[tileSourceKey][coordKey] = true;
};
/**
* @param {function(ol.Tile): boolean} isLoadedFunction Function to
* determine if the tile is loaded.
@@ -293,3 +282,50 @@ ol.renderer.Layer.prototype.snapCenterToPixel =
resolution * (Math.round(center.x / resolution) + (size.width % 2) / 2),
resolution * (Math.round(center.y / resolution) + (size.height % 2) / 2));
};
/**
* Manage tile pyramid.
* This function performs a number of functions related to the tiles at the
* current zoom and lower zoom levels:
* - registers idle tiles in frameState.wantedTiles so that they are not
* discarded by the tile queue
* - enqueues missing tiles
* @param {ol.FrameState} frameState Frame state.
* @param {ol.source.TileSource} tileSource Tile source.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {ol.Projection} projection Projection.
* @param {ol.Extent} extent Extent.
* @param {number} currentZ Current Z.
* @protected
*/
ol.renderer.Layer.prototype.manageTilePyramid =
function(frameState, tileSource, tileGrid, projection, extent, currentZ) {
var tileSourceKey = goog.getUid(tileSource).toString();
if (!(tileSourceKey in frameState.wantedTiles)) {
frameState.wantedTiles[tileSourceKey] = {};
}
var wantedTiles = frameState.wantedTiles[tileSourceKey];
var tileQueue = frameState.tileQueue;
var tile, tileCenter, tileCoord, 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);
tileResolution = tileGrid.getResolution(z);
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);
if (tile.getState() == ol.TileState.IDLE) {
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
wantedTiles[tileCoord.toString()] = true;
tileQueue.enqueue(tile, tileSourceKey, tileCenter, tileResolution);
}
} else {
tileSource.useTile(z + '/' + x + '/' + y);
}
}
}
}
};