Separate method for updating the tile cache

This commit is contained in:
ahocevar
2013-06-20 18:38:03 +02:00
parent 3afd8b4242
commit 0aacf197bf
@@ -310,43 +310,27 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
resolution = view2DState.resolution, resolution = view2DState.resolution,
extent = frameState.extent, extent = frameState.extent,
layer = this.getVectorLayer(), layer = this.getVectorLayer(),
tileGrid = this.tileGrid_, tileGrid = this.tileGrid_;
resolutions, tileCoord, key, i;
// lazy tile grid creation // lazy tile grid creation
if (!frameState.viewHints[ol.ViewHint.ANIMATING]) { if (!frameState.viewHints[ol.ViewHint.ANIMATING]) {
// Avoid rendering issues at very high zoom levels // avoid rendering issues for very high zoom levels
var gridResolution = Math.max(resolution, var newResolution = Math.max(resolution, ol.renderer.canvas.MIN_RESOLUTION);
ol.renderer.canvas.MIN_RESOLUTION); var oldResolutions = goog.isNull(this.tileGrid_) ? [] :
if (goog.isNull(tileGrid)) { this.tileGrid_.getResolutions();
// start with the current resolution if (!goog.array.contains(oldResolutions, newResolution)) {
resolutions = [gridResolution];
} else if (!goog.array.contains(tileGrid.getResolutions(),
gridResolution)) {
// create a new tile grid, adding the current resolution, and update z
// tile coordinates in tile cache to match the new tile grid
var oldResolutions = tileGrid.getResolutions();
resolutions = [gridResolution].concat(oldResolutions);
resolutions.sort(function(a, b) { return b - a; });
var keys = this.tileCache_.getKeys();
for (i = keys.length - 1; i >= 0; --i) {
key = keys[i];
tileCoord = ol.TileCoord.createFromString(key);
tileCoord.z = goog.array.indexOf(resolutions,
oldResolutions[tileCoord.z]);
this.tileCache_.set(tileCoord.toString(), this.tileCache_.pop());
}
}
if (goog.isDef(resolutions)) {
tileGrid = new ol.tilegrid.TileGrid({ tileGrid = new ol.tilegrid.TileGrid({
origin: [0, 0], origin: [0, 0],
projection: view2DState.projection, projection: view2DState.projection,
resolutions: resolutions, resolutions: [newResolution].concat(oldResolutions)
.sort(function(a, b) { return b - a; }),
tileSize: [512, 512] tileSize: [512, 512]
}); });
this.updateTileCache_(oldResolutions, tileGrid.getResolutions());
this.tileGrid_ = tileGrid; this.tileGrid_ = tileGrid;
} }
} }
if (goog.isNull(tileGrid)) { if (goog.isNull(tileGrid)) {
// We should only get here when the first call to renderFrame happens during // We should only get here when the first call to renderFrame happens during
// an animation. Try again in the next renderFrame call. // an animation. Try again in the next renderFrame call.
@@ -439,7 +423,7 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
var tilesOnSketchCanvas = {}; var tilesOnSketchCanvas = {};
// TODO make gutter configurable? // TODO make gutter configurable?
var tileGutter = 15 * tileResolution; var tileGutter = 15 * tileResolution;
var tile, x, y; var tile, tileCoord, key, x, y;
// render features by geometry type // render features by geometry type
var filters = this.geometryFilters_, var filters = this.geometryFilters_,
numFilters = filters.length, numFilters = filters.length,
@@ -544,6 +528,25 @@ ol.renderer.canvas.VectorLayer.prototype.pruneTileCache_ = function() {
}; };
/**
* @private
* @param {Array.<number>} oldResolutions Resolutions of the old tile grid.
* @param {Array.<number>} newResolutions Resolutions of the new tile grid.
*/
ol.renderer.canvas.VectorLayer.prototype.updateTileCache_ =
function(oldResolutions, newResolutions) {
var keys = this.tileCache_.getKeys(),
tileCoord, key, i;
for (i = keys.length - 1; i >= 0; --i) {
key = keys[i];
tileCoord = ol.TileCoord.createFromString(key);
tileCoord.z = goog.array.indexOf(newResolutions,
oldResolutions[tileCoord.z]);
this.tileCache_.set(tileCoord.toString(), this.tileCache_.pop());
}
};
/** /**
* @type {number} * @type {number}
*/ */