aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
authorgeduxas <gediminas.vileikis@gmail.com>2023-09-20 09:31:36 +0000
committergeduxas <gediminas.vileikis@gmail.com>2023-09-20 09:31:36 +0000
commit3e2c5833ac8dbabb02569544359a61baaa489a76 (patch)
treee89bc803363f235fb707d29a3e1de5da2c03f55c /modern/src
parent925c51d94f25021cb4fbf77cee7b0cb7f611692b (diff)
downloadtrackermap-web-3e2c5833ac8dbabb02569544359a61baaa489a76.tar.gz
trackermap-web-3e2c5833ac8dbabb02569544359a61baaa489a76.tar.bz2
trackermap-web-3e2c5833ac8dbabb02569544359a61baaa489a76.zip
OBDSpeed expected as km/h not knots.
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/common/components/PositionValue.jsx4
-rw-r--r--modern/src/common/util/converter.js14
-rw-r--r--modern/src/common/util/formatter.js3
3 files changed, 20 insertions, 1 deletions
diff --git a/modern/src/common/components/PositionValue.jsx b/modern/src/common/components/PositionValue.jsx
index 58841939..60476177 100644
--- a/modern/src/common/components/PositionValue.jsx
+++ b/modern/src/common/components/PositionValue.jsx
@@ -13,6 +13,7 @@ import {
formatNumericHours,
formatPercentage,
formatSpeed,
+ formatSpeedKph,
formatTime,
formatTemperature,
formatVoltage,
@@ -53,8 +54,9 @@ const PositionValue = ({ position, property, attribute }) => {
case 'longitude':
return formatCoordinate('longitude', value, coordinateFormat);
case 'speed':
- case 'obdSpeed':
return value != null ? formatSpeed(value, speedUnit, t) : '';
+ case 'obdSpeed':
+ return value != null ? formatSpeedKph(value, speedUnit, t) : '';
case 'course':
return formatCourse(value);
case 'altitude':
diff --git a/modern/src/common/util/converter.js b/modern/src/common/util/converter.js
index cb21566b..6890763b 100644
--- a/modern/src/common/util/converter.js
+++ b/modern/src/common/util/converter.js
@@ -10,6 +10,18 @@ const speedConverter = (unit) => {
}
};
+const speedConverterKph = (unit) => {
+ switch (unit) {
+ case 'kmh':
+ return 1;
+ case 'mph':
+ return 0.62137;
+ case 'kn':
+ default:
+ return 0.539957;
+ }
+};
+
export const speedUnitString = (unit, t) => {
switch (unit) {
case 'kmh':
@@ -24,6 +36,8 @@ export const speedUnitString = (unit, t) => {
export const speedFromKnots = (value, unit) => value * speedConverter(unit);
+export const speedFromKph = (value, unit) => value * speedConverterKph(unit);
+
export const speedToKnots = (value, unit) => value / speedConverter(unit);
const distanceConverter = (unit) => {
diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js
index aeacc145..79f51fce 100644
--- a/modern/src/common/util/formatter.js
+++ b/modern/src/common/util/formatter.js
@@ -8,6 +8,7 @@ import {
distanceFromMeters,
distanceUnitString,
speedFromKnots,
+ speedFromKph,
speedUnitString,
volumeFromLiters,
volumeUnitString,
@@ -64,6 +65,8 @@ export const formatAltitude = (value, unit, t) => `${altitudeFromMeters(value, u
export const formatSpeed = (value, unit, t) => `${speedFromKnots(value, unit).toFixed(2)} ${speedUnitString(unit, t)}`;
+export const formatSpeedKph = (value, unit, t) => `${speedFromKph(value, unit).toFixed(2)} ${speedUnitString(unit, t)}`;
+
export const formatVolume = (value, unit, t) => `${volumeFromLiters(value, unit).toFixed(2)} ${volumeUnitString(unit, t)}`;
export const formatHours = (value) => dayjs.duration(value).humanize();