Themes: add icons, add 'auto'-title-icons

This commit is contained in:
Pieter Vander Vennet 2023-11-29 17:05:45 +01:00
parent 0f545b29cb
commit 2c662c9578
10 changed files with 313 additions and 44 deletions

View file

@ -1,2 +1,2 @@
SPDX-FileCopyrightText: Unkown
SPDX-License-Identifier: CC0
SPDX-License-Identifier: CC0-1.0

View file

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

View file

@ -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": []
}
]

View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
id="svg"
version="1.1"
width="307.91855"
height="343.46448"
viewBox="0 0 307.91855 343.46448"
sodipodi:docname="no_winter.svg"
inkscape:version="1.3.1 (1:1.3.1+202311172155+91b66b0783)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:zoom="1.2257936"
inkscape:cx="190.48884"
inkscape:cy="271.25284"
inkscape:window-width="1920"
inkscape:window-height="995"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg" />
<g
id="g1"
transform="rotate(-0.2875813,162.85132,95.170788)">
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 5.008225,86.10653 302.13815,258.03113"
id="path3"
sodipodi:nodetypes="cc" />
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 153.09023,0.048073 1.65028,343.280557"
id="path3-7"
sodipodi:nodetypes="cc" />
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 302.54004,85.82932 5.2907,257.54738"
id="path4"
sodipodi:nodetypes="cc" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 5.786561,200.08323 53.987051,25.55191 -3.26951,61.20155"
id="path6" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 56.719332,59.041006 3.20013,59.642774 -55.391241,26.23225"
id="path7" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 201.87442,31.964241 152.44006,65.486554 101.3842,31.580519"
id="path8" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 203.26283,313.48917 -49.04644,-34.08735 -51.44157,33.31792"
id="path9" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 300.19729,199.07429 -53.31225,26.93149 4.84196,61.09726"
id="path10" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 251.37871,59.718988 -4.44648,59.562822 54.83066,27.38467"
id="path11" />
</g>
<path
style="fill:#000000;stroke:#e40000;stroke-width:25;stroke-linecap:round;stroke-dasharray:none;stroke-opacity:1"
d="M 23.115301,297.04602 290.36883,29.792506"
id="path1" />
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: Pieter Vander Vennet
SPDX-License-Identifier: CC0-1.0

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
id="svg"
version="1.1"
width="307.54224"
height="343.37671"
viewBox="0 0 307.54224 343.37671"
sodipodi:docname="no_winter.svg"
inkscape:version="1.3.1 (1:1.3.1+202311172155+91b66b0783)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:zoom="1.2257936"
inkscape:cx="190.48884"
inkscape:cy="271.25285"
inkscape:window-width="1920"
inkscape:window-height="995"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg" />
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 5.008225,86.10653 302.13815,258.03113"
id="path3"
sodipodi:nodetypes="cc" />
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 153.09023,0.048073 1.65028,343.280557"
id="path3-7"
sodipodi:nodetypes="cc" />
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 302.54004,85.82932 5.2907,257.54738"
id="path4"
sodipodi:nodetypes="cc" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 5.786561,200.08323 53.987051,25.55191 -3.26951,61.20155"
id="path6" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 56.719332,59.041006 3.20013,59.642774 -55.391241,26.23225"
id="path7" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="M 201.87442,31.964241 152.44006,65.486554 101.3842,31.580519"
id="path8" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 203.26283,313.48917 -49.04644,-34.08735 -51.44157,33.31792"
id="path9" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 300.19729,199.07429 -53.31225,26.93149 4.84196,61.09726"
id="path10" />
<path
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:20;stroke-dasharray:none;stroke-opacity:1"
d="m 251.37871,59.718988 -4.44648,59.562822 54.83066,27.38467"
id="path11" />
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: Pieter Vander Vennet
SPDX-License-Identifier: CC0-1.0

View file

@ -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<string, string> }) {
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(/&lt;/g, "<")?.replace(/&gt;/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<string, string>}) {
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(/&lt;/g,'<')?.replace(/&gt;/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'
}
}

View file

@ -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<LayerConfigJson> {
return json
}
}
export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
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 = <QuestionableTagRenderingConfigJson>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 = `<img class="m-1 h-6 w-6 low-interaction rounded" src='${path}'/>`
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] = <TagRenderingConfigJson>{
id: "title_icon_auto_" + trId,
mappings,
}
}
return json
}
}
export class PrepareLayer extends Fuse<LayerConfigJson> {
constructor(state: DesugaringContext) {
@ -1247,6 +1292,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
),
new SetDefault("titleIcons", ["icons.defaults"]),
new AddRatingBadge(),
new AutoTitleIcon(),
new On(
"titleIcons",
(layer) =>

View file

@ -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:<tagrenderingId>` to automatically create an icon based on a tagRendering which has icons
*
* Type: icon[]
* group: infobox
*/