Add names to feature sources, fix that old, cached geometries get changed when a newer version is loaded

This commit is contained in:
Pieter Vander Vennet 2021-04-23 12:55:38 +02:00
parent 6234d26bac
commit 141d4db028
14 changed files with 60 additions and 43 deletions

View file

@ -3,13 +3,15 @@ import {UIEventSource} from "../UIEventSource";
export default class FeatureSourceMerger implements FeatureSource {
public features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{feature: any; freshness: Date}[]>([]);
public features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>([]);
public readonly name;
private readonly _sources: FeatureSource[];
constructor(sources: FeatureSource[]) {
this._sources = sources;
this.name = "SourceMerger of (" + sources.map(s => s.name).join(", ") + ")"
const self = this;
for (let i = 0; i < sources.length; i++){
for (let i = 0; i < sources.length; i++) {
let source = sources[i];
source.features.addCallback(() => {
self.Update();
@ -21,17 +23,17 @@ export default class FeatureSourceMerger implements FeatureSource {
private Update() {
let all = {}; // Mapping 'id' -> {feature, freshness}
for (const source of this._sources) {
if(source?.features?.data === undefined){
if (source?.features?.data === undefined) {
continue;
}
for (const f of source.features.data) {
const id = f.feature.properties.id+f.feature.geometry.type+f.feature._matching_layer_id;
const id = f.feature.properties.id;
const oldV = all[id];
if(oldV === undefined){
if (oldV === undefined) {
all[id] = f;
}else{
if(oldV.freshness < f.freshness){
all[id]=f;
} else {
if (oldV.freshness < f.freshness) {
all[id] = f;
}
}
}