forked from MapComplete/MapComplete
Refactoring: fix GPX-track view
This commit is contained in:
parent
4172af6a72
commit
c6e12fdd6b
23 changed files with 217 additions and 347 deletions
|
@ -5,11 +5,19 @@ import { UIEventSource } from "../../UIEventSource"
|
|||
* Constructs a UIEventStore for the properties of every Feature, indexed by id
|
||||
*/
|
||||
export default class FeaturePropertiesStore {
|
||||
private readonly _source: FeatureSource & IndexedFeatureSource
|
||||
private readonly _elements = new Map<string, UIEventSource<Record<string, string>>>()
|
||||
|
||||
constructor(source: FeatureSource & IndexedFeatureSource) {
|
||||
this._source = source
|
||||
constructor(...sources: FeatureSource[]) {
|
||||
for (const source of sources) {
|
||||
this.trackFeatureSource(source)
|
||||
}
|
||||
}
|
||||
|
||||
public getStore(id: string): UIEventSource<Record<string, string>> {
|
||||
return this._elements.get(id)
|
||||
}
|
||||
|
||||
public trackFeatureSource(source: FeatureSource) {
|
||||
const self = this
|
||||
source.features.addCallbackAndRunD((features) => {
|
||||
console.log("Re-indexing features")
|
||||
|
@ -41,14 +49,6 @@ export default class FeaturePropertiesStore {
|
|||
})
|
||||
}
|
||||
|
||||
public getStore(id: string): UIEventSource<Record<string, string>> {
|
||||
return this._elements.get(id)
|
||||
}
|
||||
|
||||
public addSpecial(id: string, store: UIEventSource<Record<string, string>>) {
|
||||
this._elements.set(id, store)
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the tags of the old properties object, returns true if a change was made.
|
||||
* Metatags are overriden if they are in the new properties, but not removed
|
||||
|
@ -87,7 +87,6 @@ export default class FeaturePropertiesStore {
|
|||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
public addAlias(oldId: string, newId: string): void {
|
||||
console.log("FeaturePropertiesStore: adding alias for", oldId, newId)
|
||||
if (newId === undefined) {
|
||||
// We removed the node/way/relation with type 'type' and id 'oldId' on openstreetmap!
|
||||
const element = this._elements.get(oldId)
|
||||
|
|
|
@ -3,11 +3,11 @@ import FilteredLayer from "../../Models/FilteredLayer"
|
|||
import { BBox } from "../BBox"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
export interface FeatureSource {
|
||||
features: Store<Feature[]>
|
||||
export interface FeatureSource<T extends Feature = Feature> {
|
||||
features: Store<T[]>
|
||||
}
|
||||
export interface WritableFeatureSource extends FeatureSource {
|
||||
features: UIEventSource<Feature[]>
|
||||
export interface WritableFeatureSource<T extends Feature = Feature> extends FeatureSource<T> {
|
||||
features: UIEventSource<T[]>
|
||||
}
|
||||
|
||||
export interface Tiled {
|
||||
|
|
|
@ -61,7 +61,7 @@ export default class FilteringFeatureSource implements FeatureSource {
|
|||
const includedFeatureIds = new Set<string>()
|
||||
const globalFilters = self._globalFilters?.data?.map((f) => f)
|
||||
const newFeatures = (features ?? []).filter((f) => {
|
||||
self.registerCallback(f)
|
||||
self.registerCallback(f.properties.id)
|
||||
|
||||
if (!layer.isShown(f.properties, globalFilters)) {
|
||||
return false
|
||||
|
@ -91,11 +91,11 @@ export default class FilteringFeatureSource implements FeatureSource {
|
|||
this.features.setData(newFeatures)
|
||||
}
|
||||
|
||||
private registerCallback(feature: any) {
|
||||
private registerCallback(featureId: string) {
|
||||
if (this._fetchStore === undefined) {
|
||||
return
|
||||
}
|
||||
const src = this._fetchStore(feature)
|
||||
const src = this._fetchStore(featureId)
|
||||
if (src == undefined) {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue