forked from MapComplete/MapComplete
FIx caching script, some cleanup
This commit is contained in:
parent
e922768f99
commit
5b513b1248
3 changed files with 141 additions and 102 deletions
|
@ -8,6 +8,9 @@ import GeoJsonSource from "../Sources/GeoJsonSource";
|
|||
import {BBox} from "../../BBox";
|
||||
|
||||
export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
||||
|
||||
private static whitelistCache = new Map<string, any>()
|
||||
|
||||
constructor(layer: FilteredLayer,
|
||||
registerLayer: (layer: FeatureSourceForLayer & Tiled) => void,
|
||||
state: {
|
||||
|
@ -30,18 +33,26 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
.replace("{x}_{y}.geojson", "overview.json")
|
||||
.replace("{layer}", layer.layerDef.id)
|
||||
|
||||
Utils.downloadJsonCached(whitelistUrl, 1000*60*60).then(
|
||||
json => {
|
||||
const data = new Map<number, Set<number>>();
|
||||
for (const x in json) {
|
||||
data.set(Number(x), new Set(json[x]))
|
||||
if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) {
|
||||
whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl)
|
||||
} else {
|
||||
Utils.downloadJsonCached(whitelistUrl, 1000 * 60 * 60).then(
|
||||
json => {
|
||||
const data = new Map<number, Set<number>>();
|
||||
for (const x in json) {
|
||||
if(x === "zoom"){
|
||||
continue
|
||||
}
|
||||
data.set(Number(x), new Set(json[x]))
|
||||
}
|
||||
console.log("The whitelist is", data, "based on ", json, "from", whitelistUrl)
|
||||
whitelist = data
|
||||
DynamicGeoJsonTileSource.whitelistCache.set(whitelistUrl, whitelist)
|
||||
}
|
||||
console.log("The whitelist is", data, "based on ", json, "from", whitelistUrl)
|
||||
whitelist = data
|
||||
}
|
||||
).catch(err => {
|
||||
console.warn("No whitelist found for ", layer.layerDef.id, err)
|
||||
})
|
||||
).catch(err => {
|
||||
console.warn("No whitelist found for ", layer.layerDef.id, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const seenIds = new Set<string>();
|
||||
|
@ -53,7 +64,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
if (whitelist !== undefined) {
|
||||
const isWhiteListed = whitelist.get(zxy[1])?.has(zxy[2])
|
||||
if (!isWhiteListed) {
|
||||
console.log("Not downloading tile", ...zxy, "as it is not on the whitelist")
|
||||
console.debug("Not downloading tile", ...zxy, "as it is not on the whitelist")
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
@ -77,4 +88,15 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
|
||||
}
|
||||
|
||||
public static RegisterWhitelist(url: string, json: any) {
|
||||
const data = new Map<number, Set<number>>();
|
||||
for (const x in json) {
|
||||
if(x === "zoom"){
|
||||
continue
|
||||
}
|
||||
data.set(Number(x), new Set(json[x]))
|
||||
}
|
||||
DynamicGeoJsonTileSource.whitelistCache.set(url, data)
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue