chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-11-14 02:21:10 +01:00
parent 47281a8d6c
commit 3fd14e82a0
84 changed files with 2093 additions and 1450 deletions

View file

@ -49,7 +49,7 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
},
options?: {
padToTiles?: Store<number>
isActive?: Store<boolean>,
isActive?: Store<boolean>
ignoreZoom?: boolean
}
) {
@ -57,7 +57,9 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
this._isActive = options?.isActive ?? new ImmutableStore(true)
this.padToZoomLevel = options?.padToTiles
const self = this
this._layersToDownload = options?.ignoreZoom? new ImmutableStore(state.layers) : state.zoom.map((zoom) => this.layersToDownload(zoom))
this._layersToDownload = options?.ignoreZoom
? new ImmutableStore(state.layers)
: state.zoom.map((zoom) => this.layersToDownload(zoom))
state.bounds.mapD(
(_) => {
@ -123,9 +125,11 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
let bounds: BBox
do {
try {
bounds = overrideBounds ?? this.state.bounds.data
?.pad(this.state.widenFactor)
?.expandToTileBounds(this.padToZoomLevel?.data)
bounds =
overrideBounds ??
this.state.bounds.data
?.pad(this.state.widenFactor)
?.expandToTileBounds(this.padToZoomLevel?.data)
if (!bounds) {
return
}

View file

@ -42,7 +42,7 @@ export default class ThemeSource extends FeatureSourceMerger {
backend: string,
isDisplayed: (id: string) => Store<boolean>,
mvtAvailableLayers: Set<string>,
fullNodeDatabaseSource?: FullNodeDatabaseSource,
fullNodeDatabaseSource?: FullNodeDatabaseSource
) {
const supportsForceDownload: UpdatableFeatureSource[] = []
@ -63,7 +63,7 @@ export default class ThemeSource extends FeatureSourceMerger {
{
isActive: isDisplayed(layer.id),
maxAge: layer.maxAgeOfCache,
},
}
)
fromCache.set(layer.id, src)
}
@ -82,7 +82,7 @@ export default class ThemeSource extends FeatureSourceMerger {
zoom,
backend,
featureSwitches,
fullNodeDatabaseSource,
fullNodeDatabaseSource
)
nonMvtSources.push(osmApiSource)
@ -91,14 +91,13 @@ export default class ThemeSource extends FeatureSourceMerger {
console.log(
"Layers ",
nonMvtLayers.map((l) => l.id),
" cannot be fetched from the cache server, defaulting to overpass/OSM-api",
" cannot be fetched from the cache server, defaulting to overpass/OSM-api"
)
overpassSource = ThemeSource.setupOverpass(osmLayers, bounds, zoom, featureSwitches)
nonMvtSources.push(overpassSource)
supportsForceDownload.push(overpassSource)
}
function setIsLoading() {
const loading = overpassSource?.runningQuery?.data || osmApiSource?.isRunning?.data
isLoading.setData(loading)
@ -108,40 +107,47 @@ export default class ThemeSource extends FeatureSourceMerger {
osmApiSource?.isRunning?.addCallbackAndRun(() => setIsLoading())
const geojsonSources: UpdatableFeatureSource[] = geojsonlayers.map((l) =>
ThemeSource.setupGeojsonSource(l, mapProperties, isDisplayed(l.id)),
ThemeSource.setupGeojsonSource(l, mapProperties, isDisplayed(l.id))
)
const downloadAllBounds: UIEventSource<BBox> = new UIEventSource<BBox>(undefined)
const downloadAll= new OverpassFeatureSource({
layers: layers.filter(l => l.isNormal()),
bounds: mapProperties.bounds,
zoom: mapProperties.zoom,
overpassUrl: featureSwitches.overpassUrl,
overpassTimeout: featureSwitches.overpassTimeout,
overpassMaxZoom: new ImmutableStore(99),
widenFactor: 0,
},{
ignoreZoom: true
})
const downloadAll = new OverpassFeatureSource(
{
layers: layers.filter((l) => l.isNormal()),
bounds: mapProperties.bounds,
zoom: mapProperties.zoom,
overpassUrl: featureSwitches.overpassUrl,
overpassTimeout: featureSwitches.overpassTimeout,
overpassMaxZoom: new ImmutableStore(99),
widenFactor: 0,
},
{
ignoreZoom: true,
}
)
super(...geojsonSources, ...Array.from(fromCache.values()), ...mvtSources, ...nonMvtSources, downloadAll)
super(
...geojsonSources,
...Array.from(fromCache.values()),
...mvtSources,
...nonMvtSources,
downloadAll
)
this.isLoading = isLoading
supportsForceDownload.push(...geojsonSources)
supportsForceDownload.push(...mvtSources) // Non-mvt sources are handled by overpass
this._mapBounds = mapProperties.bounds
this._downloadAll = downloadAll
this.supportsForceDownload = supportsForceDownload
}
private static setupMvtSource(
layer: LayerConfig,
mapProperties: { zoom: Store<number>; bounds: Store<BBox> },
isActive?: Store<boolean>,
isActive?: Store<boolean>
): UpdatableFeatureSource {
return new DynamicMvtileSource(layer, mapProperties, { isActive })
}
@ -149,12 +155,12 @@ export default class ThemeSource extends FeatureSourceMerger {
private static setupGeojsonSource(
layer: LayerConfig,
mapProperties: { zoom: Store<number>; bounds: Store<BBox> },
isActiveByFilter?: Store<boolean>,
isActiveByFilter?: Store<boolean>
): UpdatableFeatureSource {
const source = layer.source
const isActive = mapProperties.zoom.map(
(z) => (isActiveByFilter?.data ?? true) && z >= layer.minzoom,
[isActiveByFilter],
[isActiveByFilter]
)
if (source.geojsonZoomLevel === undefined) {
// This is a 'load everything at once' geojson layer
@ -170,7 +176,7 @@ export default class ThemeSource extends FeatureSourceMerger {
zoom: Store<number>,
backend: string,
featureSwitches: FeatureSwitchState,
fullNodeDatabase: FullNodeDatabaseSource,
fullNodeDatabase: FullNodeDatabaseSource
): OsmFeatureSource | undefined {
if (osmLayers.length == 0) {
return undefined
@ -204,7 +210,7 @@ export default class ThemeSource extends FeatureSourceMerger {
osmLayers: LayerConfig[],
bounds: Store<BBox>,
zoom: Store<number>,
featureSwitches: FeatureSwitchState,
featureSwitches: FeatureSwitchState
): OverpassFeatureSource | undefined {
if (osmLayers.length == 0) {
return undefined
@ -233,14 +239,14 @@ export default class ThemeSource extends FeatureSourceMerger {
{
padToTiles: zoom.map((zoom) => Math.min(15, zoom + 1)),
isActive,
},
}
)
}
public async downloadAll() {
console.log("Downloading all data:")
await this._downloadAll.updateAsync(this._mapBounds.data)
// await Promise.all(this.supportsForceDownload.map((i) => i.updateAsync()))
// await Promise.all(this.supportsForceDownload.map((i) => i.updateAsync()))
console.log("Done")
}
}