2020-11-06 01:58:26 +01:00
|
|
|
import Translations from "../../UI/i18n/Translations";
|
2020-10-27 01:01:34 +01:00
|
|
|
import TagRenderingConfig from "./TagRenderingConfig";
|
|
|
|
import {LayerConfigJson} from "./LayerConfigJson";
|
|
|
|
import {FromJSON} from "./FromJSON";
|
|
|
|
import SharedTagRenderings from "../SharedTagRenderings";
|
|
|
|
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
2020-11-06 01:58:26 +01:00
|
|
|
import {Translation} from "../../UI/i18n/Translation";
|
2021-01-03 00:19:42 +01:00
|
|
|
import Img from "../../UI/Base/Img";
|
2020-11-06 04:02:53 +01:00
|
|
|
import Svg from "../../Svg";
|
2021-04-10 03:50:44 +02:00
|
|
|
|
2020-11-17 02:22:48 +01:00
|
|
|
import {Utils} from "../../Utils";
|
|
|
|
import Combine from "../../UI/Base/Combine";
|
2020-11-17 16:29:51 +01:00
|
|
|
import {VariableUiElement} from "../../UI/Base/VariableUIElement";
|
2020-11-27 01:39:54 +01:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-12-06 00:20:27 +01:00
|
|
|
import {FixedUiElement} from "../../UI/Base/FixedUiElement";
|
2020-12-02 21:23:23 +01:00
|
|
|
import {UIElement} from "../../UI/UIElement";
|
2021-02-05 16:32:37 +01:00
|
|
|
import {SubstitutedTranslation} from "../../UI/SubstitutedTranslation";
|
2021-03-20 23:45:52 +01:00
|
|
|
import SourceConfig from "./SourceConfig";
|
2021-03-29 00:41:53 +02:00
|
|
|
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
|
|
|
import {Tag} from "../../Logic/Tags/Tag";
|
2021-04-06 18:17:07 +02:00
|
|
|
import SubstitutingTag from "../../Logic/Tags/SubstitutingTag";
|
2021-04-10 23:53:13 +02:00
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
export default class LayerConfig {
|
2020-11-17 02:22:48 +01:00
|
|
|
|
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
static WAYHANDLING_DEFAULT = 0;
|
|
|
|
static WAYHANDLING_CENTER_ONLY = 1;
|
|
|
|
static WAYHANDLING_CENTER_AND_WAY = 2;
|
2021-03-26 03:24:58 +01:00
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
id: string;
|
|
|
|
name: Translation
|
|
|
|
description: Translation;
|
2021-03-20 23:45:52 +01:00
|
|
|
source: SourceConfig;
|
2021-03-24 01:25:57 +01:00
|
|
|
calculatedTags: [string, string][]
|
2020-11-17 02:22:48 +01:00
|
|
|
doNotDownload: boolean;
|
|
|
|
passAllFeatures: boolean;
|
2021-03-25 15:19:44 +01:00
|
|
|
isShown: TagRenderingConfig;
|
2020-10-27 01:01:34 +01:00
|
|
|
minzoom: number;
|
2021-03-21 01:36:34 +01:00
|
|
|
maxzoom: number;
|
2020-11-17 02:22:48 +01:00
|
|
|
title?: TagRenderingConfig;
|
2020-10-27 01:01:34 +01:00
|
|
|
titleIcons: TagRenderingConfig[];
|
2020-10-27 14:46:40 +01:00
|
|
|
icon: TagRenderingConfig;
|
2020-12-06 00:20:27 +01:00
|
|
|
iconOverlays: { if: TagsFilter, then: TagRenderingConfig, badge: boolean }[]
|
2020-10-27 14:46:40 +01:00
|
|
|
iconSize: TagRenderingConfig;
|
2021-04-10 23:53:13 +02:00
|
|
|
label: TagRenderingConfig;
|
2020-11-17 02:22:48 +01:00
|
|
|
rotation: TagRenderingConfig;
|
2020-10-27 14:46:40 +01:00
|
|
|
color: TagRenderingConfig;
|
|
|
|
width: TagRenderingConfig;
|
2020-10-30 00:56:46 +01:00
|
|
|
dashArray: TagRenderingConfig;
|
2020-10-27 01:01:34 +01:00
|
|
|
wayHandling: number;
|
|
|
|
|
|
|
|
presets: {
|
|
|
|
title: Translation,
|
|
|
|
tags: Tag[],
|
|
|
|
description?: Translation,
|
|
|
|
}[];
|
|
|
|
|
|
|
|
tagRenderings: TagRenderingConfig [];
|
2021-03-24 01:25:57 +01:00
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
constructor(json: LayerConfigJson,
|
2021-03-24 02:01:04 +01:00
|
|
|
context?: string,
|
|
|
|
official: boolean = true,) {
|
2020-10-27 01:01:34 +01:00
|
|
|
context = context + "." + json.id;
|
2021-01-08 03:57:18 +01:00
|
|
|
const self = this;
|
2020-10-27 01:01:34 +01:00
|
|
|
this.id = json.id;
|
2021-03-15 16:23:04 +01:00
|
|
|
this.name = Translations.T(json.name, context + ".name");
|
|
|
|
this.description = Translations.T(json.description, context + ".description");
|
2021-03-20 23:45:52 +01:00
|
|
|
|
|
|
|
let legacy = undefined;
|
|
|
|
if (json["overpassTags"] !== undefined) {
|
|
|
|
// @ts-ignore
|
|
|
|
legacy = FromJSON.Tag(json["overpassTags"], context + ".overpasstags");
|
|
|
|
}
|
2021-03-24 01:25:57 +01:00
|
|
|
if (json.source !== undefined) {
|
|
|
|
if (legacy !== undefined) {
|
|
|
|
throw context + "Both the legacy 'layer.overpasstags' and the new 'layer.source'-field are defined"
|
2021-03-20 23:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let osmTags: TagsFilter = legacy;
|
|
|
|
if (json.source["osmTags"]) {
|
|
|
|
osmTags = FromJSON.Tag(json.source["osmTags"], context + "source.osmTags");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.source = new SourceConfig({
|
|
|
|
osmTags: osmTags,
|
2021-03-29 02:53:06 +02:00
|
|
|
geojsonSource: json.source["geoJson"],
|
2021-03-20 23:45:52 +01:00
|
|
|
overpassScript: json.source["overpassScript"],
|
|
|
|
});
|
2021-03-24 01:25:57 +01:00
|
|
|
} else {
|
2021-03-20 23:45:52 +01:00
|
|
|
this.source = new SourceConfig({
|
2021-03-24 01:25:57 +01:00
|
|
|
osmTags: legacy
|
2021-03-20 23:45:52 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-24 01:25:57 +01:00
|
|
|
this.calculatedTags = undefined;
|
|
|
|
if (json.calculatedTags !== undefined) {
|
2021-03-24 02:01:04 +01:00
|
|
|
if (!official) {
|
|
|
|
console.warn(`Unofficial theme ${this.id} with custom javascript! This is a security risk`)
|
|
|
|
}
|
2021-03-24 01:25:57 +01:00
|
|
|
this.calculatedTags = [];
|
2021-03-26 03:24:58 +01:00
|
|
|
for (const kv of json.calculatedTags) {
|
|
|
|
|
|
|
|
const index = kv.indexOf("=")
|
|
|
|
const key = kv.substring(0, index);
|
|
|
|
const code = kv.substring(index + 1);
|
|
|
|
|
|
|
|
this.calculatedTags.push([key, code])
|
2021-03-24 01:25:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-20 23:45:52 +01:00
|
|
|
this.doNotDownload = json.doNotDownload ?? false;
|
|
|
|
this.passAllFeatures = json.passAllFeatures ?? false;
|
2021-03-21 01:36:34 +01:00
|
|
|
this.minzoom = json.minzoom ?? 0;
|
|
|
|
this.maxzoom = json.maxzoom ?? 1000;
|
2020-10-27 01:01:34 +01:00
|
|
|
this.wayHandling = json.wayHandling ?? 0;
|
2021-03-13 19:08:31 +01:00
|
|
|
this.presets = (json.presets ?? []).map((pr, i) =>
|
2020-10-30 00:56:46 +01:00
|
|
|
({
|
2021-03-13 19:08:31 +01:00
|
|
|
title: Translations.T(pr.title, `${context}.presets[${i}].title`),
|
2020-10-30 00:56:46 +01:00
|
|
|
tags: pr.tags.map(t => FromJSON.SimpleTag(t)),
|
2021-03-13 19:08:31 +01:00
|
|
|
description: Translations.T(pr.description, `${context}.presets[${i}].description`)
|
2020-10-30 00:56:46 +01:00
|
|
|
}))
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
/** Given a key, gets the corresponding property from the json (or the default if not found
|
|
|
|
*
|
|
|
|
* The found value is interpreted as a tagrendering and fetched/parsed
|
|
|
|
* */
|
|
|
|
function tr(key: string, deflt) {
|
|
|
|
const v = json[key];
|
|
|
|
if (v === undefined || v === null) {
|
|
|
|
if (deflt === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-03-20 23:45:52 +01:00
|
|
|
return new TagRenderingConfig(deflt, self.source.osmTags, `${context}.${key}.default value`);
|
2021-01-08 03:57:18 +01:00
|
|
|
}
|
|
|
|
if (typeof v === "string") {
|
2021-04-21 01:26:36 +02:00
|
|
|
const shared = SharedTagRenderings.SharedTagRendering.get(v);
|
2021-01-08 03:57:18 +01:00
|
|
|
if (shared) {
|
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
}
|
2021-03-20 23:45:52 +01:00
|
|
|
return new TagRenderingConfig(v, self.source.osmTags, `${context}.${key}`);
|
2021-01-08 03:57:18 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
/**
|
|
|
|
* Converts a list of tagRenderingCOnfigJSON in to TagRenderingConfig
|
|
|
|
* A string is interpreted as a name to call
|
|
|
|
*/
|
2021-03-21 01:32:21 +01:00
|
|
|
function trs(tagRenderings?: (string | TagRenderingConfigJson)[], readOnly = false) {
|
2020-10-27 01:01:34 +01:00
|
|
|
if (tagRenderings === undefined) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-01-08 03:57:18 +01:00
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
return tagRenderings.map(
|
|
|
|
(renderingJson, i) => {
|
|
|
|
if (typeof renderingJson === "string") {
|
2021-01-08 03:57:18 +01:00
|
|
|
|
|
|
|
if (renderingJson === "questions") {
|
2021-03-24 01:25:57 +01:00
|
|
|
if (readOnly) {
|
2021-03-21 01:32:21 +01:00
|
|
|
throw `A tagrendering has a question, but asking a question does not make sense here: is it a title icon or a geojson-layer? ${context}`
|
|
|
|
}
|
2021-03-24 01:25:57 +01:00
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
return new TagRenderingConfig("questions", undefined)
|
2020-12-08 23:44:34 +01:00
|
|
|
}
|
2021-01-08 03:57:18 +01:00
|
|
|
|
|
|
|
|
2021-04-21 01:26:36 +02:00
|
|
|
const shared = SharedTagRenderings.SharedTagRendering.get(renderingJson);
|
2020-10-27 01:01:34 +01:00
|
|
|
if (shared !== undefined) {
|
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
throw `Predefined tagRendering ${renderingJson} not found in ${context}`;
|
|
|
|
}
|
2021-03-20 23:45:52 +01:00
|
|
|
return new TagRenderingConfig(renderingJson, self.source.osmTags, `${context}.tagrendering[${i}]`);
|
2020-10-27 01:01:34 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-21 01:32:21 +01:00
|
|
|
this.tagRenderings = trs(json.tagRenderings, this.source.geojsonSource !== undefined);
|
2020-11-24 12:52:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
const titleIcons = [];
|
|
|
|
const defaultIcons = ["phonelink", "emaillink", "wikipedialink", "osmlink", "sharelink"];
|
|
|
|
for (const icon of (json.titleIcons ?? defaultIcons)) {
|
|
|
|
if (icon === "defaults") {
|
|
|
|
titleIcons.push(...defaultIcons);
|
|
|
|
} else {
|
|
|
|
titleIcons.push(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 01:32:21 +01:00
|
|
|
this.titleIcons = trs(titleIcons, true);
|
2020-11-24 12:52:01 +01:00
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
|
2020-11-17 02:22:48 +01:00
|
|
|
this.title = tr("title", undefined);
|
2021-04-11 19:21:41 +02:00
|
|
|
this.icon = tr("icon", "");
|
2021-01-08 03:57:18 +01:00
|
|
|
this.iconOverlays = (json.iconOverlays ?? []).map((overlay, i) => {
|
2021-03-20 23:45:52 +01:00
|
|
|
let tr = new TagRenderingConfig(overlay.then, self.source.osmTags, `iconoverlays.${i}`);
|
2021-04-21 01:26:36 +02:00
|
|
|
if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons.get(overlay.then) !== undefined) {
|
|
|
|
tr = SharedTagRenderings.SharedIcons.get(overlay.then);
|
2020-12-06 00:20:27 +01:00
|
|
|
}
|
2020-11-27 03:05:29 +01:00
|
|
|
return {
|
|
|
|
if: FromJSON.Tag(overlay.if),
|
2020-12-06 00:20:27 +01:00
|
|
|
then: tr,
|
2020-11-27 03:05:29 +01:00
|
|
|
badge: overlay.badge ?? false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-17 02:22:48 +01:00
|
|
|
const iconPath = this.icon.GetRenderValue({id: "node/-1"}).txt;
|
|
|
|
if (iconPath.startsWith(Utils.assets_path)) {
|
|
|
|
const iconKey = iconPath.substr(Utils.assets_path.length);
|
|
|
|
if (Svg.All[iconKey] === undefined) {
|
|
|
|
throw "Builtin SVG asset not found: " + iconPath
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 15:19:44 +01:00
|
|
|
this.isShown = tr("isShown", "yes");
|
2020-10-27 01:01:34 +01:00
|
|
|
this.iconSize = tr("iconSize", "40,40,center");
|
2021-04-10 23:53:13 +02:00
|
|
|
this.label = tr("label", "")
|
2020-10-27 01:01:34 +01:00
|
|
|
this.color = tr("color", "#0000ff");
|
|
|
|
this.width = tr("width", "7");
|
2020-11-17 02:22:48 +01:00
|
|
|
this.rotation = tr("rotation", "0");
|
2020-10-30 00:56:46 +01:00
|
|
|
this.dashArray = tr("dashArray", "");
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
|
2021-04-06 18:17:07 +02:00
|
|
|
if (json["showIf"] !== undefined) {
|
|
|
|
throw "Invalid key on layerconfig " + this.id + ": showIf. Did you mean 'isShown' instead?";
|
2021-03-26 03:24:58 +01:00
|
|
|
}
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|
2020-11-16 01:59:30 +01:00
|
|
|
|
2021-03-24 02:01:04 +01:00
|
|
|
public CustomCodeSnippets(): string[] {
|
|
|
|
if (this.calculatedTags === undefined) {
|
2021-03-24 01:25:57 +01:00
|
|
|
return []
|
|
|
|
}
|
2021-03-24 02:01:04 +01:00
|
|
|
|
2021-03-24 01:25:57 +01:00
|
|
|
return this.calculatedTags.map(code => code[1]);
|
|
|
|
}
|
2020-11-16 01:59:30 +01:00
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
public AddRoamingRenderings(addAll: {
|
|
|
|
tagRenderings: TagRenderingConfig[],
|
|
|
|
titleIcons: TagRenderingConfig[],
|
|
|
|
iconOverlays: { "if": TagsFilter, then: TagRenderingConfig, badge: boolean }[]
|
|
|
|
|
|
|
|
}): LayerConfig {
|
2021-03-15 16:23:04 +01:00
|
|
|
|
|
|
|
let insertionPoint = this.tagRenderings.map(tr => tr.IsQuestionBoxElement()).indexOf(true)
|
|
|
|
if (insertionPoint < 0) {
|
|
|
|
// No 'questions' defined - we just add them all to the end
|
|
|
|
insertionPoint = this.tagRenderings.length;
|
|
|
|
}
|
|
|
|
this.tagRenderings.splice(insertionPoint, 0, ...addAll.tagRenderings);
|
|
|
|
|
|
|
|
|
2021-01-08 03:57:18 +01:00
|
|
|
this.iconOverlays.push(...addAll.iconOverlays);
|
|
|
|
for (const icon of addAll.titleIcons) {
|
2021-03-15 16:23:04 +01:00
|
|
|
this.titleIcons.splice(0, 0, icon);
|
2021-01-08 03:57:18 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GetRoamingRenderings(): {
|
|
|
|
tagRenderings: TagRenderingConfig[],
|
|
|
|
titleIcons: TagRenderingConfig[],
|
|
|
|
iconOverlays: { "if": TagsFilter, then: TagRenderingConfig, badge: boolean }[]
|
|
|
|
|
|
|
|
} {
|
|
|
|
|
|
|
|
const tagRenderings = this.tagRenderings.filter(tr => tr.roaming);
|
|
|
|
const titleIcons = this.titleIcons.filter(tr => tr.roaming);
|
|
|
|
const iconOverlays = this.iconOverlays.filter(io => io.then.roaming)
|
|
|
|
|
|
|
|
return {
|
|
|
|
tagRenderings: tagRenderings,
|
|
|
|
titleIcons: titleIcons,
|
|
|
|
iconOverlays: iconOverlays
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-27 01:39:54 +01:00
|
|
|
public GenerateLeafletStyle(tags: UIEventSource<any>, clickable: boolean):
|
2020-11-16 01:59:30 +01:00
|
|
|
{
|
2021-01-08 03:57:18 +01:00
|
|
|
icon:
|
|
|
|
{
|
|
|
|
html: UIElement,
|
|
|
|
iconSize: [number, number],
|
|
|
|
iconAnchor: [number, number],
|
|
|
|
popupAnchor: [number, number],
|
|
|
|
iconUrl: string,
|
|
|
|
className: string
|
|
|
|
},
|
|
|
|
color: string,
|
|
|
|
weight: number,
|
|
|
|
dashArray: number[]
|
2020-11-16 01:59:30 +01:00
|
|
|
} {
|
|
|
|
|
|
|
|
function num(str, deflt = 40) {
|
|
|
|
const n = Number(str);
|
|
|
|
if (isNaN(n)) {
|
|
|
|
return deflt;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:22:48 +01:00
|
|
|
function rendernum(tr: TagRenderingConfig, deflt: number) {
|
|
|
|
const str = Number(render(tr, "" + deflt));
|
|
|
|
const n = Number(str);
|
|
|
|
if (isNaN(n)) {
|
|
|
|
return deflt;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
function render(tr: TagRenderingConfig, deflt?: string) {
|
2020-11-27 01:39:54 +01:00
|
|
|
const str = (tr?.GetRenderValue(tags.data)?.txt ?? deflt);
|
2021-04-06 21:10:18 +02:00
|
|
|
return SubstitutedTranslation.SubstituteKeys(str, tags.data).replace(/{.*}/g, "");
|
2020-11-17 02:22:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const iconSize = render(this.iconSize, "40,40,center").split(",");
|
|
|
|
const dashArray = render(this.dashArray).split(" ").map(Number);
|
|
|
|
let color = render(this.color, "#00f");
|
|
|
|
|
|
|
|
if (color.startsWith("--")) {
|
|
|
|
color = getComputedStyle(document.body).getPropertyValue("--catch-detail-color")
|
|
|
|
}
|
|
|
|
|
|
|
|
const weight = rendernum(this.width, 5);
|
|
|
|
|
2020-11-16 01:59:30 +01:00
|
|
|
const iconW = num(iconSize[0]);
|
2021-04-11 00:09:19 +02:00
|
|
|
let iconH = num(iconSize[1]);
|
2020-11-16 01:59:30 +01:00
|
|
|
const mode = iconSize[2] ?? "center"
|
|
|
|
|
|
|
|
let anchorW = iconW / 2;
|
|
|
|
let anchorH = iconH / 2;
|
|
|
|
if (mode === "left") {
|
|
|
|
anchorW = 0;
|
|
|
|
}
|
|
|
|
if (mode === "right") {
|
|
|
|
anchorW = iconW;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode === "top") {
|
|
|
|
anchorH = 0;
|
|
|
|
}
|
|
|
|
if (mode === "bottom") {
|
|
|
|
anchorH = iconH;
|
|
|
|
}
|
|
|
|
|
2020-11-27 01:39:54 +01:00
|
|
|
const iconUrlStatic = render(this.icon);
|
2020-11-27 03:05:29 +01:00
|
|
|
const self = this;
|
2021-03-20 23:45:52 +01:00
|
|
|
const mappedHtml = tags.map(tgs => {
|
2020-12-06 00:20:27 +01:00
|
|
|
function genHtmlFromString(sourcePart: string): UIElement {
|
2021-04-06 18:17:07 +02:00
|
|
|
if (sourcePart.indexOf("html:") == 0) {
|
|
|
|
// We use § as a replacement for ;
|
|
|
|
const html = sourcePart.substring("html:".length)
|
|
|
|
const inner = new FixedUiElement(SubstitutingTag.substituteString(html, tgs)).SetClass("block w-min text-center")
|
|
|
|
const outer = new Combine([inner]).SetClass("flex flex-col items-center")
|
|
|
|
return outer;
|
|
|
|
}
|
|
|
|
|
2021-01-18 19:36:19 +01:00
|
|
|
const style = `width:100%;height:100%;transform: rotate( ${rotation} );display:block;position: absolute; top: 0; left: 0`;
|
2020-12-06 00:20:27 +01:00
|
|
|
let html: UIElement = new FixedUiElement(`<img src="${sourcePart}" style="${style}" />`);
|
2021-01-04 04:06:21 +01:00
|
|
|
const match = sourcePart.match(/([a-zA-Z0-9_]*):([^;]*)/)
|
2020-11-27 03:05:29 +01:00
|
|
|
if (match !== null && Svg.All[match[1] + ".svg"] !== undefined) {
|
|
|
|
html = new Combine([
|
|
|
|
(Svg.All[match[1] + ".svg"] as string)
|
2021-01-08 03:57:18 +01:00
|
|
|
.replace(/#000000/g, match[2])
|
2020-12-06 00:20:27 +01:00
|
|
|
]).SetStyle(style);
|
2020-11-27 03:05:29 +01:00
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-06 18:17:07 +02:00
|
|
|
// What do you mean, 'tgs' is never read?
|
|
|
|
// It is read implicitly in the 'render' method
|
|
|
|
const iconUrl = render(self.icon);
|
|
|
|
const rotation = render(self.rotation, "0deg");
|
|
|
|
|
|
|
|
let htmlParts: UIElement[] = [];
|
2021-04-11 00:09:19 +02:00
|
|
|
let sourceParts = Utils.NoNull(iconUrl.split(";").filter(prt => prt != ""));
|
2020-11-27 03:05:29 +01:00
|
|
|
for (const sourcePart of sourceParts) {
|
|
|
|
htmlParts.push(genHtmlFromString(sourcePart))
|
|
|
|
}
|
|
|
|
|
|
|
|
let badges = [];
|
|
|
|
for (const iconOverlay of self.iconOverlays) {
|
2020-12-06 00:20:27 +01:00
|
|
|
if (!iconOverlay.if.matchesProperties(tgs)) {
|
2020-11-27 03:05:29 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (iconOverlay.badge) {
|
2020-12-06 00:20:27 +01:00
|
|
|
const badgeParts: UIElement[] = [];
|
2021-04-10 23:53:13 +02:00
|
|
|
const partDefs = iconOverlay.then.GetRenderValue(tgs).txt.split(";").filter(prt => prt != "");
|
2020-12-02 21:23:23 +01:00
|
|
|
|
|
|
|
for (const badgePartStr of partDefs) {
|
|
|
|
badgeParts.push(genHtmlFromString(badgePartStr))
|
|
|
|
}
|
|
|
|
|
|
|
|
const badgeCompound = new Combine(badgeParts)
|
|
|
|
.SetStyle("display:flex;position:relative;width:100%;height:100%;");
|
|
|
|
|
|
|
|
badges.push(badgeCompound)
|
|
|
|
|
2020-11-27 03:05:29 +01:00
|
|
|
} else {
|
2020-12-06 00:20:27 +01:00
|
|
|
htmlParts.push(genHtmlFromString(
|
|
|
|
iconOverlay.then.GetRenderValue(tgs).txt));
|
2020-11-27 03:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (badges.length > 0) {
|
|
|
|
const badgesComponent = new Combine(badges)
|
2020-12-06 00:20:27 +01:00
|
|
|
.SetStyle("display:flex;height:50%;width:100%;position:absolute;top:50%;left:50%;");
|
2020-11-27 03:05:29 +01:00
|
|
|
htmlParts.push(badgesComponent)
|
2020-11-27 01:39:54 +01:00
|
|
|
}
|
2021-04-10 23:53:13 +02:00
|
|
|
|
2021-04-21 01:26:36 +02:00
|
|
|
if (sourceParts.length == 0) {
|
|
|
|
iconH = 0
|
|
|
|
}
|
|
|
|
try {
|
2021-04-10 23:53:13 +02:00
|
|
|
|
2021-04-21 01:26:36 +02:00
|
|
|
const label = self.label?.GetRenderValue(tgs)?.Subs(tgs)
|
|
|
|
?.SetClass("block w-min text-center")
|
|
|
|
?.SetStyle("margin-top: " + (iconH + 2) + "px")
|
|
|
|
if (label !== undefined) {
|
|
|
|
htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center"))
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e, tgs)
|
2021-04-10 23:53:13 +02:00
|
|
|
}
|
2020-12-06 00:20:27 +01:00
|
|
|
return new Combine(htmlParts).Render();
|
2020-11-27 01:39:54 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-11-16 01:59:30 +01:00
|
|
|
return {
|
|
|
|
icon:
|
|
|
|
{
|
2020-12-06 00:20:27 +01:00
|
|
|
html: new VariableUiElement(mappedHtml),
|
2020-11-16 01:59:30 +01:00
|
|
|
iconSize: [iconW, iconH],
|
|
|
|
iconAnchor: [anchorW, anchorH],
|
2020-11-17 02:22:48 +01:00
|
|
|
popupAnchor: [0, 3 - anchorH],
|
2020-11-27 01:39:54 +01:00
|
|
|
iconUrl: iconUrlStatic,
|
2020-11-17 16:29:51 +01:00
|
|
|
className: clickable ? "leaflet-div-icon" : "leaflet-div-icon unclickable"
|
2020-11-16 01:59:30 +01:00
|
|
|
},
|
|
|
|
color: color,
|
|
|
|
weight: weight,
|
|
|
|
dashArray: dashArray
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-09 02:57:06 +02:00
|
|
|
public ExtractImages(): Set<string> {
|
|
|
|
const parts: Set<string>[] = []
|
|
|
|
parts.push(...this.tagRenderings?.map(tr => tr.ExtractImages(false)))
|
|
|
|
parts.push(...this.titleIcons?.map(tr => tr.ExtractImages(true)))
|
|
|
|
parts.push(this.icon?.ExtractImages(true))
|
|
|
|
parts.push(...this.iconOverlays?.map(overlay => overlay.then.ExtractImages(true)))
|
|
|
|
for (const preset of this.presets) {
|
|
|
|
parts.push(new Set<string>(preset.description?.ExtractImages(false)))
|
|
|
|
}
|
2021-04-10 23:53:13 +02:00
|
|
|
|
2021-04-09 02:57:06 +02:00
|
|
|
const allIcons = new Set<string>();
|
|
|
|
for (const part of parts) {
|
|
|
|
part?.forEach(allIcons.add, allIcons)
|
|
|
|
}
|
|
|
|
|
|
|
|
return allIcons;
|
|
|
|
}
|
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|