From 47011370ddf3994f67a55eab33a111bfa170fdb1 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 18 Sep 2021 02:32:40 +0200 Subject: [PATCH] Add more documentation and checks to the models --- Models/ThemeConfig/Json/LayerConfigJson.ts | 4 +++- Models/ThemeConfig/Json/TagRenderingConfigJson.ts | 4 ++++ Models/ThemeConfig/LayerConfig.ts | 12 ++++++++++++ Models/ThemeConfig/LayoutConfig.ts | 6 +++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Models/ThemeConfig/Json/LayerConfigJson.ts b/Models/ThemeConfig/Json/LayerConfigJson.ts index f03166d07c..3068d25fd2 100644 --- a/Models/ThemeConfig/Json/LayerConfigJson.ts +++ b/Models/ThemeConfig/Json/LayerConfigJson.ts @@ -84,7 +84,9 @@ export interface LayerConfigJson { /** * This tag rendering should either be 'yes' or 'no'. If 'no' is returned, then the feature will be hidden from view. - * This is useful to hide certain features from view. Important: hiding features does not work dynamically, but is only calculated when the data is first renders. + * This is useful to hide certain features from view. + * + * Important: hiding features does not work dynamically, but is only calculated when the data is first renders. * This implies that it is not possible to hide a feature after a tagging change * * The default value is 'yes' diff --git a/Models/ThemeConfig/Json/TagRenderingConfigJson.ts b/Models/ThemeConfig/Json/TagRenderingConfigJson.ts index 9152bf463c..415c17cd18 100644 --- a/Models/ThemeConfig/Json/TagRenderingConfigJson.ts +++ b/Models/ThemeConfig/Json/TagRenderingConfigJson.ts @@ -79,6 +79,10 @@ export interface TagRenderingConfigJson { /** * If this condition is met, then the text under `then` will be shown. * If no value matches, and the user selects this mapping as an option, then these tags will be uploaded to OSM. + * + * For example: {'if': 'diet:vegetarion=yes', 'then':'A vegetarian option is offered here'} + * + * This can be an substituting-tag as well, e.g. {'if': 'addr:street:={_calculated_nearby_streetname}', 'then': '{_calculated_nearby_streetname}'} */ if: AndOrTagConfigJson | string, /** diff --git a/Models/ThemeConfig/LayerConfig.ts b/Models/ThemeConfig/LayerConfig.ts index ee8c836fec..c3cadc1e09 100644 --- a/Models/ThemeConfig/LayerConfig.ts +++ b/Models/ThemeConfig/LayerConfig.ts @@ -104,6 +104,10 @@ export default class LayerConfig { throw context + "Use 'geoJson' instead of 'geoJsonSource'"; } + if (json.source["geojson"] !== undefined) { + throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)"; + } + this.source = new SourceConfig( { osmTags: osmTags, @@ -133,6 +137,14 @@ export default class LayerConfig { const key = kv.substring(0, index); const code = kv.substring(index + 1); + try{ + + new Function("feat", "return " + code + ";"); + }catch(e){ + throw `Invalid function definition: code ${code} is invalid:${e} (at ${context})` + } + + this.calculatedTags.push([key, code]); } } diff --git a/Models/ThemeConfig/LayoutConfig.ts b/Models/ThemeConfig/LayoutConfig.ts index e34a83cb39..b57b6bab3d 100644 --- a/Models/ThemeConfig/LayoutConfig.ts +++ b/Models/ThemeConfig/LayoutConfig.ts @@ -53,10 +53,10 @@ export default class LayoutConfig { public readonly cacheTimeout?: number; public readonly overpassUrl: string; public readonly overpassTimeout: number; - private readonly _official: boolean; + public readonly official: boolean; constructor(json: LayoutConfigJson, official = true, context?: string) { - this._official = official; + this.official = official; this.id = json.id; context = (context ?? "") + "." + this.id; this.maintainer = json.maintainer; @@ -221,7 +221,7 @@ export default class LayoutConfig { } public CustomCodeSnippets(): string[] { - if (this._official) { + if (this.official) { return []; } const msg = "
This layout uses custom javascript, loaded for the wide internet. The code is printed below, please report suspicious code on the issue tracker of MapComplete:
"