From 7b47af8978ce417b111b3aac01ccc60c13660adf Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 17 Apr 2021 23:36:46 +0200 Subject: [PATCH] Add license info, fix non-updating values after reopening popups --- Logic/Actors/TitleHandler.ts | 9 ++-- Logic/ElementStorage.ts | 20 +++++---- Logic/FeatureSource/LocalStorageSaver.ts | 7 ++-- .../FeatureSource/MetaTaggingFeatureSource.ts | 7 +++- Logic/Osm/Changes.ts | 2 + Logic/SimpleMetaTagger.ts | 4 +- Logic/Tags/TagsFilter.ts | 4 +- Logic/UIEventSource.ts | 1 + UI/Popup/FeatureInfoBox.ts | 13 +++--- UI/ShowDataLayer.ts | 4 +- assets/themes/climbing/license_info.json | 42 ++++++++++++------- 11 files changed, 71 insertions(+), 42 deletions(-) diff --git a/Logic/Actors/TitleHandler.ts b/Logic/Actors/TitleHandler.ts index 93bb4bb..f03961a 100644 --- a/Logic/Actors/TitleHandler.ts +++ b/Logic/Actors/TitleHandler.ts @@ -42,10 +42,11 @@ class TitleElement extends UIElement { continue; } if (layer.source.osmTags.matchesProperties(properties)) { - const title = new TagRenderingAnswer( - this._allElementsStorage.addOrGetElement(feature), - layer.title - ) + const tags = this._allElementsStorage.getEventSourceById(feature.properties.id); + if (tags == undefined) { + return defaultTitle; + } + const title = new TagRenderingAnswer(tags, layer.title) return new Combine([defaultTitle, " | ", title]).Render(); } } diff --git a/Logic/ElementStorage.ts b/Logic/ElementStorage.ts index d301d79..553d305 100644 --- a/Logic/ElementStorage.ts +++ b/Logic/ElementStorage.ts @@ -5,14 +5,14 @@ import {UIEventSource} from "./UIEventSource"; export class ElementStorage { - private _elements = []; + private _elements = new Map>(); constructor() { } addElementById(id: string, eventSource: UIEventSource) { - this._elements[id] = eventSource; + this._elements.set(id, eventSource); } /** @@ -23,14 +23,13 @@ export class ElementStorage { */ addOrGetElement(feature: any): UIEventSource { 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(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 { - 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); } } \ No newline at end of file diff --git a/Logic/FeatureSource/LocalStorageSaver.ts b/Logic/FeatureSource/LocalStorageSaver.ts index e97780d..5a66cef 100644 --- a/Logic/FeatureSource/LocalStorageSaver.ts +++ b/Logic/FeatureSource/LocalStorageSaver.ts @@ -15,13 +15,14 @@ export default class LocalStorageSaver implements FeatureSource { this.features = source.features; this.features.addCallbackAndRun(features => { + if (features === undefined) { + return; + } const now = new Date().getTime() features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000) - if (features === undefined) { - return; - } + if(features.length == 0){ return; } diff --git a/Logic/FeatureSource/MetaTaggingFeatureSource.ts b/Logic/FeatureSource/MetaTaggingFeatureSource.ts index fd24722..5b3ef12 100644 --- a/Logic/FeatureSource/MetaTaggingFeatureSource.ts +++ b/Logic/FeatureSource/MetaTaggingFeatureSource.ts @@ -15,8 +15,11 @@ export default class MetaTaggingFeatureSource implements FeatureSource { } featuresFreshness.forEach(featureFresh => { const feature = featureFresh.feature; - State.state.allElements.addOrGetElement(feature); - + + if(!State.state.allElements.has(feature.properties.id)){ + State.state.allElements.addOrGetElement(feature) + } + if (Hash.hash.data === feature.properties.id) { State.state.selectedElement.setData(feature); } diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index caf0afe..0471a49 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -57,9 +57,11 @@ export class Changes implements FeatureSource{ if (changes.length == 0) { return; } + for (const change of changes) { if (elementTags[change.k] !== change.v) { elementTags[change.k] = change.v; + console.log("Applied ", change.k, "=", change.v) this.pending.data.push({elementId: elementTags.id, key: change.k, value: change.v}); } } diff --git a/Logic/SimpleMetaTagger.ts b/Logic/SimpleMetaTagger.ts index ae77b7b..30bf191 100644 --- a/Logic/SimpleMetaTagger.ts +++ b/Logic/SimpleMetaTagger.ts @@ -64,7 +64,7 @@ export default class SimpleMetaTagger { SimpleMetaTagger.GetCountryCodeFor(lon, lat, (countries) => { try { feature.properties["_country"] = countries[0].trim().toLowerCase(); - const tagsSource = State.state.allElements.addOrGetElement(feature); + const tagsSource = State.state.allElements.getEventSourceById(feature.properties.id); tagsSource.ping(); } catch (e) { console.warn(e) @@ -77,7 +77,7 @@ export default class SimpleMetaTagger { "If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')", (feature => { - const tagsSource = State.state.allElements.addOrGetElement(feature); + const tagsSource = State.state.allElements.getEventSourceById(feature.properties.id); tagsSource.addCallbackAndRun(tags => { if (tags.opening_hours === undefined || tags._country === undefined) { return; diff --git a/Logic/Tags/TagsFilter.ts b/Logic/Tags/TagsFilter.ts index 5400aa8..3b93d41 100644 --- a/Logic/Tags/TagsFilter.ts +++ b/Logic/Tags/TagsFilter.ts @@ -14,7 +14,9 @@ export abstract class TagsFilter { /** * Converts the tagsFilter into a list of key-values that should be uploaded to OSM. - * Throws an error if not applicable + * Throws an error if not applicable. + * + * Note: properties are the already existing tags-object. It is only used in the substituting tag */ abstract asChange(properties:any): {k: string, v:string}[] diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index 8f604fd..0c92d31 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -21,6 +21,7 @@ export class UIEventSource { for (let i = 0; i < 10; i++) { console.log(copy[i].tag, copy[i]); } + return UIEventSource.allSources; } return []; } diff --git a/UI/Popup/FeatureInfoBox.ts b/UI/Popup/FeatureInfoBox.ts index 7cea701..b81e1af 100644 --- a/UI/Popup/FeatureInfoBox.ts +++ b/UI/Popup/FeatureInfoBox.ts @@ -19,7 +19,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen { super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig), () => FeatureInfoBox.GenerateContent(tags, layerConfig), tags.data.id); - + if (layerConfig === undefined) { throw "Undefined layerconfig"; } @@ -49,6 +49,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen { private static GenerateContent(tags: UIEventSource, layerConfig: LayerConfig): UIElement { let questionBox: UIElement = undefined; + if (State.state.featureSwitchUserbadge.data) { questionBox = new QuestionBox(tags, layerConfig.tagRenderings); } @@ -60,15 +61,15 @@ export default class FeatureInfoBox extends ScrollableFullScreen { questionBoxIsUsed = true; return questionBox; } - return new EditableTagRendering(tags, tr); + return new EditableTagRendering(tags, tr); }); if (!questionBoxIsUsed) { renderings.push(questionBox); } - - if(State.state.featureSwitchIsDebugging.data){ - const config: TagRenderingConfig = new TagRenderingConfig({render:"{all_tags()}"}, new Tag("id",""), ""); - renderings.push(new TagRenderingAnswer(tags,config )) + + if (State.state.featureSwitchIsDebugging.data) { + const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), ""); + renderings.push(new TagRenderingAnswer(tags, config)) } return new Combine(renderings).SetClass("block") diff --git a/UI/ShowDataLayer.ts b/UI/ShowDataLayer.ts index b077ea3..4ebe82e 100644 --- a/UI/ShowDataLayer.ts +++ b/UI/ShowDataLayer.ts @@ -88,7 +88,7 @@ export default class ShowDataLayer { marker.openPopup(); const popup = marker.getPopup(); - const tags = State.state.allElements.addOrGetElement(selected); + const tags = State.state.allElements.getEventSourceById(selected.properties.id); const layer: LayerConfig = this._layerDict[selected._matching_layer_id]; const infoBox = FeatureInfoBox.construct(tags, layer); @@ -118,7 +118,7 @@ export default class ShowDataLayer { // We have to convert them to the appropriate icon // Click handling is done in the next step - const tagSource = State.state.allElements.addOrGetElement(feature) + const tagSource = State.state.allElements.getEventSourceById(feature.properties.id) const layer: LayerConfig = this._layerDict[feature._matching_layer_id]; if (layer === undefined) { diff --git a/assets/themes/climbing/license_info.json b/assets/themes/climbing/license_info.json index 9c1ff1a..e6542e3 100644 --- a/assets/themes/climbing/license_info.json +++ b/assets/themes/climbing/license_info.json @@ -1,78 +1,92 @@ [ { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_gym.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_icon.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_no_rope.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_rope.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_route.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "climbing_unknown.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }, { "authors": [ - "Polarbear w", "Christian Neumann" + "Polarbear w", + "Christian Neumann" ], "path": "club.svg", "license": "CC0", "sources": [ - "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", "https://utopicode.de/", + "https://wiki.openstreetmap.org/wiki/File:Climbing_icon_no_rope.svg", + "https://utopicode.de/", "https://github.com/chrneumann/MapComplete" ] }