You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB

/**
* @module ol/TileCache
*/
import LRUCache from './structs/LRUCache.js';
import {fromKey, getKey} from './tilecoord.js';
class TileCache extends LRUCache {
clear() {
while (this.getCount() > 0) {
this.pop().release();
}
super.clear();
}
/**
* @param {!Object<string, boolean>} usedTiles Used tiles.
*/
expireCache(usedTiles) {
while (this.canExpireCache()) {
const tile = this.peekLast();
if (tile.getKey() in usedTiles) {
break;
} else {
this.pop().release();
}
}
}
/**
* Prune all tiles from the cache that don't have the same z as the newest tile.
*/
pruneExceptNewestZ() {
if (this.getCount() === 0) {
return;
}
const key = this.peekFirstKey();
const tileCoord = fromKey(key);
const z = tileCoord[0];
this.forEach(
function (tile) {
if (tile.tileCoord[0] !== z) {
this.remove(getKey(tile.tileCoord));
tile.release();
}
}.bind(this)
);
}
}
export default TileCache;