diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-08 17:05:30 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-08 17:05:30 -0700 |
commit | 2a2f723da4f2b247f06cc766bde32659e054695c (patch) | |
tree | 01053be0303b86cc72c650f8dca8ed492f1f7dca /modern/src/common | |
parent | e082357d5a425875a2d7320f333e99981abdaa39 (diff) | |
download | trackermap-web-2a2f723da4f2b247f06cc766bde32659e054695c.tar.gz trackermap-web-2a2f723da4f2b247f06cc766bde32659e054695c.tar.bz2 trackermap-web-2a2f723da4f2b247f06cc766bde32659e054695c.zip |
Fix course crash (fix #958)
Diffstat (limited to 'modern/src/common')
-rw-r--r-- | modern/src/common/util/formatter.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js index d3ee835a..a743c58b 100644 --- a/modern/src/common/util/formatter.js +++ b/modern/src/common/util/formatter.js @@ -17,7 +17,11 @@ export const formatAlarm = (value, t) => (value ? t(prefixString('alarm', value) export const formatCourse = (value) => { const courseValues = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; - return courseValues[Math.floor(value / 45)]; + let normalizedValue = value % 360; + if (normalizedValue < 0) { + normalizedValue += 360; + } + return courseValues[Math.floor(normalizedValue / 45)]; }; export const formatDistance = (value, unit, t) => `${distanceFromMeters(value, unit).toFixed(2)} ${distanceUnitString(unit, t)}`; |