forked from MapComplete/MapComplete
Docs: add 'used in layers'-information for builtingQuestions + various small refactorings
This commit is contained in:
parent
2545982dbd
commit
bc2ea7841f
9 changed files with 83 additions and 47 deletions
|
|
@ -3,9 +3,38 @@ import { ExtraFuncParams, ExtraFunctions } from "../../Logic/ExtraFunctions"
|
|||
import LayerConfig from "./LayerConfig"
|
||||
import { SpecialVisualization } from "../../UI/SpecialVisualization"
|
||||
import SpecialVisualizations from "../../UI/SpecialVisualizations"
|
||||
import { LayerConfigJson } from "./Json/LayerConfigJson"
|
||||
|
||||
export default class DependencyCalculator {
|
||||
public static GetTagRenderingDependencies(tr: TagRenderingConfig): {
|
||||
|
||||
/**
|
||||
* For every tagRendering in the listed layers, determines in what layers they end up
|
||||
*/
|
||||
public static tagRenderingImportedBy(questionedLayer: LayerConfig, layers: LayerConfig[]): Map<string, {
|
||||
layer: string
|
||||
}[]> {
|
||||
const result: Map<string, { layer: string }[]> = new Map()
|
||||
|
||||
for (const layer of layers) {
|
||||
const hasRightContext = layer.tagRenderings.filter(tr => tr._definedIn !== undefined && tr?._definedIn?.[0] === questionedLayer.id)
|
||||
for (const tr of hasRightContext) {
|
||||
const id = tr._definedIn[1]
|
||||
if (!result.has(id)) {
|
||||
result.set(id, [])
|
||||
}
|
||||
result.get(id).push({ layer: layer.id })
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates what layers are introduced by a tagRenderingConfig
|
||||
* @param tr
|
||||
* @private
|
||||
*/
|
||||
private static getTagRenderingDependencies(tr: TagRenderingConfig): {
|
||||
id: string
|
||||
minzoom?: number
|
||||
neededBy: string
|
||||
|
|
@ -83,7 +112,7 @@ export default class DependencyCalculator {
|
|||
}
|
||||
|
||||
for (const tr of layer.AllTagRenderings()) {
|
||||
for (const dep of DependencyCalculator.GetTagRenderingDependencies(tr)) {
|
||||
for (const dep of DependencyCalculator.getTagRenderingDependencies(tr)) {
|
||||
deps.push({
|
||||
neededLayer: dep.id,
|
||||
reason: `tagrendering ${dep.neededBy} needs this layer`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue