Themes(maxspeed): support forward/backward, fix #1127

This commit is contained in:
Pieter Vander Vennet 2025-04-18 00:26:53 +02:00
parent 45435703f9
commit 5515114be9
4 changed files with 109 additions and 11 deletions

View file

@ -102,7 +102,13 @@
"render": "#000000", "render": "#000000",
"mappings": [ "mappings": [
{ {
"if": "maxspeed=", "if": {
"and": [
"maxspeed=",
"maxspeed:forward=",
"maxspeed:backward="
]
},
"then": "#ff0000" "then": "#ff0000"
} }
] ]
@ -112,6 +118,7 @@
], ],
"tagRenderings": [ "tagRenderings": [
{ {
"id": "maxspeed-maxspeed",
"render": { "render": {
"en": "The maximum allowed speed on this road is {canonical(maxspeed)}", "en": "The maximum allowed speed on this road is {canonical(maxspeed)}",
"de": "Die zulässige Höchstgeschwindigkeit auf dieser Straße beträgt {canonical(maxspeed)}", "de": "Die zulässige Höchstgeschwindigkeit auf dieser Straße beträgt {canonical(maxspeed)}",
@ -135,7 +142,10 @@
}, },
"freeform": { "freeform": {
"key": "maxspeed", "key": "maxspeed",
"type": "pnat" "type": "pnat",
"addExtraTags": [
"_forward_backward=no"
]
}, },
"mappings": [ "mappings": [
{ {
@ -162,9 +172,70 @@
"maxspeed=20" "maxspeed=20"
], ],
"hideInAnswer": "_country!=be" "hideInAnswer": "_country!=be"
},
{
"if": {
"and": [
"maxspeed=",
"_forward_backward=yes"
]
},
"then": {
"en": "The maximum allowed speed on this road depends on the direction a vehicle goes"
}
} }
], ],
"id": "maxspeed-maxspeed" "condition": {
"or": [
"maxspeed~*",
{
"and": [
"maxspeed:forward=",
"maxspeed:backward="
]
}
]
}
},
{
"id": "maxspeed-forward",
"condition": {
"or": [
"maxspeed:backward~*",
"maxspeed:forward~*",
"_forward_backward=yes"
]
},
"question": {
"en": "What is the maximum allowed speed when travelling {direction_absolute()}?"
},
"render": {
"en": "The maximum allowed speed when travelling {direction_absolute()} on this road is {canonical(maxspeed:forward)}"
},
"freeform": {
"key": "maxspeed:forward",
"type": "pnat"
}
},
{
"id": "maxspeed-backward",
"condition": {
"or": [
"maxspeed:forward~*",
"maxspeed:backward~*",
"_forward_backward=yes"
]
},
"question": {
"en": "What is the maximum allowed speed when travelling {direction_absolute(,180)}?"
},
"render": {
"en": "The maximum allowed speed when travelling {direction_absolute(,180)} on this road is {canonical(maxspeed:backward)}"
},
"freeform": {
"key": "maxspeed:backward",
"type": "pnat"
}
} }
], ],
"allowMove": false, "allowMove": false,
@ -177,6 +248,20 @@
"denominations": [ "denominations": [
"mph" "mph"
] ]
},
"maxspeed:forward": {
"quantity": "speed",
"canonical": "kmh",
"denominations": [
"mph"
]
},
"maxspeed:backward": {
"quantity": "speed",
"canonical": "kmh",
"denominations": [
"mph"
]
} }
} }
] ]

View file

@ -445,6 +445,10 @@ export class Changes {
// Apply tag changes // Apply tag changes
for (const kv of change.tags ?? []) { for (const kv of change.tags ?? []) {
const k = kv.k const k = kv.k
if (k.startsWith("_")) {
// These values are ignored later on anyways
continue
}
let v = kv.v let v = kv.v
if (v === "") { if (v === "") {

View file

@ -14,6 +14,8 @@
</script> </script>
{#if tags?.length > 0} {#if tags?.length > 0}
<div class="flex gap-x-4">
{#each tags as tag} {#each tags as tag}
<div class="break-words" style="word-break: break-word"> <div class="break-words" style="word-break: break-word">
{#if tag["value"] === ""} {#if tag["value"] === ""}
@ -25,6 +27,7 @@
{/if} {/if}
</div> </div>
{/each} {/each}
</div>
{:else} {:else}
<slot name="no-tags"> <slot name="no-tags">
<Tr cls="subtle" t={Translations.t.general.noTagsSelected} /> <Tr cls="subtle" t={Translations.t.general.noTagsSelected} />

View file

@ -1,11 +1,7 @@
import { FixedUiElement } from "./Base/FixedUiElement" import { FixedUiElement } from "./Base/FixedUiElement"
import BaseUIElement from "./BaseUIElement" import BaseUIElement from "./BaseUIElement"
import { default as FeatureTitle } from "./Popup/Title.svelte" import { default as FeatureTitle } from "./Popup/Title.svelte"
import { import { RenderingSpecification, SpecialVisualization, SpecialVisualizationState } from "./SpecialVisualization"
RenderingSpecification,
SpecialVisualization,
SpecialVisualizationState,
} from "./SpecialVisualization"
import { HistogramViz } from "./Popup/HistogramViz" import { HistogramViz } from "./Popup/HistogramViz"
import { UploadToOsmViz } from "./Popup/UploadToOsmViz" import { UploadToOsmViz } from "./Popup/UploadToOsmViz"
import { MultiApplyViz } from "./Popup/MultiApplyViz" import { MultiApplyViz } from "./Popup/MultiApplyViz"
@ -40,8 +36,11 @@ import { UISpecialVisualisations } from "./SpecialVisualisations/UISpecialVisual
import { SettingsVisualisations } from "./SpecialVisualisations/SettingsVisualisations" import { SettingsVisualisations } from "./SpecialVisualisations/SettingsVisualisations"
import { ReviewSpecialVisualisations } from "./SpecialVisualisations/ReviewSpecialVisualisations" import { ReviewSpecialVisualisations } from "./SpecialVisualisations/ReviewSpecialVisualisations"
import { DataImportSpecialVisualisations } from "./SpecialVisualisations/DataImportSpecialVisualisations" import { DataImportSpecialVisualisations } from "./SpecialVisualisations/DataImportSpecialVisualisations"
import TagrenderingManipulationSpecialVisualisations from "./SpecialVisualisations/TagrenderingManipulationSpecialVisualisations" import TagrenderingManipulationSpecialVisualisations
import { WebAndCommunicationSpecialVisualisations } from "./SpecialVisualisations/WebAndCommunicationSpecialVisualisations" from "./SpecialVisualisations/TagrenderingManipulationSpecialVisualisations"
import {
WebAndCommunicationSpecialVisualisations
} from "./SpecialVisualisations/WebAndCommunicationSpecialVisualisations"
import ClearGPSHistory from "./BigComponents/ClearGPSHistory.svelte" import ClearGPSHistory from "./BigComponents/ClearGPSHistory.svelte"
import AllFeaturesStatistics from "./Statistics/AllFeaturesStatistics.svelte" import AllFeaturesStatistics from "./Statistics/AllFeaturesStatistics.svelte"
@ -524,6 +523,11 @@ export default class SpecialVisualizations {
doc: "The attribute containing the degrees", doc: "The attribute containing the degrees",
defaultValue: "_direction:centerpoint", defaultValue: "_direction:centerpoint",
}, },
{
name: "offset",
doc: "Offset value that is added to the actual value, e.g. `180` to indicate the opposite (backward) direction",
defaultValue: "0"
}
], ],
constr( constr(
@ -532,6 +536,8 @@ export default class SpecialVisualizations {
args: string[] args: string[]
): BaseUIElement { ): BaseUIElement {
const key = args[0] === "" ? "_direction:centerpoint" : args[0] const key = args[0] === "" ? "_direction:centerpoint" : args[0]
const offset = args[1] === "" ? 0 : Number(args[1])
return new VariableUiElement( return new VariableUiElement(
tagSource tagSource
.map((tags) => { .map((tags) => {
@ -540,7 +546,7 @@ export default class SpecialVisualizations {
}) })
.mapD((value) => { .mapD((value) => {
const dir = GeoOperations.bearingToHuman( const dir = GeoOperations.bearingToHuman(
GeoOperations.parseBearing(value) GeoOperations.parseBearing(value) + offset
) )
console.log("Human dir", dir) console.log("Human dir", dir)
return Translations.t.general.visualFeedback.directionsAbsolute[dir] return Translations.t.general.visualFeedback.directionsAbsolute[dir]