diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-05 16:43:42 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-05 16:43:42 -0700 |
commit | 8bde80a8cd1fb9b92f4867edbeeae48158f9036b (patch) | |
tree | 493edc77a38e4e39b438c4255a02cf843eedc821 /modern/src/common/util | |
parent | dad1892d4718f15c9ecdd301db140d66d52da6b3 (diff) | |
download | trackermap-web-8bde80a8cd1fb9b92f4867edbeeae48158f9036b.tar.gz trackermap-web-8bde80a8cd1fb9b92f4867edbeeae48158f9036b.tar.bz2 trackermap-web-8bde80a8cd1fb9b92f4867edbeeae48158f9036b.zip |
Configurable altitude units
Diffstat (limited to 'modern/src/common/util')
-rw-r--r-- | modern/src/common/util/converter.js | 24 | ||||
-rw-r--r-- | modern/src/common/util/formatter.js | 11 |
2 files changed, 34 insertions, 1 deletions
diff --git a/modern/src/common/util/converter.js b/modern/src/common/util/converter.js index 559e68aa..cb21566b 100644 --- a/modern/src/common/util/converter.js +++ b/modern/src/common/util/converter.js @@ -54,6 +54,30 @@ export const distanceFromMeters = (value, unit) => value * distanceConverter(uni export const distanceToMeters = (value, unit) => value / distanceConverter(unit); +const altitudeConverter = (unit) => { + switch (unit) { + case 'ft': + return 3.28084; + case 'm': + default: + return 1; + } +}; + +export const altitudeUnitString = (unit, t) => { + switch (unit) { + case 'ft': + return t('sharedFeet'); + case 'm': + default: + return t('sharedMeters'); + } +}; + +export const altitudeFromMeters = (value, unit) => value * altitudeConverter(unit); + +export const altitudeToMeters = (value, unit) => value / altitudeConverter(unit); + const volumeConverter = (unit) => { switch (unit) { case 'impGal': diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js index 034b0401..f36b4d38 100644 --- a/modern/src/common/util/formatter.js +++ b/modern/src/common/util/formatter.js @@ -1,6 +1,13 @@ import moment from 'moment'; import { - distanceFromMeters, distanceUnitString, speedFromKnots, speedUnitString, volumeFromLiters, volumeUnitString, + altitudeFromMeters, + altitudeUnitString, + distanceFromMeters, + distanceUnitString, + speedFromKnots, + speedUnitString, + volumeFromLiters, + volumeUnitString, } from './converter'; import { prefixString } from './stringUtils'; @@ -26,6 +33,8 @@ export const formatCourse = (value) => { export const formatDistance = (value, unit, t) => `${distanceFromMeters(value, unit).toFixed(2)} ${distanceUnitString(unit, t)}`; +export const formatAltitude = (value, unit, t) => `${altitudeFromMeters(value, unit).toFixed(2)} ${altitudeUnitString(unit, t)}`; + export const formatSpeed = (value, unit, t) => `${speedFromKnots(value, unit).toFixed(2)} ${speedUnitString(unit, t)}`; export const formatVolume = (value, unit, t) => `${volumeFromLiters(value, unit).toFixed(2)} ${volumeUnitString(unit, t)}`; |