diff --git a/assets/layers/drinking_water/bottle.svg.license b/assets/layers/drinking_water/bottle.svg.license index 8e8b5805d..1480316c2 100644 --- a/assets/layers/drinking_water/bottle.svg.license +++ b/assets/layers/drinking_water/bottle.svg.license @@ -1,2 +1,2 @@ SPDX-FileCopyrightText: Unkown -SPDX-License-Identifier: CC0 \ No newline at end of file +SPDX-License-Identifier: CC0-1.0 \ No newline at end of file diff --git a/assets/layers/drinking_water/drinking_water.json b/assets/layers/drinking_water/drinking_water.json index 796c8628d..ff9bdb5b9 100644 --- a/assets/layers/drinking_water/drinking_water.json +++ b/assets/layers/drinking_water/drinking_water.json @@ -62,6 +62,7 @@ "cs": "Pitná voda" } }, + "titleIcons": ["icons.defaults", "auto:type", "auto:seasonal"], "pointRendering": [ { "iconBadges": [ @@ -301,6 +302,79 @@ } ] }, + { + "id": "seasonal", + "question": { + "en": "Is this drinking water point available all year round?" + }, + "mappings": [ + { + "if": "seasonal=no", + "then":{ + "en":"This drinking water point is available all around the year" + } + }, + { + "if": "seasonal=summer", + "then":{ + "en":"This drinking water point is only available in summer" + } + }, + { + "if": "seasonal=spring;summer;autumn", + "icon": "./assets/layers/drinking_water/no_winter.svg", + "then":{ + "en":"This drinking water point is closed during the winter" + } + } + ] + }, + {"builtin":["opening_hours_24_7"], + "override": { + "questionHint":{ + "en":"These are the opening hours if the drinking water fountain is operational." + }, + "+mappings":[ + { + "if":{ + "and": [ + "seasonal!=no", + {"or":[ + { + "and":[ + "seasonal!~.*winter.*", + "_now:date~....-(12|01|02)-.." + ] + }, + { + "and":[ + "seasonal!~.*spring.*", + "_now:date~....-(03|04|05)-.." + ] + }, + { + "and":[ + "seasonal!~.*summer.*", + "_now:date~....-(06|07|08)-.." + ] + }, + { + "and":[ + "seasonal!~.*autumn.*", + "_now:date~....-(09|10|11)-.." + ] + } + ]} + ] + }, + "then":{ + "en": "This drinking water fountain is closed this season." + }, + "hideInAnswer":true + } + ] + } + }, { "id": "render-closest-drinking-water", "render": { @@ -316,6 +390,7 @@ }, "condition": "_closest_other_drinking_water_id~*" } + ], "deletion": { "softDeletionTags": { diff --git a/assets/layers/drinking_water/license_info.json b/assets/layers/drinking_water/license_info.json index ce8217e97..57460d021 100644 --- a/assets/layers/drinking_water/license_info.json +++ b/assets/layers/drinking_water/license_info.json @@ -33,6 +33,14 @@ "https://osoc.be/editions/2020/cyclofix" ] }, + { + "path": "no_winter.svg", + "license": "CC0-1.0", + "authors": [ + "Pieter Vander Vennet" + ], + "sources": [] + }, { "path": "tap.svg", "license": "CC0-1.0", @@ -42,5 +50,13 @@ "sources": [ "https://commons.wikimedia.org/wiki/File:Water_DIN-style.svg" ] + }, + { + "path": "winter.svg", + "license": "CC0-1.0", + "authors": [ + "Pieter Vander Vennet" + ], + "sources": [] } ] \ No newline at end of file diff --git a/assets/layers/drinking_water/no_winter.svg b/assets/layers/drinking_water/no_winter.svg new file mode 100644 index 000000000..5e4766a58 --- /dev/null +++ b/assets/layers/drinking_water/no_winter.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + diff --git a/assets/layers/drinking_water/no_winter.svg.license b/assets/layers/drinking_water/no_winter.svg.license new file mode 100644 index 000000000..ed0288300 --- /dev/null +++ b/assets/layers/drinking_water/no_winter.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Pieter Vander Vennet +SPDX-License-Identifier: CC0-1.0 \ No newline at end of file diff --git a/assets/layers/drinking_water/winter.svg b/assets/layers/drinking_water/winter.svg new file mode 100644 index 000000000..f1c2df8b4 --- /dev/null +++ b/assets/layers/drinking_water/winter.svg @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + diff --git a/assets/layers/drinking_water/winter.svg.license b/assets/layers/drinking_water/winter.svg.license new file mode 100644 index 000000000..ed0288300 --- /dev/null +++ b/assets/layers/drinking_water/winter.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Pieter Vander Vennet +SPDX-License-Identifier: CC0-1.0 \ No newline at end of file diff --git a/src/Logic/State/UserSettingsMetaTagging.ts b/src/Logic/State/UserSettingsMetaTagging.ts index 6e568c5c3..33a5ae85b 100644 --- a/src/Logic/State/UserSettingsMetaTagging.ts +++ b/src/Logic/State/UserSettingsMetaTagging.ts @@ -1,42 +1,14 @@ import { Utils } from "../../Utils" /** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */ export class ThemeMetaTagging { - public static readonly themeName = "usersettings" + public static readonly themeName = "usersettings" - public metaTaggging_for_usersettings(feat: { properties: Record }) { - Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_md", () => - feat.properties._description - .match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/) - ?.at(1) - ) - Utils.AddLazyProperty( - feat.properties, - "_d", - () => feat.properties._description?.replace(/</g, "<")?.replace(/>/g, ">") ?? "" - ) - Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_a", () => - ((feat) => { - const e = document.createElement("div") - e.innerHTML = feat.properties._d - return Array.from(e.getElementsByTagName("a")).filter( - (a) => a.href.match(/mastodon|en.osm.town/) !== null - )[0]?.href - })(feat) - ) - Utils.AddLazyProperty(feat.properties, "_mastodon_link", () => - ((feat) => { - const e = document.createElement("div") - e.innerHTML = feat.properties._d - return Array.from(e.getElementsByTagName("a")).filter( - (a) => a.getAttribute("rel")?.indexOf("me") >= 0 - )[0]?.href - })(feat) - ) - Utils.AddLazyProperty( - feat.properties, - "_mastodon_candidate", - () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a - ) - feat.properties["__current_backgroun"] = "initial_value" - } -} + public metaTaggging_for_usersettings(feat: {properties: Record}) { + Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) ) + Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/</g,'<')?.replace(/>/g,'>') ?? '' ) + Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href }) (feat) ) + Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat) ) + Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a ) + feat.properties['__current_backgroun'] = 'initial_value' + } +} \ No newline at end of file diff --git a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts index fd041335c..172b984ae 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -10,10 +10,7 @@ import { SetDefault, } from "./Conversion" import { LayerConfigJson } from "../Json/LayerConfigJson" -import { - MinimalTagRenderingConfigJson, - TagRenderingConfigJson, -} from "../Json/TagRenderingConfigJson" +import { MinimalTagRenderingConfigJson, TagRenderingConfigJson } from "../Json/TagRenderingConfigJson" import { Utils } from "../../../Utils" import RewritableConfigJson from "../Json/RewritableConfigJson" import SpecialVisualizations from "../../../UI/SpecialVisualizations" @@ -26,7 +23,7 @@ import predifined_filters from "../../../../assets/layers/filters/filters.json" import { TagConfigJson } from "../Json/TagConfigJson" import PointRenderingConfigJson, { IconConfigJson } from "../Json/PointRenderingConfigJson" import ValidationUtils from "./ValidationUtils" -import { RenderingSpecification, SpecialVisualization } from "../../../UI/SpecialVisualization" +import { RenderingSpecification } from "../../../UI/SpecialVisualization" import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson" import { ConfigMeta } from "../../../UI/Studio/configMeta" import LineRenderingConfigJson from "../Json/LineRenderingConfigJson" @@ -1220,6 +1217,54 @@ export class AddRatingBadge extends DesugaringStep { return json } } +export class AutoTitleIcon extends DesugaringStep { + constructor() { + super( + "The auto-icon creates a (non-clickable) title icon based on a tagRendering which has icons", + ["titleIcons"], + "AutoTitleIcon" + ) + } + + convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson { + json = { ...json } + json.titleIcons = [...json.titleIcons] + for (let i = 0; i < json.titleIcons.length; i++) { + const titleIcon = json.titleIcons[i] + if (typeof titleIcon !== "string") { + continue + } + if (!titleIcon.startsWith("auto:")) { + continue + } + const trId = titleIcon.substring("auto:".length) + const tr = json.tagRenderings.find((tr) => tr["id"] === trId) + if (tr === undefined) { + context + .enters("titleIcons", i) + .err("TagRendering with id " + trId + " not found") + continue + } + const mappings: { if: TagConfigJson, then: string }[] = tr.mappings?.filter(m => m.icon !== undefined) + .map(m => { + const path: string = typeof m.icon === "string" ? m.icon : m.icon.path + const img = `` + return ({ if: m.if, then: img }) + }) + if (mappings.length === 0) { + context + .enters("titleIcons", i) + .warn("TagRendering with id " + trId + " does not have any icons, not generating an icon for this") + continue + } + json.titleIcons[i] = { + id: "title_icon_auto_" + trId, + mappings, + } + } + return json + } +} export class PrepareLayer extends Fuse { constructor(state: DesugaringContext) { @@ -1247,6 +1292,7 @@ export class PrepareLayer extends Fuse { ), new SetDefault("titleIcons", ["icons.defaults"]), new AddRatingBadge(), + new AutoTitleIcon(), new On( "titleIcons", (layer) => diff --git a/src/Models/ThemeConfig/Json/LayerConfigJson.ts b/src/Models/ThemeConfig/Json/LayerConfigJson.ts index 0cd857bde..50e5870bc 100644 --- a/src/Models/ThemeConfig/Json/LayerConfigJson.ts +++ b/src/Models/ThemeConfig/Json/LayerConfigJson.ts @@ -240,6 +240,8 @@ export interface LayerConfigJson { * Use an empty array to hide them. * Note that "defaults" will insert all the default titleIcons (which are added automatically) * + * Use `auto:` to automatically create an icon based on a tagRendering which has icons + * * Type: icon[] * group: infobox */