forked from MapComplete/MapComplete
Themes: validate that a background layer actually exists, fix current-view button (GRB)
This commit is contained in:
parent
eb6194bf8f
commit
fc483ed547
9 changed files with 62 additions and 29 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 &&
|
||||
|
|
|
@ -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
|
||||
* ]
|
||||
*
|
||||
|
|
|
@ -314,6 +314,7 @@ export default class LayoutConfig implements LayoutInformation {
|
|||
return layer
|
||||
}
|
||||
}
|
||||
console.log("Fallthrough", this, tags)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue