forked from MapComplete/MapComplete
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:
parent
914c12ce21
commit
b7c6861484
2 changed files with 35 additions and 35 deletions
|
@ -29,7 +29,7 @@ export default class OverpassFeatureSource implements FeatureSource {
|
||||||
|
|
||||||
|
|
||||||
private readonly retries: UIEventSource<number> = new UIEventSource<number>(0);
|
private readonly retries: UIEventSource<number> = new UIEventSource<number>(0);
|
||||||
|
|
||||||
private readonly state: {
|
private readonly state: {
|
||||||
readonly locationControl: UIEventSource<Loc>,
|
readonly locationControl: UIEventSource<Loc>,
|
||||||
readonly layoutToUse: LayoutConfig,
|
readonly layoutToUse: LayoutConfig,
|
||||||
|
@ -39,6 +39,7 @@ export default class OverpassFeatureSource implements FeatureSource {
|
||||||
}
|
}
|
||||||
private readonly _isActive: UIEventSource<boolean>;
|
private readonly _isActive: UIEventSource<boolean>;
|
||||||
private readonly onBboxLoaded: (bbox: BBox, date: Date, layers: LayerConfig[], zoomlevel: number) => void;
|
private readonly onBboxLoaded: (bbox: BBox, date: Date, layers: LayerConfig[], zoomlevel: number) => void;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
state: {
|
state: {
|
||||||
readonly locationControl: UIEventSource<Loc>,
|
readonly locationControl: UIEventSource<Loc>,
|
||||||
|
@ -90,7 +91,7 @@ export default class OverpassFeatureSource implements FeatureSource {
|
||||||
}
|
}
|
||||||
const self = this;
|
const self = this;
|
||||||
this.updateAsync(paddedZoomLevel).then(bboxDate => {
|
this.updateAsync(paddedZoomLevel).then(bboxDate => {
|
||||||
if(bboxDate === undefined || self.onBboxLoaded === undefined){
|
if (bboxDate === undefined || self.onBboxLoaded === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [bbox, date, layers] = bboxDate
|
const [bbox, date, layers] = bboxDate
|
||||||
|
@ -109,41 +110,43 @@ export default class OverpassFeatureSource implements FeatureSource {
|
||||||
return undefined;
|
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 data: any = undefined
|
||||||
let date: Date = undefined
|
let date: Date = undefined
|
||||||
const overpassUrls = self.state.overpassUrl.data
|
|
||||||
let lastUsed = 0;
|
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 {
|
do {
|
||||||
try {
|
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);
|
const overpass = this.GetFilter(overpassUrls[lastUsed], layersToDownload);
|
||||||
|
|
||||||
if (overpass === undefined) {
|
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);
|
self.retries.setData(0);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,9 +24,6 @@ import Translations from "./i18n/Translations";
|
||||||
import SimpleAddUI from "./BigComponents/SimpleAddUI";
|
import SimpleAddUI from "./BigComponents/SimpleAddUI";
|
||||||
import StrayClickHandler from "../Logic/Actors/StrayClickHandler";
|
import StrayClickHandler from "../Logic/Actors/StrayClickHandler";
|
||||||
import Lazy from "./Base/Lazy";
|
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 {
|
export class DefaultGuiState {
|
||||||
public readonly welcomeMessageIsOpened;
|
public readonly welcomeMessageIsOpened;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue