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

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

View file

@ -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();
}
}

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);
}
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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});
}
}

View file

@ -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;

View file

@ -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}[]

View file

@ -21,6 +21,7 @@ export class UIEventSource<T> {
for (let i = 0; i < 10; i++) {
console.log(copy[i].tag, copy[i]);
}
return UIEventSource.allSources;
}
return [];
}

View file

@ -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<any>,
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")

View file

@ -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) {

View file

@ -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"
]
}