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,18 +1,20 @@
|
|||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import { FeatureSource, IndexedFeatureSource } from "../FeatureSource"
|
||||
import { FeatureSource, IndexedFeatureSource, UpdatableFeatureSource } from "../FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import DynamicTileSource from "../TiledFeatureSource/DynamicTileSource"
|
||||
|
||||
/**
|
||||
* The featureSourceMerger receives complete geometries from various sources.
|
||||
* If multiple sources contain the same object (as determined by 'id'), only one copy of them is retained
|
||||
*/
|
||||
export default class FeatureSourceMerger<Src extends FeatureSource = FeatureSource> implements IndexedFeatureSource {
|
||||
export default class FeatureSourceMerger<Src extends FeatureSource = FeatureSource>
|
||||
implements IndexedFeatureSource
|
||||
{
|
||||
public features: UIEventSource<Feature[]> = new UIEventSource([])
|
||||
public readonly featuresById: Store<Map<string, Feature>>
|
||||
protected readonly _featuresById: UIEventSource<Map<string, Feature>>
|
||||
private readonly _sources: Src[] = []
|
||||
protected readonly _sources: Src[]
|
||||
|
||||
/**
|
||||
* Merges features from different featureSources.
|
||||
* In case that multiple features have the same id, the latest `_version_number` will be used. Otherwise, we will take the last one
|
||||
|
@ -27,22 +29,25 @@ export default class FeatureSourceMerger<Src extends FeatureSource = FeatureSour
|
|||
self.addDataFromSources(sources)
|
||||
})
|
||||
}
|
||||
this.addDataFromSources(sources)
|
||||
this._sources = sources
|
||||
this.addDataFromSources(sources)
|
||||
}
|
||||
|
||||
public addSource(source: Src) {
|
||||
if (!source) {
|
||||
return
|
||||
}
|
||||
if (!source.features) {
|
||||
console.error("No source found in", source)
|
||||
}
|
||||
this._sources.push(source)
|
||||
source.features.addCallbackAndRun(() => {
|
||||
this.addDataFromSources(this._sources)
|
||||
})
|
||||
}
|
||||
|
||||
protected addDataFromSources(sources: Src[]){
|
||||
this.addData(sources.map(s => s.features.data))
|
||||
protected addDataFromSources(sources: Src[]) {
|
||||
this.addData(sources.map((s) => s.features.data))
|
||||
}
|
||||
|
||||
protected addData(sources: Feature[][]) {
|
||||
|
@ -93,3 +98,17 @@ export default class FeatureSourceMerger<Src extends FeatureSource = FeatureSour
|
|||
this._featuresById.setData(all)
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdatableFeatureSourceMerger<
|
||||
Src extends UpdatableFeatureSource = UpdatableFeatureSource
|
||||
>
|
||||
extends FeatureSourceMerger<Src>
|
||||
implements IndexedFeatureSource, UpdatableFeatureSource
|
||||
{
|
||||
constructor(...sources: Src[]) {
|
||||
super(...sources)
|
||||
}
|
||||
async updateAsync() {
|
||||
await Promise.all(this._sources.map((src) => src.updateAsync()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue