Manual class transform
This commit is contained in:
@@ -11,46 +11,48 @@ import {fromKey, getKey} from './tilecoord.js';
|
||||
* @param {number=} opt_highWaterMark High water mark.
|
||||
* @struct
|
||||
*/
|
||||
const TileCache = function(opt_highWaterMark) {
|
||||
class TileCache {
|
||||
constructor(opt_highWaterMark) {
|
||||
|
||||
LRUCache.call(this, opt_highWaterMark);
|
||||
LRUCache.call(this, opt_highWaterMark);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object.<string, module:ol/TileRange>} usedTiles Used tiles.
|
||||
*/
|
||||
expireCache(usedTiles) {
|
||||
while (this.canExpireCache()) {
|
||||
const tile = this.peekLast();
|
||||
const 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.
|
||||
*/
|
||||
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.dispose();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(TileCache, LRUCache);
|
||||
|
||||
|
||||
/**
|
||||
* @param {!Object.<string, module:ol/TileRange>} usedTiles Used tiles.
|
||||
*/
|
||||
TileCache.prototype.expireCache = function(usedTiles) {
|
||||
while (this.canExpireCache()) {
|
||||
const tile = this.peekLast();
|
||||
const 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 = fromKey(key);
|
||||
const z = tileCoord[0];
|
||||
this.forEach(function(tile) {
|
||||
if (tile.tileCoord[0] !== z) {
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.dispose();
|
||||
}
|
||||
}, this);
|
||||
};
|
||||
export default TileCache;
|
||||
|
||||
Reference in New Issue
Block a user