Files
openlayers/src/ol/TileCache.js
Tim Schaub ad62739a6e Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
2018-01-12 00:50:30 -07:00

58 lines
1.3 KiB
JavaScript

/**
* @module ol/TileCache
*/
import {inherits} from './index.js';
import LRUCache from './structs/LRUCache.js';
import _ol_tilecoord_ from './tilecoord.js';
/**
* @constructor
* @extends {ol.structs.LRUCache.<ol.Tile>}
* @param {number=} opt_highWaterMark High water mark.
* @struct
*/
const TileCache = function(opt_highWaterMark) {
LRUCache.call(this, opt_highWaterMark);
};
inherits(TileCache, LRUCache);
/**
* @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
*/
TileCache.prototype.expireCache = function(usedTiles) {
let tile, zKey;
while (this.canExpireCache()) {
tile = this.peekLast();
zKey = tile.tileCoord[0].toString();
if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
break;
} else {
this.pop().dispose();
}
}
};
/**
* Prune all tiles from the cache that don't have the same z as the newest tile.
*/
TileCache.prototype.pruneExceptNewestZ = function() {
if (this.getCount() === 0) {
return;
}
const key = this.peekFirstKey();
const tileCoord = _ol_tilecoord_.fromKey(key);
const z = tileCoord[0];
this.forEach(function(tile) {
if (tile.tileCoord[0] !== z) {
this.remove(_ol_tilecoord_.getKey(tile.tileCoord));
tile.dispose();
}
}, this);
};
export default TileCache;