Themes: add toilet layers automatically if toilet information is included

This commit is contained in:
Pieter Vander Vennet 2025-04-27 23:45:09 +02:00
parent cf7e005fd1
commit af2636bfaa
8 changed files with 72 additions and 22 deletions

View file

@ -5,11 +5,19 @@ import { SpecialVisualization } from "../../UI/SpecialVisualization"
import SpecialVisualizations from "../../UI/SpecialVisualizations"
export default class DependencyCalculator {
public static GetTagRenderingDependencies(tr: TagRenderingConfig): string[] {
public static GetTagRenderingDependencies(tr: TagRenderingConfig): {
id: string,
minzoom?: number,
neededBy: string
}[] {
if (tr === undefined) {
throw "Got undefined tag rendering in getTagRenderingDependencies"
}
const deps: string[] = []
const deps: { id: string, minZoom?: number, neededBy: string }[] = []
if (tr.requiredLayers) {
deps.push(...tr.requiredLayers.map(req => ({ ...req, neededBy: tr.id })))
}
// All translated snippets
const parts: string[] = [].concat(...tr.EnumerateTranslations().map((tr) => tr.AllValues()))
@ -21,7 +29,7 @@ export default class DependencyCalculator {
.map((p) => <{ func: SpecialVisualization; args: string[] }>p)
.filter((o) => o?.func?.getLayerDependencies !== undefined)
for (const specialViz of specialVizs) {
deps.push(...specialViz.func.getLayerDependencies(specialViz.args))
deps.push(...specialViz.func.getLayerDependencies(specialViz.args).map(id => ({ id, neededBy: tr.id })))
}
}
return deps
@ -43,7 +51,8 @@ export default class DependencyCalculator {
reason: string
context?: string
neededBy: string
checkHasSnapName: boolean
checkHasSnapName: boolean,
minzoom?: number
}[] = []
for (let i = 0; layer.presets !== undefined && i < layer.presets.length; i++) {
@ -68,8 +77,9 @@ export default class DependencyCalculator {
for (const tr of layer.AllTagRenderings()) {
for (const dep of DependencyCalculator.GetTagRenderingDependencies(tr)) {
deps.push({
neededLayer: dep,
reason: "a tagrendering needs this layer",
neededLayer: dep.id,
reason: `tagrendering ${dep.neededBy} needs this layer`,
minzoom: dep.minzoom,
context: tr.id,
neededBy: layer.id,
checkHasSnapName: false,
@ -91,8 +101,8 @@ export default class DependencyCalculator {
let currentKey = undefined
let currentLine = undefined
const params: ExtraFuncParams = {
getFeatureById: (_) => undefined,
getFeaturesWithin: (layerId, _) => {
getFeatureById: () => undefined,
getFeaturesWithin: (layerId) => {
if (layerId === "*") {
// This is a wildcard
return []
@ -128,7 +138,9 @@ export default class DependencyCalculator {
)
const result = func(obj, helpers)
obj.properties[key] = JSON.stringify(result)
} catch (e) {}
} catch (e) {
// pass
}
}
}