From d04c6f4c017bc18ec336abaffbca5a34cddb687e Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 2 Jul 2013 14:54:59 +0200 Subject: [PATCH] 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. --- src/ol/tilecache.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ol/tilecache.js b/src/ol/tilecache.js index 09cf94c81d..61d2a940ac 100644 --- a/src/ol/tilecache.js +++ b/src/ol/tilecache.js @@ -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); + } + } +};