forked from MapComplete/MapComplete
refactoring: fix special renderings (partly), deprecate
This commit is contained in:
parent
9b2f92dedc
commit
aaaaf1948d
15 changed files with 160 additions and 95 deletions
|
@ -322,7 +322,9 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
|||
* AddMiniMap.hasMinimap({render: "Some random value {minimap}"}) // => false
|
||||
*/
|
||||
static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean {
|
||||
return ValidationUtils.getSpecialVisualisations(renderingConfig).indexOf("minimap") >= 0
|
||||
return ValidationUtils.getSpecialVisualisations(renderingConfig).some(
|
||||
(vis) => vis.funcName === "minimap"
|
||||
)
|
||||
}
|
||||
|
||||
convert(layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson } {
|
||||
|
@ -344,7 +346,7 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
class AddContextToTransltionsInLayout extends DesugaringStep<LayoutConfigJson> {
|
||||
class AddContextToTranslationsInLayout extends DesugaringStep<LayoutConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"Adds context to translations, including the prefix 'themes:json.id'; this is to make sure terms in an 'overrides' or inline layer are linkable too",
|
||||
|
@ -644,7 +646,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
|||
super(
|
||||
"Fully prepares and expands a theme",
|
||||
|
||||
new AddContextToTransltionsInLayout(),
|
||||
new AddContextToTranslationsInLayout(),
|
||||
new PreparePersonalTheme(state),
|
||||
new WarnForUnsubstitutedLayersInTheme(),
|
||||
new On("layers", new Concat(new SubstituteLayer(state))),
|
||||
|
@ -663,4 +665,28 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
|||
new On("layers", new Each(new AddMiniMap(state)))
|
||||
)
|
||||
}
|
||||
|
||||
convert(
|
||||
json: LayoutConfigJson,
|
||||
context: string
|
||||
): { result: LayoutConfigJson; errors: string[]; warnings: string[]; information: string[] } {
|
||||
const result = super.convert(json, context)
|
||||
|
||||
const needsNodeDatabase = result.result.layers?.some((l: LayerConfigJson) =>
|
||||
l.tagRenderings?.some((tr: TagRenderingConfigJson) =>
|
||||
ValidationUtils.getSpecialVisualisations(tr)?.some(
|
||||
(special) => special.needsNodeDatabase
|
||||
)
|
||||
)
|
||||
)
|
||||
if (needsNodeDatabase) {
|
||||
result.information.push(
|
||||
context +
|
||||
": setting 'enableNodeDatabase' as this theme uses a special visualisation which needs to keep track of _all_ nodes"
|
||||
)
|
||||
result.result.enableNodeDatabase = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -620,6 +620,15 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
|||
': detected `special` on the top level. Did you mean `{"render":{ "special": ... }}`'
|
||||
)
|
||||
}
|
||||
if (json.group) {
|
||||
errors.push(
|
||||
"At " +
|
||||
context +
|
||||
': groups are deprecated, use `"label": ["' +
|
||||
json.group +
|
||||
'"]` instead'
|
||||
)
|
||||
}
|
||||
const freeformType = json["freeform"]?.["type"]
|
||||
if (freeformType) {
|
||||
if (Validators.AvailableTypes().indexOf(freeformType) < 0) {
|
||||
|
@ -688,6 +697,17 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
if (json.source === "special") {
|
||||
if (!Constants.priviliged_layers.find((x) => x == json.id)) {
|
||||
errors.push(
|
||||
context +
|
||||
": layer " +
|
||||
json.id +
|
||||
" uses 'special' as source.osmTags. However, this layer is not a priviliged layer"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (json.tagRenderings !== undefined && json.tagRenderings.length > 0) {
|
||||
if (json.title === undefined) {
|
||||
errors.push(
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
import { SpecialVisualization } from "../../../UI/SpecialVisualization"
|
||||
|
||||
export default class ValidationUtils {
|
||||
/**
|
||||
* Gives all the (function names of) used special visualisations
|
||||
* @param renderingConfig
|
||||
*/
|
||||
public static getSpecialVisualisations(renderingConfig: TagRenderingConfigJson): string[] {
|
||||
public static getSpecialVisualisations(
|
||||
renderingConfig: TagRenderingConfigJson
|
||||
): SpecialVisualization[] {
|
||||
const translations: any[] = Utils.NoNull([
|
||||
renderingConfig.render,
|
||||
...(renderingConfig.mappings ?? []).map((m) => m.then),
|
||||
])
|
||||
const all: string[] = []
|
||||
const all: SpecialVisualization[] = []
|
||||
for (let translation of translations) {
|
||||
if (typeof translation == "string") {
|
||||
translation = { "*": translation }
|
||||
|
@ -27,7 +30,7 @@ export default class ValidationUtils {
|
|||
const parts = SpecialVisualizations.constructSpecification(template)
|
||||
const specials = parts
|
||||
.filter((p) => typeof p !== "string")
|
||||
.map((special) => special["func"].funcName)
|
||||
.map((special) => special["func"])
|
||||
all.push(...specials)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue