Premptively load low resolution tiles
This commit is contained in:
@@ -96,7 +96,6 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
@@ -156,19 +155,14 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
var allTilesLoaded = true;
|
||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
||||
var tile, tileCoord, 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);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADED ||
|
||||
tileState == ol.TileState.EMPTY) {
|
||||
if (tileState == ol.TileState.LOADED || tileState == ol.TileState.EMPTY) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
continue;
|
||||
} else if (tileState == ol.TileState.ERROR) {
|
||||
@@ -246,6 +240,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
this.manageTilePyramid(
|
||||
frameState, tileSource, tileGrid, projection, extent, z);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
var transform = this.transform_;
|
||||
|
||||
@@ -83,7 +83,6 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
@@ -113,18 +112,14 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
tilesToDrawByZ, getTileIfLoaded);
|
||||
|
||||
var allTilesLoaded = true;
|
||||
var tile, tileCenter, tileCoord, tileState, x, y;
|
||||
var tile, tileCoord, 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);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADED) {
|
||||
if (tileState == ol.TileState.LOADED) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
continue;
|
||||
} else if (tileState == ol.TileState.ERROR ||
|
||||
@@ -224,6 +219,8 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
this.manageTilePyramid(
|
||||
frameState, tileSource, tileGrid, projection, extent, z);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -285,7 +285,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
var tileSourceKey = goog.getUid(tileSource).toString();
|
||||
var tileGrid = tileSource.getTileGrid();
|
||||
if (goog.isNull(tileGrid)) {
|
||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||
@@ -394,11 +393,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
tileCoord = new ol.TileCoord(z, x, y);
|
||||
tile = tileSource.getTile(tileCoord, tileGrid, projection);
|
||||
tileState = tile.getState();
|
||||
if (tileState == ol.TileState.IDLE) {
|
||||
this.updateWantedTiles(frameState.wantedTiles, tileSource, tileCoord);
|
||||
tileCenter = tileGrid.getTileCoordCenter(tileCoord);
|
||||
frameState.tileQueue.enqueue(tile, tileSourceKey, tileCenter);
|
||||
} else if (tileState == ol.TileState.LOADED) {
|
||||
if (tileState == ol.TileState.LOADED) {
|
||||
if (mapRenderer.isTileTextureLoaded(tile)) {
|
||||
tilesToDrawByZ[z][tileCoord.toString()] = tile;
|
||||
continue;
|
||||
@@ -466,6 +461,8 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
this.manageTilePyramid(
|
||||
frameState, tileSource, tileGrid, projection, extent, z);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
|
||||
|
||||
Reference in New Issue
Block a user