diff --git a/Logic/SimpleMetaTagger.ts b/Logic/SimpleMetaTagger.ts index 51b518e..f807689 100644 --- a/Logic/SimpleMetaTagger.ts +++ b/Logic/SimpleMetaTagger.ts @@ -10,6 +10,14 @@ import Combine from "../UI/Base/Combine"; import UpdateTagsFromOsmAPI from "./Actors/UpdateTagsFromOsmAPI"; +const cardinalDirections = { + N: 0, NNE: 22.5, NE: 45, ENE: 67.5, + E: 90, ESE: 112.5, SE: 135, SSE: 157.5, + S: 180, SSW: 202.5, SW: 225, WSW: 247.5, + W: 270, WNW: 292.5, NW: 315, NNW: 337.5 +} + + export default class SimpleMetaTagger { static coder: any; public static readonly objectMetaInfo = new SimpleMetaTagger( @@ -172,8 +180,8 @@ export default class SimpleMetaTagger { ) private static directionSimplified = new SimpleMetaTagger( { - keys: ["_direction:simplified", "_direction:leftright"], - doc: "_direction:simplified turns 'camera:direction' and 'direction' into either 0, 45, 90, 135, 180, 225, 270 or 315, whichever is closest. _direction:leftright is either 'left' or 'right', which is left-looking on the map or 'right-looking' on the map" + keys: ["_direction:numerical", "_direction:leftright"], + doc: "_direction:numerical is a normalized, numerical direction based on 'camera:direction' or on 'direction'; it is only present if a valid direction is found (e.g. 38.5 or NE). _direction:leftright is either 'left' or 'right', which is left-looking on the map or 'right-looking' on the map" }, (feature => { const tags = feature.properties; @@ -181,18 +189,16 @@ export default class SimpleMetaTagger { if (direction === undefined) { return; } - let n = Number(direction); + const n = cardinalDirections[direction] ?? Number(direction); if (isNaN(n)) { return; } - // [22.5 -> 67.5] is sector 1 - // [67.5 -> ] is sector 1 - n = (n + 22.5) % 360; - n = Math.floor(n / 45); - tags["_direction:simplified"] = n; - tags["_direction:leftright"] = n <= 3 ? "right" : "left"; + // The % operator has range (-360, 360). We apply a trick to get [0, 360). + const normalized = ((n % 360) + 360) % 360; + tags["_direction:numerical"] = normalized; + tags["_direction:leftright"] = normalized <= 180 ? "right" : "left"; }) ) @@ -399,4 +405,4 @@ export default class SimpleMetaTagger { } -} \ No newline at end of file +} diff --git a/assets/layers/direction/direction.json b/assets/layers/direction/direction.json index da9b20a..dc58a3a 100644 --- a/assets/layers/direction/direction.json +++ b/assets/layers/direction/direction.json @@ -32,17 +32,11 @@ ] }, "rotation": { - "render": "{camera:direction}deg", - "mappings": [ - { - "if": "direction~*", - "then": "{direction}deg" - } - ] + "render": "{_direction:numerical}deg" }, "iconSize": "200,200,center", "color": "--catch-detail-color", "stroke": "0", "presets": [], "wayHandling": 2 -} \ No newline at end of file +} diff --git a/assets/layers/surveillance_camera/surveillance_camera.json b/assets/layers/surveillance_camera/surveillance_camera.json index 9692465..117276e 100644 --- a/assets/layers/surveillance_camera/surveillance_camera.json +++ b/assets/layers/surveillance_camera/surveillance_camera.json @@ -345,7 +345,7 @@ }, "rotation": { "#": "Note: {camera:direction} is substituted by a number, giving the string 'calc(123deg + 90deg)' ; it is this string that is used as css property, which interprets the calc", - "render": "calc({camera:direction}deg + 90deg)", + "render": "calc({_direction:numerical}deg + 90deg)", "mappings": [ { "if": "camera:type=dome", @@ -353,7 +353,7 @@ }, { "if": "_direction:leftright=right", - "then": "calc({camera:direction}deg - 90deg)" + "then": "calc({_direction:numerical}deg - 90deg)" } ] }, @@ -386,4 +386,4 @@ } ], "wayHandling": 2 -} \ No newline at end of file +}