Only track tiles that are actually wanted

Instead of keeping track of wanted tile ranges, we can instead track wanted tiles individually.  This provides enough for the map to know how to prioritize tiles and should be more efficient (no extra calls to extend tile ranges or check for tile containment within a range).
This commit is contained in:
Tim Schaub
2013-02-06 16:08:24 -07:00
parent e335b7b74a
commit 2bd29ff60e
6 changed files with 13 additions and 21 deletions

View File

@@ -31,7 +31,7 @@ goog.require('ol.layer.LayerState');
* usedTiles: Object.<string, Object.<string, ol.TileRange>>,
* view2DState: ol.View2DState,
* viewHints: Array.<number>,
* wantedTiles: Object.<string, Object.<string, ol.TileRange>>}}
* wantedTiles: Object.<string, Object.<string, boolean>>}}
*/
ol.FrameState;

View File

@@ -500,9 +500,8 @@ ol.Map.prototype.getTilePriority = function(tile, tileSourceKey, tileCenter) {
if (goog.isNull(frameState) || !(tileSourceKey in frameState.wantedTiles)) {
return ol.TileQueue.DROP;
}
var zKey = tile.tileCoord.z.toString();
if (!(zKey in frameState.wantedTiles[tileSourceKey]) ||
!frameState.wantedTiles[tileSourceKey][zKey].contains(tile.tileCoord)) {
var coordKey = tile.tileCoord.toString();
if (!frameState.wantedTiles[tileSourceKey][coordKey]) {
return ol.TileQueue.DROP;
}
var center = frameState.view2DState.center;

View File

@@ -167,6 +167,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
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) {
@@ -216,7 +217,6 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
if (!allTilesLoaded) {
frameState.animate = true;
this.updateWantedTiles(frameState.wantedTiles, tileSource, z, tileRange);
}
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);

View File

@@ -131,6 +131,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
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) {
@@ -234,7 +235,6 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
if (!allTilesLoaded) {
frameState.animate = true;
this.updateWantedTiles(frameState.wantedTiles, tileSource, z, tileRange);
}
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);

View File

@@ -4,6 +4,7 @@ goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.FrameState');
goog.require('ol.Object');
goog.require('ol.TileCoord');
goog.require('ol.TileRange');
goog.require('ol.layer.Layer');
goog.require('ol.layer.LayerProperty');
@@ -197,24 +198,16 @@ ol.renderer.Layer.prototype.updateUsedTiles =
/**
* @protected
* @param {Object.<string, Object.<string, ol.TileRange>>} wantedTiles Wanted
* tile ranges.
* @param {Object.<string, Object.<string, boolean>>} wantedTiles Wanted tiles.
* @param {ol.source.Source} source Source.
* @param {number} z Z.
* @param {ol.TileRange} tileRange Tile range.
* @param {ol.TileCoord} tileCoord Tile coordinate.
*/
ol.renderer.Layer.prototype.updateWantedTiles =
function(wantedTiles, source, z, tileRange) {
function(wantedTiles, source, tileCoord) {
var sourceKey = goog.getUid(source).toString();
var zKey = z.toString();
if (sourceKey in wantedTiles) {
if (zKey in wantedTiles[sourceKey]) {
wantedTiles[sourceKey][zKey].extend(tileRange);
} else {
wantedTiles[sourceKey][zKey] = tileRange;
}
} else {
var coordKey = tileCoord.toString();
if (!(sourceKey in wantedTiles)) {
wantedTiles[sourceKey] = {};
wantedTiles[sourceKey][zKey] = tileRange;
}
wantedTiles[sourceKey][coordKey] = true;
};

View File

@@ -393,6 +393,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
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) {
@@ -457,7 +458,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
this.renderedTileRange_ = null;
this.renderedFramebufferExtent_ = null;
frameState.animate = true;
this.updateWantedTiles(frameState.wantedTiles, tileSource, z, tileRange);
}
}