Themes: validate that a background layer actually exists, fix current-view button (GRB)

This commit is contained in:
Pieter Vander Vennet 2024-01-03 18:24:00 +01:00
parent eb6194bf8f
commit fc483ed547
9 changed files with 62 additions and 29 deletions

View file

@ -22,7 +22,8 @@
"startZoom": 9,
"startLat": 51.0249,
"startLon": 4.026489,
"defaultBackgroundId": "AGIVFlandersGRB",
"defaultBackgroundId": "osm",
"credits": [
"Pieter Vander Vennet"
],

View file

@ -63,7 +63,7 @@
"startZoom": 8,
"startLat": 50.642,
"startLon": 4.482,
"defaultBackgroundId": "AGIV",
"defaultBackgroundId": "photo",
"credits": [
"Midgard"
],
@ -76,4 +76,4 @@
"maxZoom": 19,
"minNeededElements": 25
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "mapcomplete",
"version": "0.36.10",
"version": "0.36.11",
"repository": "https://github.com/pietervdvn/MapComplete",
"description": "A small website to edit OSM easily",
"bugs": "https://github.com/pietervdvn/MapComplete/issues",

View file

@ -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 {

View file

@ -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 &&

View file

@ -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
* ]
*

View file

@ -314,6 +314,7 @@ export default class LayoutConfig implements LayoutInformation {
return layer
}
}
console.log("Fallthrough", this, tags)
return undefined
}
}

View file

@ -13,13 +13,7 @@
import type { MapProperties } from "../Models/MapProperties"
import Geosearch from "./BigComponents/Geosearch.svelte"
import Translations from "./i18n/Translations"
import {
CogIcon,
EyeIcon,
HeartIcon,
MenuIcon,
XCircleIcon,
} from "@rgossiaux/svelte-heroicons/solid"
import { CogIcon, EyeIcon, HeartIcon, MenuIcon, XCircleIcon } from "@rgossiaux/svelte-heroicons/solid"
import Tr from "./Base/Tr.svelte"
import CommunityIndexView from "./BigComponents/CommunityIndexView.svelte"
import FloatOver from "./Base/FloatOver.svelte"
@ -72,8 +66,6 @@
import FilterPanel from "./BigComponents/FilterPanel.svelte"
import PrivacyPolicy from "./BigComponents/PrivacyPolicy.svelte"
import { BBox } from "../Logic/BBox"
import { MapLibreAdaptor } from "./Map/MapLibreAdaptor.js"
import { QueryParameters } from "../Logic/Web/QueryParameters"
export let state: ThemeViewState
let layout = state.layout
@ -100,8 +92,12 @@
})
})
let selectedLayer: Store<LayerConfig> = state.selectedElement.mapD((element) =>
state.layout.getMatchingLayer(element.properties)
let selectedLayer: Store<LayerConfig> = state.selectedElement.mapD((element) => {
if (element.properties.id.startsWith("current_view")) {
return currentViewLayer
}
return state.layout.getMatchingLayer(element.properties)
},
)
let currentZoom = state.mapProperties.zoom
let showCrosshair = state.userRelatedState.showCrosshair
@ -109,6 +105,7 @@
let viewport: UIEventSource<HTMLDivElement> = new UIEventSource<HTMLDivElement>(undefined)
let mapproperties: MapProperties = state.mapProperties
state.mapProperties.installCustomKeyboardHandler(viewport)
function updateViewport() {
const rect = viewport.data?.getBoundingClientRect()
if (!rect) {
@ -142,7 +139,7 @@
onDestroy(
rasterLayer.addCallbackAndRunD((l) => {
rasterLayerName = l.properties.name
})
}),
)
let previewedImage = state.previewedImage
@ -189,10 +186,10 @@
<div class="pointer-events-auto float-right mt-1 flex flex-col px-1 max-[480px]:w-full sm:m-2">
<If condition={state.visualFeedback}>
{#if $selectedElement === undefined}
<div class="w-fit">
<VisualFeedbackPanel {state} />
</div>
{#if $selectedElement === undefined}
<div class="w-fit">
<VisualFeedbackPanel {state} />
</div>
{/if}
</If>
<If condition={state.featureSwitches.featureSwitchSearch}>
@ -228,7 +225,7 @@
{#if currentViewLayer?.tagRenderings && currentViewLayer.defaultIcon()}
<MapControlButton
on:click={() => {
selectedElement.setData(state.currentView.features?.data?.[0])
state.selectedElement.setData(state.currentView.features?.data?.[0])
}}
on:keydown={forwardEventToMap}
>

File diff suppressed because one or more lines are too long