Add some more sanity checkes on layers

This commit is contained in:
Pieter Vander Vennet 2021-11-09 18:22:05 +01:00
parent bdd9ed4c22
commit 43e63fac3b

View file

@ -196,6 +196,11 @@ export default class LayerConfig extends WithContextLoader {
throw "MapRendering is undefined in " + context
}
if (json.mapRendering === null) {
this.mapRendering = []
this.lineRendering = []
} else {
this.mapRendering = json.mapRendering
.filter(r => r["location"] !== undefined)
.map((r, i) => new PointRenderingConfig(<PointRenderingConfigJson>r, context + ".mapRendering[" + i + "]"))
@ -204,6 +209,16 @@ export default class LayerConfig extends WithContextLoader {
.filter(r => r["location"] === undefined)
.map((r, i) => new LineRenderingConfig(<LineRenderingConfigJson>r, context + ".mapRendering[" + i + "]"))
const hasCenterRendering = this.mapRendering.some(r => r.location.has("centroid") || r.location.has("start") || r.location.has("end"))
if (this.lineRendering.length === 0 && this.mapRendering.length === 0) {
console.log(json.mapRendering)
throw("The layer " + this.id + " does not have any maprenderings defined and will thus not show up on the map at all. If this is intentional, set maprenderings to 'null' instead of '[]'")
} else if (!hasCenterRendering && this.lineRendering.length === 0) {
throw "The layer " + this.id + " might not render ways. This might result in dropped information"
}
}
const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? [];
if (missingIds?.length > 0 && official) {
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
@ -414,7 +429,6 @@ export default class LayerConfig extends WithContextLoader {
}
let usingLayer: BaseUIElement[] = []
if (usedInThemes?.length > 0 && !addedByDefault) {
usingLayer = [new Title("Themes using this layer", 4),