Add flag to generate new items only once

This commit is contained in:
Pieter Vander Vennet 2021-07-18 17:50:35 +02:00
parent 9c9be0918b
commit 9f91d30147
2 changed files with 47 additions and 46 deletions

View file

@ -13,7 +13,9 @@ export default class ChangeApplicator implements FeatureSource {
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>; public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name: string; public readonly name: string;
constructor(source: FeatureSource, changes: Changes) { constructor(source: FeatureSource, changes: Changes, mode?: {
generateNewGeometries: boolean
}) {
this.name = "ChangesApplied(" + source.name + ")" this.name = "ChangesApplied(" + source.name + ")"
this.features = source.features this.features = source.features
@ -21,10 +23,10 @@ export default class ChangeApplicator implements FeatureSource {
const self = this; const self = this;
let runningUpdate = false; let runningUpdate = false;
source.features.addCallbackAndRunD(features => { source.features.addCallbackAndRunD(features => {
if(runningUpdate){ if (runningUpdate) {
return; // No need to ping again return; // No need to ping again
} }
ChangeApplicator.ApplyChanges(features, changes.pendingChanges.data) ChangeApplicator.ApplyChanges(features, changes.pendingChanges.data, mode)
seenChanges.clear() seenChanges.clear()
}) })
@ -33,7 +35,7 @@ export default class ChangeApplicator implements FeatureSource {
changes = changes.filter(ch => !seenChanges.has(ch)) changes = changes.filter(ch => !seenChanges.has(ch))
changes.forEach(c => seenChanges.add(c)) changes.forEach(c => seenChanges.add(c))
console.log("Called back", changes) console.log("Called back", changes)
ChangeApplicator.ApplyChanges(self.features.data, changes) ChangeApplicator.ApplyChanges(self.features.data, changes, mode)
source.features.ping() source.features.ping()
runningUpdate = false; runningUpdate = false;
}) })
@ -45,9 +47,9 @@ export default class ChangeApplicator implements FeatureSource {
/** /**
* Returns true if the geometry is changed and the source should be pinged * Returns true if the geometry is changed and the source should be pinged
*/ */
private static ApplyChanges(features: {feature: any, freshness: Date}[], cs: ChangeDescription[]): boolean { private static ApplyChanges(features: { feature: any; freshness: Date }[], cs: ChangeDescription[], mode: { generateNewGeometries: boolean }): boolean {
if (cs.length === 0 || features === undefined ) { if (cs.length === 0 || features === undefined) {
return ; return;
} }
console.log("Applying changes ", this.name, cs) console.log("Applying changes ", this.name, cs)
@ -75,13 +77,15 @@ export default class ChangeApplicator implements FeatureSource {
// First, create the new features - they have a negative ID // First, create the new features - they have a negative ID
// We don't set the properties yet though // We don't set the properties yet though
if (mode?.generateNewGeometries) {
changesPerId.forEach(cs => { changesPerId.forEach(cs => {
cs.forEach(change => { cs
.forEach(change => {
if (change.id >= 0) { if (change.id >= 0) {
return; // Nothing to do here, already created return; // Nothing to do here, already created
} }
if(change.changes === undefined){ if (change.changes === undefined) {
// An update to the object - not the actual created // An update to the object - not the actual created
return; return;
} }
@ -113,7 +117,7 @@ export default class ChangeApplicator implements FeatureSource {
} }
}) })
}) })
}
for (const feature of features) { for (const feature of features) {
const f = feature.feature; const f = feature.feature;
@ -133,9 +137,6 @@ export default class ChangeApplicator implements FeatureSource {
// Apply tag changes and ping the consumers // Apply tag changes and ping the consumers
const k = kv.k const k = kv.k
let v = kv.v let v = kv.v
if (v === "") {
v = undefined;
}
f.properties[k] = v; f.properties[k] = v;
} }

View file

@ -43,7 +43,7 @@ export default class FeaturePipeline implements FeatureSource {
new FeatureDuplicatorPerLayer(flayers, new FeatureDuplicatorPerLayer(flayers,
new RegisteringFeatureSource( new RegisteringFeatureSource(
new ChangeApplicator( new ChangeApplicator(
updater, changes updater, changes, {generateNewGeometries: true}
)) ))
)), layout)); )), layout));