forked from MapComplete/MapComplete
Fixing adding multiple points
This commit is contained in:
parent
32bc1433b4
commit
baf41cb79d
6 changed files with 20 additions and 25 deletions
|
@ -4,21 +4,24 @@
|
|||
import FeatureSource from "./FeatureSource";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
export default class RememberingSource implements FeatureSource{
|
||||
features: UIEventSource<{feature: any, freshness: Date}[]> = new UIEventSource<{feature: any, freshness: Date}[]>([]);
|
||||
|
||||
export default class RememberingSource implements FeatureSource {
|
||||
features: UIEventSource<{ feature: any, freshness: Date }[]>;
|
||||
|
||||
constructor(source: FeatureSource) {
|
||||
const self = this;
|
||||
source.features.addCallbackAndRun(features => {
|
||||
if(features === undefined){
|
||||
return;
|
||||
const empty = [];
|
||||
this.features = source.features.map(features => {
|
||||
const oldFeatures = self.features?.data ?? empty;
|
||||
if (features === undefined) {
|
||||
return oldFeatures;
|
||||
}
|
||||
const ids = new Set<string>( features.map(f => f.feature.properties.id+f.feature.geometry.type));
|
||||
const newList = features.concat(
|
||||
self.features.data.filter(old => !ids.has(old.feature.properties.id+old.feature.geometry.type))
|
||||
)
|
||||
self.features.setData(newList);
|
||||
|
||||
// Then new ids
|
||||
const ids = new Set<string>(features.map(f => f.feature.properties.id + f.feature.geometry.type));
|
||||
// the old data
|
||||
const oldData = oldFeatures.filter(old => !ids.has(old.feature.properties.id + old.feature.geometry.type))
|
||||
return [...features, ...oldData];
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue