Themes: validate that a background layer actually exists, fix current-view button (GRB)

This commit is contained in:
Pieter Vander Vennet 2024-01-03 18:24:00 +01:00
parent eb6194bf8f
commit fc483ed547
9 changed files with 62 additions and 29 deletions

View file

@ -83,6 +83,15 @@ export class AvailableRasterLayers {
})
)
}
public static allIds(): Set<string> {
const all: string[] = []
all.push(...AvailableRasterLayers.globalLayers.map((l) => l.properties.id))
all.push(...AvailableRasterLayers.EditorLayerIndex.map((l) => l.properties.id))
all.push(this.osmCarto.properties.id)
all.push(this.maptilerDefaultLayer.properties.id)
return new Set<string>(all)
}
}
export class RasterLayerUtils {

View file

@ -21,6 +21,9 @@ import PresetConfig from "../PresetConfig"
import { TagsFilter } from "../../../Logic/Tags/TagsFilter"
import { Translatable } from "../Json/Translatable"
import { ConversionContext } from "./ConversionContext"
import * as eli from "../../../assets/editor-layer-index.json"
import { AvailableRasterLayers } from "../../RasterLayers"
import Back from "../../../assets/svg/Back.svelte"
class ValidateLanguageCompleteness extends DesugaringStep<LayoutConfig> {
private readonly _languages: string[]
@ -124,6 +127,7 @@ export class DoesImageExist extends DesugaringStep<string> {
}
export class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
private static readonly _availableLayers = AvailableRasterLayers.allIds()
/**
* The paths where this layer is originally saved. Triggers some extra checks
* @private
@ -260,6 +264,19 @@ export class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
.err("The overpassURL is a string, use a list of strings instead. Wrap it with [ ]")
}
if (json.defaultBackgroundId) {
const backgroundId = json.defaultBackgroundId
const isCategory =
backgroundId === "photo" || backgroundId === "map" || backgroundId === "osmbasedmap"
if (!isCategory && !ValidateTheme._availableLayers.has(backgroundId)) {
context
.enter("defaultBackgroundId")
.err("This layer ID is not known: " + backgroundId)
}
}
return json
}
}
@ -1465,7 +1482,7 @@ export class ValidateLayer extends Conversion<
}
}
for (let i = 0; i < json.presets.length; i++) {
for (let i = 0; i < json.presets?.length; i++) {
const preset = json.presets[i]
if (
preset.snapToLayer === undefined &&

View file

@ -145,7 +145,7 @@ export interface LayerConfigJson {
* There are a few extra functions available. Refer to <a>Docs/CalculatedTags.md</a> for more information
* The functions will be run in order, e.g.
* [
Not found... * "_max_overlap_m2=Math.max(...feat.overlapsWith("someOtherLayer").map(o => o.overlap))
* "_max_overlap_m2=Math.max(...feat.overlapsWith("someOtherLayer").map(o => o.overlap))
* "_max_overlap_ratio=Number(feat._max_overlap_m2)/feat.area
* ]
*

View file

@ -314,6 +314,7 @@ export default class LayoutConfig implements LayoutInformation {
return layer
}
}
console.log("Fallthrough", this, tags)
return undefined
}
}