forked from openlayers/openlayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileCache.js
43 lines (38 loc) · 954 Bytes
/
TileCache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @module ol/TileCache
*/
import LRUCache from './structs/LRUCache.js';
import {fromKey, getKey} from './tilecoord.js';
class TileCache extends LRUCache {
/**
* @param {!Object<string, import("./TileRange.js").default>} 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;