Simplify handling of id rewrites by centralizing them to the changesethandler (which improves testability too), fixes a part of #564

This commit is contained in:
Pieter Vander Vennet 2022-04-08 04:18:53 +02:00
parent c3f3f69c3b
commit 9238f0f381
7 changed files with 232 additions and 96 deletions

View file

@ -49,6 +49,29 @@ export class ElementStorage {
return this._elements.has(id);
}
addAlias(oldId: string, newId: string){
if (newId === undefined) {
// We removed the node/way/relation with type 'type' and id 'oldId' on openstreetmap!
const element = this.getEventSourceById(oldId);
element.data._deleted = "yes"
element.ping();
return;
}
if (oldId == newId) {
return undefined;
}
const element = this.getEventSourceById( oldId);
if (element === undefined) {
// Element to rewrite not found, probably a node or relation that is not rendered
return undefined
}
element.data.id = newId;
this.addElementById(newId, element);
this.ContainingFeatures.set(newId, this.ContainingFeatures.get( oldId))
element.ping();
}
private addOrGetById(elementId: string, newProperties: any): UIEventSource<any> {
if (!this._elements.has(elementId)) {
const eventSource = new UIEventSource<any>(newProperties, "tags of " + elementId);