diff --git a/Customizations/SharedTagRenderings.ts b/Customizations/SharedTagRenderings.ts index 5014ad4f7..035a61dcc 100644 --- a/Customizations/SharedTagRenderings.ts +++ b/Customizations/SharedTagRenderings.ts @@ -2,18 +2,20 @@ import * as questions from "../assets/tagRenderings/questions.json"; import * as icons from "../assets/tagRenderings/icons.json"; import {Utils} from "../Utils"; import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"; +import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; export default class SharedTagRenderings { public static SharedTagRendering: Map = SharedTagRenderings.generatedSharedFields(); + public static SharedTagRenderingJson: Map = SharedTagRenderings.generatedSharedFieldsJsons(); public static SharedIcons: Map = SharedTagRenderings.generatedSharedFields(true); private static generatedSharedFields(iconsOnly = false): Map { - const dict = new Map(); - - function add(key, store) { + const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly) + const d = new Map() + for (const key of Array.from(configJsons.keys())) { try { - dict.set(key, new TagRenderingConfig(store[key], undefined, `SharedTagRenderings.${key}`)) + d.set(key, new TagRenderingConfig(configJsons.get(key), undefined, `SharedTagRenderings.${key}`)) } catch (e) { if (!Utils.runningFromConsole) { console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e) @@ -21,14 +23,19 @@ export default class SharedTagRenderings { } } } + return d + } + + private static generatedSharedFieldsJsons(iconsOnly = false): Map { + const dict = new Map(); if (!iconsOnly) { for (const key in questions) { - add(key, questions); + dict.set(key, questions[key]) } } for (const key in icons) { - add(key, icons); + dict.set(key, icons[key]) } return dict; diff --git a/Models/Constants.ts b/Models/Constants.ts index fce9144eb..759557962 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import {Utils} from "../Utils"; export default class Constants { - public static vNumber = "0.9.6"; + public static vNumber = "0.9.7"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/Models/ThemeConfig/Json/LayerConfigJson.ts b/Models/ThemeConfig/Json/LayerConfigJson.ts index fcd11aa90..ba6371de7 100644 --- a/Models/ThemeConfig/Json/LayerConfigJson.ts +++ b/Models/ThemeConfig/Json/LayerConfigJson.ts @@ -256,7 +256,7 @@ export interface LayerConfigJson { * A special value is 'questions', which indicates the location of the questions box. If not specified, it'll be appended to the bottom of the featureInfobox. * */ - tagRenderings?: (string | TagRenderingConfigJson) [], + tagRenderings?: (string | {builtin: string, override: any} | TagRenderingConfigJson) [], /** diff --git a/Models/ThemeConfig/LayerConfig.ts b/Models/ThemeConfig/LayerConfig.ts index 84ae9e472..9a5d3f322 100644 --- a/Models/ThemeConfig/LayerConfig.ts +++ b/Models/ThemeConfig/LayerConfig.ts @@ -214,7 +214,7 @@ export default class LayerConfig { * A string is interpreted as a name to call */ function trs( - tagRenderings?: (string | TagRenderingConfigJson)[], + tagRenderings?: (string | { builtin: string, override: any } | TagRenderingConfigJson)[], readOnly = false ) { if (tagRenderings === undefined) { @@ -224,7 +224,12 @@ export default class LayerConfig { return Utils.NoNull( tagRenderings.map((renderingJson, i) => { if (typeof renderingJson === "string") { - if (renderingJson === "questions") { + renderingJson = {builtin: renderingJson, override: undefined} + } + + if (renderingJson["builtin"] !== undefined) { + const renderingId = renderingJson["builtin"] + if (renderingId === "questions") { if (readOnly) { throw `A tagrendering has a question, but asking a question does not make sense here: is it a title icon or a geojson-layer? ${context}. The offending tagrendering is ${JSON.stringify( renderingJson @@ -234,26 +239,34 @@ export default class LayerConfig { return new TagRenderingConfig("questions", undefined); } - const shared = - SharedTagRenderings.SharedTagRendering.get(renderingJson); + if (renderingJson["override"] !== undefined) { + const sharedJson = SharedTagRenderings.SharedTagRenderingJson.get(renderingId) + return new TagRenderingConfig( + Utils.Merge(renderingJson["override"], sharedJson), + self.source.osmTags, + `${context}.tagrendering[${i}]+override` + ); + } + + const shared = SharedTagRenderings.SharedTagRendering.get(renderingId); + if (shared !== undefined) { return shared; } + if (Utils.runningFromConsole) { + return undefined; + } const keys = Array.from( SharedTagRenderings.SharedTagRendering.keys() ); - - if (Utils.runningFromConsole) { - return undefined; - } - - throw `Predefined tagRendering ${renderingJson} not found in ${context}.\n Try one of ${keys.join( + throw `Predefined tagRendering ${renderingId} not found in ${context}.\n Try one of ${keys.join( ", " )}\n If you intent to output this text literally, use {\"render\": } instead"}`; } + return new TagRenderingConfig( - renderingJson, + renderingJson, self.source.osmTags, `${context}.tagrendering[${i}]` ); diff --git a/Models/ThemeConfig/TagRenderingConfig.ts b/Models/ThemeConfig/TagRenderingConfig.ts index 90c6e0a6e..1ed34a180 100644 --- a/Models/ThemeConfig/TagRenderingConfig.ts +++ b/Models/ThemeConfig/TagRenderingConfig.ts @@ -67,7 +67,9 @@ export default class TagRenderingConfig { } if (json.freeform) { - + if(json.freeform.addExtraTags !== undefined && json.freeform.addExtraTags.length === undefined){ + throw `Freeform.addExtraTags should be a list of strings - not a single string (at ${context})` + } this.freeform = { key: json.freeform.key, type: json.freeform.type ?? "string",