From baf41cb79da764e8ac12a0412e8af3f09a37d316 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 4 Jan 2021 22:59:11 +0100 Subject: [PATCH] Fixing adding multiple points --- InitUiElements.ts | 1 - .../FeatureDuplicatorPerLayer.ts | 11 +------- Logic/FeatureSource/FeatureSourceMerger.ts | 3 +++ Logic/FeatureSource/RememberingSource.ts | 27 ++++++++++--------- Models/Constants.ts | 2 +- UI/ShowDataLayer.ts | 1 - 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index 9ce75318f..a1cb4531c 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -419,7 +419,6 @@ export class InitUiElements { State.state.allElements.addElement(feature); }) MetaTagging.addMetatags(features); - console.log("ALL FEATURES", features); }) new ShowDataLayer(source.features, State.state.leafletMap, diff --git a/Logic/FeatureSource/FeatureDuplicatorPerLayer.ts b/Logic/FeatureSource/FeatureDuplicatorPerLayer.ts index 34aca439b..8b35ba338 100644 --- a/Logic/FeatureSource/FeatureDuplicatorPerLayer.ts +++ b/Logic/FeatureSource/FeatureDuplicatorPerLayer.ts @@ -13,27 +13,18 @@ export default class FeatureDuplicatorPerLayer implements FeatureSource { constructor(layers: { layerDef: LayerConfig }[], upstream: FeatureSource) { - let noPassthroughts = true; - for (const layer of layers) { - if (layer.layerDef.passAllFeatures) { - noPassthroughts = false; - break; - } - } - this.features = upstream.features.map(features => { const newFeatures: { feature: any, freshness: Date }[] = []; if(features === undefined){ return newFeatures; } - for (const f of features) { if (f.feature._matching_layer_id) { // Already matched previously // We simply add it newFeatures.push(f); - return; + continue; } diff --git a/Logic/FeatureSource/FeatureSourceMerger.ts b/Logic/FeatureSource/FeatureSourceMerger.ts index 2ea08c42b..2d6a2010b 100644 --- a/Logic/FeatureSource/FeatureSourceMerger.ts +++ b/Logic/FeatureSource/FeatureSourceMerger.ts @@ -17,6 +17,9 @@ 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){ + continue; + } for (const f of source.features.data) { const id = f.feature.properties.id+f.feature.geometry.type+f.feature._matching_layer_id; const oldV = all[id]; diff --git a/Logic/FeatureSource/RememberingSource.ts b/Logic/FeatureSource/RememberingSource.ts index 58628dfc3..7f95b8fed 100644 --- a/Logic/FeatureSource/RememberingSource.ts +++ b/Logic/FeatureSource/RememberingSource.ts @@ -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( 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(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]; }) } - + } \ No newline at end of file diff --git a/Models/Constants.ts b/Models/Constants.ts index a58a2c897..b13c38c01 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -1,7 +1,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.2.7-rc3"; + public static vNumber = "0.2.7-rc4"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/UI/ShowDataLayer.ts b/UI/ShowDataLayer.ts index 14839f0b9..04dc80af7 100644 --- a/UI/ShowDataLayer.ts +++ b/UI/ShowDataLayer.ts @@ -32,7 +32,6 @@ export default class ShowDataLayer { } function update() { - console.log("UPDATING!") if (features.data === undefined) { return; }