Add failsafe: overpass will stop redownloading if the features have been fetched by other sources and will pick the new bounds when redownloading

This commit is contained in:
pietervdvn 2021-10-20 01:26:39 +02:00
parent 914c12ce21
commit b7c6861484
2 changed files with 35 additions and 35 deletions

View file

@ -29,7 +29,7 @@ export default class OverpassFeatureSource implements FeatureSource {
private readonly retries: UIEventSource<number> = new UIEventSource<number>(0);
private readonly state: {
readonly locationControl: UIEventSource<Loc>,
readonly layoutToUse: LayoutConfig,
@ -39,6 +39,7 @@ export default class OverpassFeatureSource implements FeatureSource {
}
private readonly _isActive: UIEventSource<boolean>;
private readonly onBboxLoaded: (bbox: BBox, date: Date, layers: LayerConfig[], zoomlevel: number) => void;
constructor(
state: {
readonly locationControl: UIEventSource<Loc>,
@ -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 {

View file

@ -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;