Add license info, fix non-updating values after reopening popups
This commit is contained in:
parent
576fd8ff40
commit
7b47af8978
11 changed files with 71 additions and 42 deletions
|
@ -42,10 +42,11 @@ class TitleElement extends UIElement {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (layer.source.osmTags.matchesProperties(properties)) {
|
if (layer.source.osmTags.matchesProperties(properties)) {
|
||||||
const title = new TagRenderingAnswer(
|
const tags = this._allElementsStorage.getEventSourceById(feature.properties.id);
|
||||||
this._allElementsStorage.addOrGetElement(feature),
|
if (tags == undefined) {
|
||||||
layer.title
|
return defaultTitle;
|
||||||
)
|
}
|
||||||
|
const title = new TagRenderingAnswer(tags, layer.title)
|
||||||
return new Combine([defaultTitle, " | ", title]).Render();
|
return new Combine([defaultTitle, " | ", title]).Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ import {UIEventSource} from "./UIEventSource";
|
||||||
|
|
||||||
export class ElementStorage {
|
export class ElementStorage {
|
||||||
|
|
||||||
private _elements = [];
|
private _elements = new Map<string, UIEventSource<any>>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addElementById(id: string, eventSource: UIEventSource<any>) {
|
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> {
|
addOrGetElement(feature: any): UIEventSource<any> {
|
||||||
const elementId = feature.properties.id;
|
const elementId = feature.properties.id;
|
||||||
if (elementId in this._elements) {
|
if (this._elements.has(elementId)) {
|
||||||
const es = this._elements[elementId];
|
const es = this._elements.get(elementId);
|
||||||
if (es.data == feature.properties) {
|
if (es.data == feature.properties) {
|
||||||
// Reference comparison gives the same object! we can just return the event source
|
// Reference comparison gives the same object! we can just return the event source
|
||||||
return es;
|
return es;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const keptKeys = es.data;
|
const keptKeys = es.data;
|
||||||
// The element already exists
|
// The element already exists
|
||||||
// We add all the new keys to the old keys
|
// We add all the new keys to the old keys
|
||||||
|
@ -49,15 +48,20 @@ export class ElementStorage {
|
||||||
return es;
|
return es;
|
||||||
} else {
|
} else {
|
||||||
const eventSource = new UIEventSource<any>(feature.properties, "tags of " + feature.properties.id);
|
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;
|
return eventSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getEventSourceById(elementId): UIEventSource<any> {
|
getEventSourceById(elementId): UIEventSource<any> {
|
||||||
if (elementId in this._elements) {
|
if (this._elements.has(elementId)) {
|
||||||
return this._elements[elementId];
|
return this._elements.get(elementId);
|
||||||
}
|
}
|
||||||
console.error("Can not find eventsource with id ", elementId);
|
console.error("Can not find eventsource with id ", elementId);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
has(id) {
|
||||||
|
return this._elements.has(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,13 +15,14 @@ export default class LocalStorageSaver implements FeatureSource {
|
||||||
this.features = source.features;
|
this.features = source.features;
|
||||||
|
|
||||||
this.features.addCallbackAndRun(features => {
|
this.features.addCallbackAndRun(features => {
|
||||||
|
if (features === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const now = new Date().getTime()
|
const now = new Date().getTime()
|
||||||
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)
|
features = features.filter(f => layout.data.cacheTimeout > Math.abs(now - f.freshness.getTime())/1000)
|
||||||
|
|
||||||
if (features === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(features.length == 0){
|
if(features.length == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ export default class MetaTaggingFeatureSource implements FeatureSource {
|
||||||
}
|
}
|
||||||
featuresFreshness.forEach(featureFresh => {
|
featuresFreshness.forEach(featureFresh => {
|
||||||
const feature = featureFresh.feature;
|
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) {
|
if (Hash.hash.data === feature.properties.id) {
|
||||||
State.state.selectedElement.setData(feature);
|
State.state.selectedElement.setData(feature);
|
||||||
|
|
|
@ -57,9 +57,11 @@ export class Changes implements FeatureSource{
|
||||||
if (changes.length == 0) {
|
if (changes.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const change of changes) {
|
for (const change of changes) {
|
||||||
if (elementTags[change.k] !== change.v) {
|
if (elementTags[change.k] !== change.v) {
|
||||||
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});
|
this.pending.data.push({elementId: elementTags.id, key: change.k, value: change.v});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ export default class SimpleMetaTagger {
|
||||||
SimpleMetaTagger.GetCountryCodeFor(lon, lat, (countries) => {
|
SimpleMetaTagger.GetCountryCodeFor(lon, lat, (countries) => {
|
||||||
try {
|
try {
|
||||||
feature.properties["_country"] = countries[0].trim().toLowerCase();
|
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();
|
tagsSource.ping();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(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')",
|
"If 'opening_hours' is present, it will add the current state of the feature (being 'yes' or 'no')",
|
||||||
(feature => {
|
(feature => {
|
||||||
|
|
||||||
const tagsSource = State.state.allElements.addOrGetElement(feature);
|
const tagsSource = State.state.allElements.getEventSourceById(feature.properties.id);
|
||||||
tagsSource.addCallbackAndRun(tags => {
|
tagsSource.addCallbackAndRun(tags => {
|
||||||
if (tags.opening_hours === undefined || tags._country === undefined) {
|
if (tags.opening_hours === undefined || tags._country === undefined) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -14,7 +14,9 @@ export abstract class TagsFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the tagsFilter into a list of key-values that should be uploaded to OSM.
|
* 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}[]
|
abstract asChange(properties:any): {k: string, v:string}[]
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ export class UIEventSource<T> {
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
console.log(copy[i].tag, copy[i]);
|
console.log(copy[i].tag, copy[i]);
|
||||||
}
|
}
|
||||||
|
return UIEventSource.allSources;
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
private static GenerateContent(tags: UIEventSource<any>,
|
private static GenerateContent(tags: UIEventSource<any>,
|
||||||
layerConfig: LayerConfig): UIElement {
|
layerConfig: LayerConfig): UIElement {
|
||||||
let questionBox: UIElement = undefined;
|
let questionBox: UIElement = undefined;
|
||||||
|
|
||||||
if (State.state.featureSwitchUserbadge.data) {
|
if (State.state.featureSwitchUserbadge.data) {
|
||||||
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
|
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ export default class ShowDataLayer {
|
||||||
marker.openPopup();
|
marker.openPopup();
|
||||||
|
|
||||||
const popup = marker.getPopup();
|
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 layer: LayerConfig = this._layerDict[selected._matching_layer_id];
|
||||||
const infoBox = FeatureInfoBox.construct(tags, layer);
|
const infoBox = FeatureInfoBox.construct(tags, layer);
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ export default class ShowDataLayer {
|
||||||
// We have to convert them to the appropriate icon
|
// We have to convert them to the appropriate icon
|
||||||
// Click handling is done in the next step
|
// 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];
|
const layer: LayerConfig = this._layerDict[feature._matching_layer_id];
|
||||||
|
|
||||||
if (layer === undefined) {
|
if (layer === undefined) {
|
||||||
|
|
|
@ -1,78 +1,92 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_gym.svg",
|
"path": "climbing_gym.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_icon.svg",
|
"path": "climbing_icon.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_no_rope.svg",
|
"path": "climbing_no_rope.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_rope.svg",
|
"path": "climbing_rope.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_route.svg",
|
"path": "climbing_route.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "climbing_unknown.svg",
|
"path": "climbing_unknown.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Polarbear w", "Christian Neumann"
|
"Polarbear w",
|
||||||
|
"Christian Neumann"
|
||||||
],
|
],
|
||||||
"path": "club.svg",
|
"path": "club.svg",
|
||||||
"license": "CC0",
|
"license": "CC0",
|
||||||
"sources": [
|
"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"
|
"https://github.com/chrneumann/MapComplete"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue