Fix issues with camera rotation

This commit fixes at least these issues that I was aware of:
* Cardinal directions (e.g. NE) were not recognized.
* The camera icon did not rotatie when direction=* was used instead of
  camera:direction, but the blue direction visualizer did.

Pietervdvn said he would have liked to convert the code for direction
normalizing to calculatedTags in a JSON file (as documented in
Docs/CalculatedTags.md), but when he saw the oneliners I had to produce
in response, I was allowed to keep it in SimpleMetaTagger.ts for now.
For your amusement, the oneliners are included below.

    "calculatedTags": [
      "_direction:numerical=(dir => dir === undefined ? undefined : ({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}[dir] ?? (isNaN(parseFloat(dir)) ? undefined : ((parseFloat(dir) % 360 + 360) % 360)))))(feat.properties['camera:direction'] ?? feat.properties.direction)",
      "_direction:leftright=feat.properties['_direction:numerical'] === undefined ? undefined : (feat.properties['_direction:numerical'] <= 180 ? 'right' : 'left')"
    ]
This commit is contained in:
Midgard 2021-04-28 16:45:48 +02:00 committed by pietervdvn
parent a6a897b7a0
commit 122acf8674
3 changed files with 21 additions and 21 deletions

View File

@ -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 {
}
}
}

View File

@ -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
}
}

View File

@ -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
}
}