From 707d99619d7b5fa90891e93d5641f52715f04beb Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 12 Feb 2024 14:45:26 +0100 Subject: [PATCH] Themes: fix validation errors due to #1779 --- assets/themes/atm/atm.json | 3 ++- assets/themes/climbing/climbing.json | 1 + assets/themes/healthcare/healthcare.json | 4 ++-- .../ThemeConfig/Conversion/PrepareTheme.ts | 17 +++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/assets/themes/atm/atm.json b/assets/themes/atm/atm.json index 75d249d10c..fc6f4e7073 100644 --- a/assets/themes/atm/atm.json +++ b/assets/themes/atm/atm.json @@ -38,7 +38,6 @@ "builtin": "bank", "override": { "id": "banks_with_atm", - "name": null, "minzoom": 14, "source": { "osmTags": { @@ -56,6 +55,7 @@ "builtin": "bank", "override": { "minzoom": 18, + "name": null, "filter": { "sameAs": "bank_with_atm" } @@ -167,6 +167,7 @@ "builtin": "postoffices", "override": { "minzoom": 18, + "name": null, "filter": { "sameAs": "post_offices_with_atm" } diff --git a/assets/themes/climbing/climbing.json b/assets/themes/climbing/climbing.json index f359b932dd..f080d16fa7 100644 --- a/assets/themes/climbing/climbing.json +++ b/assets/themes/climbing/climbing.json @@ -393,6 +393,7 @@ ] }, "minzoom": 16, + "name": null, "+tagRenderings": [ { "id": "repairs_climbing_shoes", diff --git a/assets/themes/healthcare/healthcare.json b/assets/themes/healthcare/healthcare.json index 51c577f0cb..dba448616e 100644 --- a/assets/themes/healthcare/healthcare.json +++ b/assets/themes/healthcare/healthcare.json @@ -110,9 +110,9 @@ }, { "builtin": "shops", - "=presets": [], - "=name": null, "override": { + "=presets": [], + "name": null, "minzoom": 18 } } diff --git a/src/Models/ThemeConfig/Conversion/PrepareTheme.ts b/src/Models/ThemeConfig/Conversion/PrepareTheme.ts index 6fd08631fa..6a8127fe8b 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareTheme.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareTheme.ts @@ -557,24 +557,33 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep } class PostvalidateTheme extends DesugaringStep { - constructor() { + private readonly _state: DesugaringContext + constructor(state: DesugaringContext) { super("Various validation steps when everything is done", [], "PostvalidateTheme") + this._state = state } convert(json: LayoutConfigJson, context: ConversionContext): LayoutConfigJson { for (const l of json.layers) { const layer = l const basedOn = layer["_basedOn"] + const basedOnDef = this._state.sharedLayers.get(basedOn) if(!basedOn){ continue } if(layer["name"] === null){ continue } - const sameBasedOn = json.layers.filter(l => l["_basedOn"] === layer["_basedOn"]) + const sameBasedOn = json.layers.filter(l => l["_basedOn"] === layer["_basedOn"] && l["id"] !== layer.id) const minZoomAll = Math.min(...sameBasedOn.map(sbo => sbo.minzoom)) + + const sameNameDetected = sameBasedOn.some( same => JSON.stringify(layer["name"]) === JSON.stringify(same["name"])) + if(!sameNameDetected){ + // The name is unique, so it'll won't be confusing + continue + } if(minZoomAll < layer.minzoom){ - context.err("There are multiple layers based on "+basedOn+". The layer with id "+layer.id+" has a minzoom of "+layer.minzoom+", but has no name set. Another similar layer has a lower minzoom. As such, the layer selection might show 'zoom in to see features' even though some of the features are already visible. Set `\"name\": null` for this layer and eventually remove the 'name':null for the other layer.") + context.err("There are multiple layers based on "+basedOn+". The layer with id "+layer.id+" has a minzoom of "+layer.minzoom+", and has a name set. Another similar layer has a lower minzoom. As such, the layer selection might show 'zoom in to see features' even though some of the features are already visible. Set `\"name\": null` for this layer and eventually remove the 'name':null for the other layer.") } } @@ -610,7 +619,7 @@ export class PrepareTheme extends Fuse { : new AddDefaultLayers(state), new AddDependencyLayersToTheme(state), new AddImportLayers(), - new PostvalidateTheme() + new PostvalidateTheme(state) ) this.state = state }