Merge pull request #226 from twpayne/preserve-low-resolution-tiles

Preserve low resolution tiles
This commit is contained in:
Tom Payne
2013-02-22 02:14:41 -08:00
6 changed files with 55 additions and 16 deletions
@@ -199,6 +199,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
} }
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange); this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent);
this.scheduleExpireCache(frameState, tileSource); this.scheduleExpireCache(frameState, tileSource);
var transform = this.transform_; var transform = this.transform_;
@@ -217,6 +217,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
} }
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange); this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent);
this.scheduleExpireCache(frameState, tileSource); this.scheduleExpireCache(frameState, tileSource);
}; };
+15 -16
View File
@@ -14,7 +14,6 @@ goog.require('ol.TileState');
goog.require('ol.layer.Layer'); goog.require('ol.layer.Layer');
goog.require('ol.layer.LayerProperty'); goog.require('ol.layer.LayerProperty');
goog.require('ol.layer.LayerState'); goog.require('ol.layer.LayerState');
goog.require('ol.source.Source');
goog.require('ol.source.TileSource'); goog.require('ol.source.TileSource');
@@ -222,24 +221,24 @@ ol.renderer.Layer.prototype.updateAttributions =
/** /**
* @protected * @protected
* @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles. * @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles.
* @param {ol.source.Source} source Source. * @param {ol.source.TileSource} tileSource Tile source.
* @param {number} z Z. * @param {number} z Z.
* @param {ol.TileRange} tileRange Tile range. * @param {ol.TileRange} tileRange Tile range.
*/ */
ol.renderer.Layer.prototype.updateUsedTiles = ol.renderer.Layer.prototype.updateUsedTiles =
function(usedTiles, source, z, tileRange) { function(usedTiles, tileSource, z, tileRange) {
// FIXME should we use tilesToDrawByZ instead? // FIXME should we use tilesToDrawByZ instead?
var sourceKey = goog.getUid(source).toString(); var tileSourceKey = goog.getUid(tileSource).toString();
var zKey = z.toString(); var zKey = z.toString();
if (sourceKey in usedTiles) { if (tileSourceKey in usedTiles) {
if (zKey in usedTiles[sourceKey]) { if (zKey in usedTiles[tileSourceKey]) {
usedTiles[sourceKey][zKey].extend(tileRange); usedTiles[tileSourceKey][zKey].extend(tileRange);
} else { } else {
usedTiles[sourceKey][zKey] = tileRange; usedTiles[tileSourceKey][zKey] = tileRange;
} }
} else { } else {
usedTiles[sourceKey] = {}; usedTiles[tileSourceKey] = {};
usedTiles[sourceKey][zKey] = tileRange; usedTiles[tileSourceKey][zKey] = tileRange;
} }
}; };
@@ -247,15 +246,15 @@ ol.renderer.Layer.prototype.updateUsedTiles =
/** /**
* @protected * @protected
* @param {Object.<string, Object.<string, boolean>>} wantedTiles Wanted tiles. * @param {Object.<string, Object.<string, boolean>>} wantedTiles Wanted tiles.
* @param {ol.source.Source} source Source. * @param {ol.source.TileSource} tileSource Tile source.
* @param {ol.TileCoord} tileCoord Tile coordinate. * @param {ol.TileCoord} tileCoord Tile coordinate.
*/ */
ol.renderer.Layer.prototype.updateWantedTiles = ol.renderer.Layer.prototype.updateWantedTiles =
function(wantedTiles, source, tileCoord) { function(wantedTiles, tileSource, tileCoord) {
var sourceKey = goog.getUid(source).toString(); var tileSourceKey = goog.getUid(tileSource).toString();
var coordKey = tileCoord.toString(); var coordKey = tileCoord.toString();
if (!(sourceKey in wantedTiles)) { if (!(tileSourceKey in wantedTiles)) {
wantedTiles[sourceKey] = {}; wantedTiles[tileSourceKey] = {};
} }
wantedTiles[sourceKey][coordKey] = true; wantedTiles[tileSourceKey][coordKey] = true;
}; };
@@ -459,6 +459,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
} }
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange); this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent);
this.scheduleExpireCache(frameState, tileSource); this.scheduleExpireCache(frameState, tileSource);
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_); goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
+11
View File
@@ -109,3 +109,14 @@ ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
ol.source.ImageTileSource.prototype.getTileCoordUrl = function(tileCoord) { ol.source.ImageTileSource.prototype.getTileCoordUrl = function(tileCoord) {
return this.tileUrlFunction(tileCoord); return this.tileUrlFunction(tileCoord);
}; };
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.useTile = function(tileCoord) {
var key = tileCoord.toString();
if (this.tileCache_.containsKey(key)) {
this.tileCache_.get(key);
}
};
+26
View File
@@ -119,3 +119,29 @@ ol.source.TileSource.prototype.getTile = goog.abstractMethod;
ol.source.TileSource.prototype.getTileGrid = function() { ol.source.TileSource.prototype.getTileGrid = function() {
return this.tileGrid; return this.tileGrid;
}; };
/**
* @param {number} z Z.
* @param {ol.Extent} extent Extent.
*/
ol.source.TileSource.prototype.useLowResolutionTiles = function(z, extent) {
var tileGrid = this.getTileGrid();
var tileRange, x, y, zKey;
// FIXME this should loop up to tileGrid's minZ when implemented
for (; z >= 0; --z) {
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
this.useTile(z + '/' + x + '/' + y);
}
}
}
};
/**
* Marks a tile coord as being used, without triggering a load.
* @param {string} tileCoordKey Tile coordinate key.
*/
ol.source.TileSource.prototype.useTile = goog.nullFunction;