List which pins are allowed by default

This commit is contained in:
Pieter Vander Vennet 2023-05-08 01:58:33 +02:00
parent b583e930d3
commit 3b28e3ff21
3 changed files with 18 additions and 7 deletions

View file

@ -1,5 +1,6 @@
import { Utils } from "../Utils" import {Utils} from "../Utils"
import * as meta from "../package.json" import * as meta from "../package.json"
export type PriviligedLayerType = typeof Constants.priviliged_layers[number] export type PriviligedLayerType = typeof Constants.priviliged_layers[number]
export default class Constants { export default class Constants {
@ -115,6 +116,11 @@ export default class Constants {
static countryCoderEndpoint: string = static countryCoderEndpoint: string =
"https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/latlon2country" "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/latlon2country"
public static readonly OsmPreferenceKeyPicturesLicense = "pictures-license" 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[] = <any>Constants._defaultPinIcons
private static isRetina(): boolean { private static isRetina(): boolean {
if (Utils.runningFromConsole) { if (Utils.runningFromConsole) {
@ -125,8 +131,8 @@ export default class Constants {
return ( return (
(window.matchMedia && (window.matchMedia &&
(window.matchMedia( (window.matchMedia(
"only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)" "only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)"
).matches || ).matches ||
window.matchMedia( 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)" "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)) || ).matches)) ||

View file

@ -11,6 +11,7 @@ import { FixedUiElement } from "../../UI/Base/FixedUiElement"
import Img from "../../UI/Base/Img" import Img from "../../UI/Base/Img"
import Combine from "../../UI/Base/Combine" import Combine from "../../UI/Base/Combine"
import { VariableUiElement } from "../../UI/Base/VariableUIElement" import { VariableUiElement } from "../../UI/Base/VariableUIElement"
import Constants from "../Constants";
export default class PointRenderingConfig extends WithContextLoader { export default class PointRenderingConfig extends WithContextLoader {
static readonly allowed_location_codes: ReadonlySet<string> = new Set<string>([ static readonly allowed_location_codes: ReadonlySet<string> = new Set<string>([
@ -86,7 +87,7 @@ export default class PointRenderingConfig extends WithContextLoader {
const iconPath = this.icon?.GetRenderValue({ id: "node/-1" })?.txt const iconPath = this.icon?.GetRenderValue({ id: "node/-1" })?.txt
if (iconPath !== undefined && iconPath.startsWith(Utils.assets_path)) { if (iconPath !== undefined && iconPath.startsWith(Utils.assets_path)) {
const iconKey = iconPath.substr(Utils.assets_path.length) 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 throw context + ": builtin SVG asset not found: " + iconPath
} }
} }
@ -109,7 +110,7 @@ export default class PointRenderingConfig extends WithContextLoader {
return undefined return undefined
} }
const match = htmlSpec.match(/([a-zA-Z0-9_]*):([^;]*)/) 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 svg = Svg.All[match[1] + ".svg"] as string
const targetColor = match[2] const targetColor = match[2]
const img = new Img( const img = new Img(

View file

@ -15,6 +15,7 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement"
import {Paragraph} from "../../UI/Base/Paragraph" import {Paragraph} from "../../UI/Base/Paragraph"
import Svg from "../../Svg" import Svg from "../../Svg"
import Validators, {ValidatorType} from "../../UI/InputElement/Validators"; import Validators, {ValidatorType} from "../../UI/InputElement/Validators";
import Constants from "../Constants";
export interface Mapping { export interface Mapping {
readonly if: UploadableTag readonly if: UploadableTag
@ -374,9 +375,12 @@ export default class TagRenderingConfig {
let iconClass = commonSize let iconClass = commonSize
if (mapping.icon !== undefined) { if (mapping.icon !== undefined) {
if (typeof mapping.icon === "string" && mapping.icon !== "") { if (typeof mapping.icon === "string" && mapping.icon !== "") {
let stripped = mapping.icon
if (stripped.endsWith(".svg")) {
stripped = stripped.substring(0, stripped.length - 4)
}
if ( if (
Svg.All[mapping.icon] !== undefined || Constants.defaultPinIcons.indexOf(stripped)
Svg.All[mapping.icon + ".svg"] !== undefined
) { ) {
icon = "./assets/svg/" + mapping.icon icon = "./assets/svg/" + mapping.icon
if (!icon.endsWith(".svg")) { if (!icon.endsWith(".svg")) {