From 4b941f294420f59de2e819f155762ca6db30de90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Fri, 4 Jan 2019 20:29:40 +0100 Subject: [PATCH 1/2] car_maxspeed: handle maxspeed:forward and maxspeed:backward --- car_maxspeed.json | 81 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/car_maxspeed.json b/car_maxspeed.json index b2249f3..6c11f5a 100644 --- a/car_maxspeed.json +++ b/car_maxspeed.json @@ -16,36 +16,67 @@ }, "feature": { "pre": [ - "{% if tags.maxspeed is not defined %}", "{% set maxspeedKmh = null %}", "{% set maxspeed = null %}", "{% set unit = null %}", - "{% else %}", "", - "{% if tags.maxspeed|matches(\"^[0-9]+$\") %}", - "{% set maxspeedKmh = tags.maxspeed %}", - "{% set maxspeed = tags.maxspeed %}", - "{% set unit = \"km/h\" %}", + "{% if tags.maxspeed is defined %}", + " {% if tags.maxspeed|matches(\"^[0-9]+$\") %}", + " {% set maxspeedKmh = tags.maxspeed %}", + " {% set maxspeed = tags.maxspeed %}", + " {% set unit = \"km/h\" %}", + " {% elseif tags.maxspeed|matches( \"(^[0-9]+) mph$\") %}", + " {% set m = tags.maxspeed|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedKmh = m[1] * 1.60934 %}", + " {% set maxspeed = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", - "", - "{% set m = tags.maxspeed|matches(\"(^[0-9]+) mph$\") %}", - "{% if m %}", - "{% set maxspeedKmh = m[1] * 1.60934 %}", - "{% set maxspeed = m[1] %}", - "{% set unit = \"mph\" %}", + "{% if attribute(tags, 'maxspeed:forward') is defined %}", + " {% if attribute(tags, 'maxspeed:forward')|matches(\"^[0-9]+$\") %}", + " {% set maxspeedFKmh = attribute(tags, 'maxspeed:forward') %}", + " {% set maxspeedF = attribute(tags, 'maxspeed:forward') %}", + " {% set unit = \"km/h\" %}", + " {% elseif attribute(tags, 'maxspeed:forward')|matches(\"^[0-9]+ mph$\") %}", + " {% set m = attribute(tags, 'maxspeed:forward')|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedFKmh = m[1] * 1.60934 %}", + " {% set maxspeedF = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", + "{% if attribute(tags, 'maxspeed:backward') is defined %}", + " {% if attribute(tags, 'maxspeed:backward')|matches(\"^[0-9]+$\") %}", + " {% set maxspeedBKmh = attribute(tags, 'maxspeed:backward') %}", + " {% set maxspeedB = attribute(tags, 'maxspeed:backward') %}", + " {% set unit = \"km/h\" %}", + " {% elseif attribute(tags, 'maxspeed:backward')|matches(\"^[0-9]+ mph$\") %}", + " {% set m = attribute(tags, 'maxspeed:backward')|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedBKmh = m[1] * 1.60934 %}", + " {% set maxspeedB = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", "{% if not maxspeedKmh %}", "{% set color = \"#404040\" %}", "{% else %}", "{% set color = colorInterpolate(const.colorMap, (maxspeedKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", + "{% endif %}", + "", + "{% if maxspeedFKmh %}", + "{% set colorF = colorInterpolate(const.colorMap, (maxspeedFKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", + "{% endif %}", + "", + "{% if maxspeedBKmh %}", + "{% set colorB = colorInterpolate(const.colorMap, (maxspeedBKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", "{% endif %}" ], "description": [ - "{% if maxspeed %}", + "{% if maxspeedF or maxspeedB %}", + "{{ maxspeedB|default(trans('unknown')) }} / {{ maxspeedF|default(trans('unknown')) }} {{ unit }}", + "{% elseif maxspeed %}", "{{ maxspeed }} {{ unit }}", "{% elseif tags.maxspeed %}", "{{ tags.maxspeed }}", @@ -53,14 +84,32 @@ "{{ trans('unknown') }}", "{% endif %}" ], - "markerSymbol": null, + "markerSymbol": "", "listMarkerSymbol": "line", + "styles": "{% if maxspeedB or maxspeedF %}left,right,default{% else %}default{% endif %}", "style": { - "width": "3", + "width": "{% if maxspeedB or maxspeedF %}0{% else %}4{% endif %}", "color": "{{ color }}", - "text": "{{ maxspeed }} ", + "text": [ + "{% if maxspeedB or maxspeedF %}", + " {% if maxspeedB %}🡸 {{ maxspeedB }} {% endif %}|{% if maxspeedF %} {{ maxspeedF }} 🡺{% endif %} ", + "{% else %}", + " {{ maxspeed }} ", + "{% endif %}" + ], "textRepeat": "1", + "textOffset": "4", "textFontWeight": "bold" + }, + "style:left": { + "width": "2", + "color": "{{ colorB|default('#404040') }}", + "offset": "-1" + }, + "style:right": { + "width": "2", + "color": "{{ colorF|default('#404040') }}", + "offset": "1" } }, "const": { From 41853b5bf5b1419d486c542e0f6e3b81935fcd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Fri, 4 Jan 2019 20:43:00 +0100 Subject: [PATCH 2/2] railway-maxspeed: handle maxspeed:forward and maxspeed:backward --- railway-maxspeed.json | 79 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/railway-maxspeed.json b/railway-maxspeed.json index 10fb8a4..1c756f2 100644 --- a/railway-maxspeed.json +++ b/railway-maxspeed.json @@ -14,36 +14,67 @@ }, "feature": { "pre": [ - "{% if tags.maxspeed is not defined %}", "{% set maxspeedKmh = null %}", "{% set maxspeed = null %}", "{% set unit = null %}", - "{% else %}", "", - "{% if tags.maxspeed|matches(\"^[0-9]+$\") %}", - "{% set maxspeedKmh = tags.maxspeed %}", - "{% set maxspeed = tags.maxspeed %}", - "{% set unit = \"km/h\" %}", + "{% if tags.maxspeed is defined %}", + " {% if tags.maxspeed|matches(\"^[0-9]+$\") %}", + " {% set maxspeedKmh = tags.maxspeed %}", + " {% set maxspeed = tags.maxspeed %}", + " {% set unit = \"km/h\" %}", + " {% elseif tags.maxspeed|matches( \"(^[0-9]+) mph$\") %}", + " {% set m = tags.maxspeed|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedKmh = m[1] * 1.60934 %}", + " {% set maxspeed = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", - "", - "{% set m = tags.maxspeed|matches(\"(^[0-9]+) mph$\") %}", - "{% if m %}", - "{% set maxspeedKmh = m[1] * 1.60934 %}", - "{% set maxspeed = m[1] %}", - "{% set unit = \"mph\" %}", + "{% if attribute(tags, 'maxspeed:forward') is defined %}", + " {% if attribute(tags, 'maxspeed:forward')|matches(\"^[0-9]+$\") %}", + " {% set maxspeedFKmh = attribute(tags, 'maxspeed:forward') %}", + " {% set maxspeedF = attribute(tags, 'maxspeed:forward') %}", + " {% set unit = \"km/h\" %}", + " {% elseif attribute(tags, 'maxspeed:forward')|matches(\"^[0-9]+ mph$\") %}", + " {% set m = attribute(tags, 'maxspeed:forward')|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedFKmh = m[1] * 1.60934 %}", + " {% set maxspeedF = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", + "{% if attribute(tags, 'maxspeed:backward') is defined %}", + " {% if attribute(tags, 'maxspeed:backward')|matches(\"^[0-9]+$\") %}", + " {% set maxspeedBKmh = attribute(tags, 'maxspeed:backward') %}", + " {% set maxspeedB = attribute(tags, 'maxspeed:backward') %}", + " {% set unit = \"km/h\" %}", + " {% elseif attribute(tags, 'maxspeed:backward')|matches(\"^[0-9]+ mph$\") %}", + " {% set m = attribute(tags, 'maxspeed:backward')|matches(\"(^[0-9]+) mph$\") %}", + " {% set maxspeedBKmh = m[1] * 1.60934 %}", + " {% set maxspeedB = m[1] %}", + " {% set unit = \"mph\" %}", + " {% endif %}", "{% endif %}", "", "{% if not maxspeedKmh %}", "{% set color = \"#404040\" %}", "{% else %}", "{% set color = colorInterpolate(const.colorMap, (maxspeedKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", + "{% endif %}", + "", + "{% if maxspeedFKmh %}", + "{% set colorF = colorInterpolate(const.colorMap, (maxspeedFKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", + "{% endif %}", + "", + "{% if maxspeedBKmh %}", + "{% set colorB = colorInterpolate(const.colorMap, (maxspeedBKmh - const.offsetColorSpeed) / const.highestColorSpeed) %}", "{% endif %}" ], "description": [ - "{% if maxspeed %}", + "{% if maxspeedF or maxspeedB %}", + "{{ maxspeedB|default(trans('unknown')) }} / {{ maxspeedF|default(trans('unknown')) }} {{ unit }}", + "{% elseif maxspeed %}", "{{ maxspeed }} {{ unit }}", "{% elseif tags.maxspeed %}", "{{ tags.maxspeed }}", @@ -53,12 +84,30 @@ ], "markerSymbol": null, "listMarkerSymbol": "line", + "styles": "{% if maxspeedB or maxspeedF %}left,right,default{% else %}default{% endif %}", "style": { - "width": "3", + "width": "{% if maxspeedB or maxspeedF %}0{% else %}4{% endif %}", "color": "{{ color }}", - "text": "{{ maxspeed }} ", + "text": [ + "{% if maxspeedB or maxspeedF %}", + " {% if maxspeedB %}🡸 {{ maxspeedB }} {% endif %}|{% if maxspeedF %} {{ maxspeedF }} 🡺{% endif %} ", + "{% else %}", + " {{ maxspeed }} ", + "{% endif %}" + ], "textRepeat": "1", + "textOffset": "4", "textFontWeight": "bold" + }, + "style:left": { + "width": "2", + "color": "{{ colorB|default('#404040') }}", + "offset": "-1" + }, + "style:right": { + "width": "2", + "color": "{{ colorF|default('#404040') }}", + "offset": "1" } }, "const": {