Prune all except for the most recent z on URL change
This commit is contained in:
@@ -155,6 +155,7 @@ ol.source.UrlTile.prototype.setTileLoadFunction = function(tileLoadFunction) {
|
||||
*/
|
||||
ol.source.UrlTile.prototype.setTileUrlFunction = function(tileUrlFunction, opt_key) {
|
||||
this.tileUrlFunction = tileUrlFunction;
|
||||
this.tileCache.pruneExceptNewestZ();
|
||||
if (typeof opt_key !== 'undefined') {
|
||||
this.setKey(opt_key);
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@ goog.provide('ol.TileCache');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.structs.LRUCache');
|
||||
goog.require('ol.tilecoord');
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,3 +34,22 @@ ol.TileCache.prototype.expireCache = function(usedTiles) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Prune all tiles from the cache that don't have the same z as the newest tile.
|
||||
*/
|
||||
ol.TileCache.prototype.pruneExceptNewestZ = function() {
|
||||
if (this.getCount() === 0) {
|
||||
return;
|
||||
}
|
||||
var key = this.peekFirstKey();
|
||||
var tileCoord = ol.tilecoord.fromKey(key);
|
||||
var z = tileCoord[0];
|
||||
this.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(ol.tilecoord.getKey(tile.tileCoord));
|
||||
tile.dispose();
|
||||
}
|
||||
}, this);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user