Fix: fix #1779, add check to prevent similar errors

This commit is contained in:
Pieter Vander Vennet 2024-02-12 14:14:25 +01:00
parent 94bc6ee31d
commit 417dc1633e
5 changed files with 33 additions and 11 deletions

View file

@ -71,6 +71,7 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
for (const name of names) {
const found = Utils.Clone(state.sharedLayers.get(name))
found["_basedOn"] = name
if (found === undefined) {
reportNotFound(name)
continue
@ -555,6 +556,31 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
}
}
class PostvalidateTheme extends DesugaringStep<LayoutConfigJson> {
constructor() {
super("Various validation steps when everything is done", [], "PostvalidateTheme")
}
convert(json: LayoutConfigJson, context: ConversionContext): LayoutConfigJson {
for (const l of json.layers) {
const layer = <LayerConfigJson> l
const basedOn = <string> layer["_basedOn"]
if(!basedOn){
continue
}
if(layer["name"] === null){
continue
}
const sameBasedOn = <LayerConfigJson[]> json.layers.filter(l => l["_basedOn"] === layer["_basedOn"])
const minZoomAll = Math.min(...sameBasedOn.map(sbo => sbo.minzoom))
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.")
}
}
return json
}
}
export class PrepareTheme extends Fuse<LayoutConfigJson> {
private state: DesugaringContext
@ -583,7 +609,8 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
? new Pass("AddDefaultLayers is disabled due to the set flag")
: new AddDefaultLayers(state),
new AddDependencyLayersToTheme(state),
new AddImportLayers()
new AddImportLayers(),
new PostvalidateTheme()
)
this.state = state
}