From b7c68614841c89036c9c215256b96f0ec420d1bd Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 20 Oct 2021 01:26:39 +0200 Subject: [PATCH] Add failsafe: overpass will stop redownloading if the features have been fetched by other sources and will pick the new bounds when redownloading --- Logic/Actors/OverpassFeatureSource.ts | 67 ++++++++++++++------------- UI/DefaultGUI.ts | 3 -- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Logic/Actors/OverpassFeatureSource.ts b/Logic/Actors/OverpassFeatureSource.ts index 5062133b6..e48ae2a3f 100644 --- a/Logic/Actors/OverpassFeatureSource.ts +++ b/Logic/Actors/OverpassFeatureSource.ts @@ -29,7 +29,7 @@ export default class OverpassFeatureSource implements FeatureSource { private readonly retries: UIEventSource = new UIEventSource(0); - + private readonly state: { readonly locationControl: UIEventSource, readonly layoutToUse: LayoutConfig, @@ -39,6 +39,7 @@ export default class OverpassFeatureSource implements FeatureSource { } private readonly _isActive: UIEventSource; private readonly onBboxLoaded: (bbox: BBox, date: Date, layers: LayerConfig[], zoomlevel: number) => void; + constructor( state: { readonly locationControl: UIEventSource, @@ -90,7 +91,7 @@ export default class OverpassFeatureSource implements FeatureSource { } const self = this; this.updateAsync(paddedZoomLevel).then(bboxDate => { - if(bboxDate === undefined || self.onBboxLoaded === undefined){ + if (bboxDate === undefined || self.onBboxLoaded === undefined) { return; } const [bbox, date, layers] = bboxDate @@ -109,41 +110,43 @@ export default class OverpassFeatureSource implements FeatureSource { return undefined; } - const bounds = this.state.currentBounds.data?.pad(this.state.layoutToUse.widenFactor)?.expandToTileBounds(padToZoomLevel); - - if (bounds === undefined) { - return undefined; - } - const self = this; - - - const layersToDownload = [] - for (const layer of this.state.layoutToUse.layers) { - - if (typeof (layer) === "string") { - throw "A layer was not expanded!" - } - if(this.state.locationControl.data.zoom < layer.minzoom){ - continue; - } - if (layer.doNotDownload) { - continue; - } - if (layer.source.geojsonSource !== undefined) { - // Not our responsibility to download this layer! - continue; - } - layersToDownload.push(layer) - } - let data: any = undefined let date: Date = undefined - const overpassUrls = self.state.overpassUrl.data let lastUsed = 0; + + + const layersToDownload = [] + for (const layer of this.state.layoutToUse.layers) { + + if (typeof (layer) === "string") { + throw "A layer was not expanded!" + } + if (this.state.locationControl.data.zoom < layer.minzoom) { + continue; + } + if (layer.doNotDownload) { + continue; + } + if (layer.source.geojsonSource !== undefined) { + // Not our responsibility to download this layer! + continue; + } + layersToDownload.push(layer) + } + + const self = this; + const overpassUrls = self.state.overpassUrl.data + let bounds : BBox do { try { - + + bounds = this.state.currentBounds.data?.pad(this.state.layoutToUse.widenFactor)?.expandToTileBounds(padToZoomLevel); + + if (bounds === undefined) { + return undefined; + } + const overpass = this.GetFilter(overpassUrls[lastUsed], layersToDownload); if (overpass === undefined) { @@ -175,7 +178,7 @@ export default class OverpassFeatureSource implements FeatureSource { } } } - } while (data === undefined); + } while (data === undefined && this._isActive.data); self.retries.setData(0); try { diff --git a/UI/DefaultGUI.ts b/UI/DefaultGUI.ts index c6416fe39..fc195f90d 100644 --- a/UI/DefaultGUI.ts +++ b/UI/DefaultGUI.ts @@ -24,9 +24,6 @@ import Translations from "./i18n/Translations"; import SimpleAddUI from "./BigComponents/SimpleAddUI"; import StrayClickHandler from "../Logic/Actors/StrayClickHandler"; import Lazy from "./Base/Lazy"; -import ShowDataMultiLayer from "./ShowDataLayer/ShowDataMultiLayer"; -import StaticFeatureSource from "../Logic/FeatureSource/Sources/StaticFeatureSource"; -import FilteredLayer from "../Models/FilteredLayer"; export class DefaultGuiState { public readonly welcomeMessageIsOpened;