forked from MapComplete/MapComplete
Fix await which causes hanging map in fallback mode
This commit is contained in:
parent
c300d90128
commit
497fa4ccdf
1 changed files with 45 additions and 45 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { Feature } from "geojson"
|
import { Feature } from "geojson"
|
||||||
import { FeatureSource, UpdatableFeatureSource } from "../FeatureSource"
|
import { UpdatableFeatureSource } from "../FeatureSource"
|
||||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||||
import { Or } from "../../Tags/Or"
|
import { Or } from "../../Tags/Or"
|
||||||
|
@ -59,49 +59,6 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the 'Overpass'-object for the given layers
|
|
||||||
* @param interpreterUrl
|
|
||||||
* @param layersToDownload
|
|
||||||
* @constructor
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
private GetFilter(interpreterUrl: string, layersToDownload: LayerConfig[]): Overpass {
|
|
||||||
let filters: TagsFilter[] = layersToDownload.map((layer) => layer.source.osmTags)
|
|
||||||
filters = Utils.NoNull(filters)
|
|
||||||
if (filters.length === 0) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
return new Overpass(new Or(filters), [], interpreterUrl, this.state.overpassTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
private async updateAsyncIfNeeded(): Promise<void> {
|
|
||||||
if (!this._isActive?.data) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (this.runningQuery.data) {
|
|
||||||
console.log("Still running a query, not updating")
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.timeout.data > 0) {
|
|
||||||
console.log("Still in timeout - not updating")
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
const requestedBounds = this.state.bounds.data
|
|
||||||
if (
|
|
||||||
this._lastQueryBBox !== undefined &&
|
|
||||||
requestedBounds.isContainedIn(this._lastQueryBBox)
|
|
||||||
) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
await this.updateAsync()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download the relevant data from overpass. Attempt to use a different server; only downloads the relevant layers
|
* Download the relevant data from overpass. Attempt to use a different server; only downloads the relevant layers
|
||||||
* @private
|
* @private
|
||||||
|
@ -166,7 +123,7 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
this.runningQuery.setData(true)
|
this.runningQuery.setData(true)
|
||||||
data = await overpass.queryGeoJson(bounds)[0]
|
data = (await overpass.queryGeoJson(bounds))[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
self.retries.data++
|
self.retries.data++
|
||||||
self.retries.ping()
|
self.retries.ping()
|
||||||
|
@ -207,4 +164,47 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
||||||
self.runningQuery.setData(false)
|
self.runningQuery.setData(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the 'Overpass'-object for the given layers
|
||||||
|
* @param interpreterUrl
|
||||||
|
* @param layersToDownload
|
||||||
|
* @constructor
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private GetFilter(interpreterUrl: string, layersToDownload: LayerConfig[]): Overpass {
|
||||||
|
let filters: TagsFilter[] = layersToDownload.map((layer) => layer.source.osmTags)
|
||||||
|
filters = Utils.NoNull(filters)
|
||||||
|
if (filters.length === 0) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return new Overpass(new Or(filters), [], interpreterUrl, this.state.overpassTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private async updateAsyncIfNeeded(): Promise<void> {
|
||||||
|
if (!this._isActive?.data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.runningQuery.data) {
|
||||||
|
console.log("Still running a query, not updating")
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.timeout.data > 0) {
|
||||||
|
console.log("Still in timeout - not updating")
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const requestedBounds = this.state.bounds.data
|
||||||
|
if (
|
||||||
|
this._lastQueryBBox !== undefined &&
|
||||||
|
requestedBounds.isContainedIn(this._lastQueryBBox)
|
||||||
|
) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
await this.updateAsync()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue