Add license info, fix non-updating values after reopening popups

This commit is contained in:
Pieter Vander Vennet 2021-04-17 23:36:46 +02:00
parent 576fd8ff40
commit 7b47af8978
11 changed files with 71 additions and 42 deletions

View file

@ -5,14 +5,14 @@ import {UIEventSource} from "./UIEventSource";
export class ElementStorage {
private _elements = [];
private _elements = new Map<string, UIEventSource<any>>();
constructor() {
}
addElementById(id: string, eventSource: UIEventSource<any>) {
this._elements[id] = eventSource;
this._elements.set(id, eventSource);
}
/**
@ -23,14 +23,13 @@ export class ElementStorage {
*/
addOrGetElement(feature: any): UIEventSource<any> {
const elementId = feature.properties.id;
if (elementId in this._elements) {
const es = this._elements[elementId];
if (this._elements.has(elementId)) {
const es = this._elements.get(elementId);
if (es.data == feature.properties) {
// Reference comparison gives the same object! we can just return the event source
return es;
}
const keptKeys = es.data;
// The element already exists
// We add all the new keys to the old keys
@ -49,15 +48,20 @@ export class ElementStorage {
return es;
} else {
const eventSource = new UIEventSource<any>(feature.properties, "tags of " + feature.properties.id);
this._elements[feature.properties.id] = eventSource;
this._elements.set(feature.properties.id, eventSource);
return eventSource;
}
}
getEventSourceById(elementId): UIEventSource<any> {
if (elementId in this._elements) {
return this._elements[elementId];
if (this._elements.has(elementId)) {
return this._elements.get(elementId);
}
console.error("Can not find eventsource with id ", elementId);
return undefined;
}
has(id) {
return this._elements.has(id);
}
}