forked from MapComplete/MapComplete
More refactoring: using a decent, configurable datapipeline now
This commit is contained in:
parent
6ac8ec84e4
commit
e42a668c4a
17 changed files with 434 additions and 265 deletions
24
Logic/FeatureSource/RememberingSource.ts
Normal file
24
Logic/FeatureSource/RememberingSource.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Every previously added point is remembered, but new points are added
|
||||
*/
|
||||
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}[]>([]);
|
||||
|
||||
constructor(source: FeatureSource) {
|
||||
const self = this;
|
||||
source.features.addCallbackAndRun(features => {
|
||||
if(features === undefined){
|
||||
return;
|
||||
}
|
||||
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);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue