Themes: fix validation errors due to #1779

This commit is contained in:
Pieter Vander Vennet 2024-02-12 14:45:26 +01:00
parent 7dc43f933e
commit 707d99619d
4 changed files with 18 additions and 7 deletions

View file

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

View file

@ -393,6 +393,7 @@
]
},
"minzoom": 16,
"name": null,
"+tagRenderings": [
{
"id": "repairs_climbing_shoes",

View file

@ -110,9 +110,9 @@
},
{
"builtin": "shops",
"=presets": [],
"=name": null,
"override": {
"=presets": [],
"name": null,
"minzoom": 18
}
}

View file

@ -557,24 +557,33 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
}
class PostvalidateTheme extends DesugaringStep<LayoutConfigJson> {
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 = <LayerConfigJson> l
const basedOn = <string> layer["_basedOn"]
const basedOnDef = this._state.sharedLayers.get(basedOn)
if(!basedOn){
continue
}
if(layer["name"] === null){
continue
}
const sameBasedOn = <LayerConfigJson[]> json.layers.filter(l => l["_basedOn"] === layer["_basedOn"])
const sameBasedOn = <LayerConfigJson[]> 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<LayoutConfigJson> {
: new AddDefaultLayers(state),
new AddDependencyLayersToTheme(state),
new AddImportLayers(),
new PostvalidateTheme()
new PostvalidateTheme(state)
)
this.state = state
}