diff --git a/Models/Constants.ts b/Models/Constants.ts index 79446a81bc..2d31e12b1a 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -1,5 +1,6 @@ -import { Utils } from "../Utils" +import {Utils} from "../Utils" import * as meta from "../package.json" + export type PriviligedLayerType = typeof Constants.priviliged_layers[number] export default class Constants { @@ -115,6 +116,11 @@ export default class Constants { static countryCoderEndpoint: string = "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/latlon2country" public static readonly OsmPreferenceKeyPicturesLicense = "pictures-license" + /** + * These are the values that are allowed to use as 'backdrop' icon for a map pin + */ + private static readonly _defaultPinIcons = ["square", "circle", "none", "pin", "person", "plus", "ring", "star", "teardrop", "triangle", "crosshair",] as const + public static readonly defaultPinIcons: string[] = Constants._defaultPinIcons private static isRetina(): boolean { if (Utils.runningFromConsole) { @@ -125,8 +131,8 @@ export default class Constants { return ( (window.matchMedia && (window.matchMedia( - "only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)" - ).matches || + "only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)" + ).matches || window.matchMedia( "only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)" ).matches)) || diff --git a/Models/ThemeConfig/PointRenderingConfig.ts b/Models/ThemeConfig/PointRenderingConfig.ts index 250f92e95c..b6b24ab65b 100644 --- a/Models/ThemeConfig/PointRenderingConfig.ts +++ b/Models/ThemeConfig/PointRenderingConfig.ts @@ -11,6 +11,7 @@ import { FixedUiElement } from "../../UI/Base/FixedUiElement" import Img from "../../UI/Base/Img" import Combine from "../../UI/Base/Combine" import { VariableUiElement } from "../../UI/Base/VariableUIElement" +import Constants from "../Constants"; export default class PointRenderingConfig extends WithContextLoader { static readonly allowed_location_codes: ReadonlySet = new Set([ @@ -86,7 +87,7 @@ export default class PointRenderingConfig extends WithContextLoader { const iconPath = this.icon?.GetRenderValue({ id: "node/-1" })?.txt if (iconPath !== undefined && iconPath.startsWith(Utils.assets_path)) { const iconKey = iconPath.substr(Utils.assets_path.length) - if (Svg.All[iconKey] === undefined) { + if (Constants.defaultPinIcons.indexOf(iconKey) < 0) { throw context + ": builtin SVG asset not found: " + iconPath } } @@ -109,7 +110,7 @@ export default class PointRenderingConfig extends WithContextLoader { return undefined } const match = htmlSpec.match(/([a-zA-Z0-9_]*):([^;]*)/) - if (match !== null && Svg.All[match[1] + ".svg"] !== undefined) { + if (match !== null && Constants.defaultPinIcons.indexOf(match[1] ) >= 0) { const svg = Svg.All[match[1] + ".svg"] as string const targetColor = match[2] const img = new Img( diff --git a/Models/ThemeConfig/TagRenderingConfig.ts b/Models/ThemeConfig/TagRenderingConfig.ts index 361d57a162..6dc60840e8 100644 --- a/Models/ThemeConfig/TagRenderingConfig.ts +++ b/Models/ThemeConfig/TagRenderingConfig.ts @@ -15,6 +15,7 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement" import {Paragraph} from "../../UI/Base/Paragraph" import Svg from "../../Svg" import Validators, {ValidatorType} from "../../UI/InputElement/Validators"; +import Constants from "../Constants"; export interface Mapping { readonly if: UploadableTag @@ -374,9 +375,12 @@ export default class TagRenderingConfig { let iconClass = commonSize if (mapping.icon !== undefined) { if (typeof mapping.icon === "string" && mapping.icon !== "") { + let stripped = mapping.icon + if (stripped.endsWith(".svg")) { + stripped = stripped.substring(0, stripped.length - 4) + } if ( - Svg.All[mapping.icon] !== undefined || - Svg.All[mapping.icon + ".svg"] !== undefined + Constants.defaultPinIcons.indexOf(stripped) ) { icon = "./assets/svg/" + mapping.icon if (!icon.endsWith(".svg")) {