forked from MapComplete/MapComplete
Download button: take advantage of MVT server, download button will now attempt to download everything
This commit is contained in:
parent
bccda67e1c
commit
e4eb8d6b52
21 changed files with 453 additions and 353 deletions
|
@ -1,5 +1,5 @@
|
|||
import { Feature } from "geojson"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { FeatureSource, UpdatableFeatureSource } from "../FeatureSource"
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import { Or } from "../../Tags/Or"
|
||||
|
@ -12,7 +12,7 @@ import { BBox } from "../../BBox"
|
|||
* A wrapper around the 'Overpass'-object.
|
||||
* It has more logic and will automatically fetch the data for the right bbox and the active layers
|
||||
*/
|
||||
export default class OverpassFeatureSource implements FeatureSource {
|
||||
export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
||||
/**
|
||||
* The last loaded features, as geojson
|
||||
*/
|
||||
|
@ -99,21 +99,15 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
) {
|
||||
return undefined
|
||||
}
|
||||
const result = await this.updateAsync()
|
||||
if (!result) {
|
||||
return
|
||||
}
|
||||
const [bounds, _, __] = result
|
||||
this._lastQueryBBox = bounds
|
||||
await this.updateAsync()
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the relevant data from overpass. Attempt to use a different server; only downloads the relevant layers
|
||||
* @private
|
||||
*/
|
||||
private async updateAsync(): Promise<[BBox, Date, LayerConfig[]]> {
|
||||
public async updateAsync(): Promise<void> {
|
||||
let data: any = undefined
|
||||
let date: Date = undefined
|
||||
let lastUsed = 0
|
||||
|
||||
const layersToDownload = []
|
||||
|
@ -172,7 +166,7 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
return undefined
|
||||
}
|
||||
this.runningQuery.setData(true)
|
||||
;[data, date] = await overpass.queryGeoJson(bounds)
|
||||
data = await overpass.queryGeoJson(bounds)[0]
|
||||
} catch (e) {
|
||||
self.retries.data++
|
||||
self.retries.ping()
|
||||
|
@ -205,10 +199,9 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
|
||||
console.log("Overpass returned", data.features.length, "features")
|
||||
self.features.setData(data.features)
|
||||
return [bounds, date, layersToDownload]
|
||||
this._lastQueryBBox = bounds
|
||||
} catch (e) {
|
||||
console.error("Got the overpass response, but could not process it: ", e, e.stack)
|
||||
return undefined
|
||||
} finally {
|
||||
self.retries.setData(0)
|
||||
self.runningQuery.setData(false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue