New pruneTileRange method

This also adds an assert that cache values are an instance of
ol.Tile in expireCache, instead of doing a type cast. Later we
will want to enforce the ol.Tile type by overriding the set
method.
This commit is contained in:
ahocevar
2013-07-02 14:54:59 +02:00
parent ac67c10acd
commit d04c6f4c01

View File

@@ -1,6 +1,8 @@
goog.provide('ol.TileCache');
goog.require('goog.asserts');
goog.require('ol.Tile');
goog.require('ol.TileCoord');
goog.require('ol.TileRange');
goog.require('ol.structs.LRUCache');
@@ -46,7 +48,10 @@ ol.TileCache.prototype.canExpireCache = function() {
ol.TileCache.prototype.expireCache = function(usedTiles) {
var tile, zKey;
while (this.canExpireCache()) {
tile = /** @type {ol.Tile} */ (this.peekLast());
tile = (this.peekLast());
// TODO: Enforce ol.Tile in ol.TileCache#set
goog.asserts.assert(tile instanceof ol.Tile,
'ol.TileCache#expireCache only works with ol.Tile values.');
zKey = tile.tileCoord.z.toString();
if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
break;
@@ -55,3 +60,21 @@ ol.TileCache.prototype.expireCache = function(usedTiles) {
}
}
};
/**
* Remove a tile range from the cache, e.g. to invalidate tiles.
* @param {ol.TileRange} tileRange The tile range to prune.
*/
ol.TileCache.prototype.pruneTileRange = function(tileRange) {
var i = this.getCount(),
key;
while (i--) {
key = this.peekLastKey();
if (tileRange.contains(ol.TileCoord.createFromString(key))) {
this.pop();
} else {
this.get(key);
}
}
};