aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modern/src/common/components/PositionValue.js5
-rw-r--r--modern/src/common/util/converter.js24
-rw-r--r--modern/src/common/util/formatter.js11
-rw-r--r--modern/src/reports/ChartReportPage.js8
-rw-r--r--modern/src/settings/ServerPage.js11
-rw-r--r--modern/src/settings/UserPage.js11
-rw-r--r--web/l10n/en.json3
7 files changed, 70 insertions, 3 deletions
diff --git a/modern/src/common/components/PositionValue.js b/modern/src/common/components/PositionValue.js
index 83fc0ef2..f80bc684 100644
--- a/modern/src/common/components/PositionValue.js
+++ b/modern/src/common/components/PositionValue.js
@@ -2,7 +2,7 @@ import React from 'react';
import { Link } from '@mui/material';
import { Link as RouterLink } from 'react-router-dom';
import {
- formatAlarm, formatBoolean, formatCoordinate, formatCourse, formatDistance, formatNumber, formatPercentage, formatSpeed, formatTime,
+ formatAlarm, formatAltitude, formatBoolean, formatCoordinate, formatCourse, formatDistance, formatNumber, formatPercentage, formatSpeed, formatTime,
} from '../util/formatter';
import { useAttributePreference, usePreference } from '../util/preferences';
import { useTranslation } from './LocalizationProvider';
@@ -18,6 +18,7 @@ const PositionValue = ({ position, property, attribute }) => {
const value = property ? position[property] : position.attributes[attribute];
const distanceUnit = useAttributePreference('distanceUnit');
+ const altitudeUnit = useAttributePreference('altitudeUnit');
const speedUnit = useAttributePreference('speedUnit');
const coordinateFormat = usePreference('coordinateFormat');
@@ -35,6 +36,8 @@ const PositionValue = ({ position, property, attribute }) => {
return formatSpeed(value, speedUnit, t);
case 'course':
return formatCourse(value);
+ case 'altitude':
+ return formatAltitude(value, altitudeUnit, t);
case 'batteryLevel':
return formatPercentage(value);
case 'alarm':
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)}`;
diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js
index 977c5158..00edf7b6 100644
--- a/modern/src/reports/ChartReportPage.js
+++ b/modern/src/reports/ChartReportPage.js
@@ -13,7 +13,9 @@ import ReportsMenu from './components/ReportsMenu';
import usePositionAttributes from '../common/attributes/usePositionAttributes';
import { useCatch } from '../reactHelper';
import { useAttributePreference } from '../common/util/preferences';
-import { distanceFromMeters, speedFromKnots, volumeFromLiters } from '../common/util/converter';
+import {
+ altitudeFromMeters, distanceFromMeters, speedFromKnots, volumeFromLiters,
+} from '../common/util/converter';
import useReportStyles from './common/useReportStyles';
const ChartReportPage = () => {
@@ -23,6 +25,7 @@ const ChartReportPage = () => {
const positionAttributes = usePositionAttributes(t);
const distanceUnit = useAttributePreference('distanceUnit');
+ const altitudeUnit = useAttributePreference('altitudeUnit');
const speedUnit = useAttributePreference('speedUnit');
const volumeUnit = useAttributePreference('volumeUnit');
@@ -51,6 +54,9 @@ const ChartReportPage = () => {
case 'speed':
formatted[key] = speedFromKnots(value, speedUnit).toFixed(2);
break;
+ case 'altitude':
+ formatted[key] = altitudeFromMeters(value, altitudeUnit).toFixed(2);
+ break;
case 'distance':
formatted[key] = distanceFromMeters(value, distanceUnit).toFixed(2);
break;
diff --git a/modern/src/settings/ServerPage.js b/modern/src/settings/ServerPage.js
index 90b854db..ee2d5f31 100644
--- a/modern/src/settings/ServerPage.js
+++ b/modern/src/settings/ServerPage.js
@@ -157,6 +157,17 @@ const ServerPage = () => {
</Select>
</FormControl>
<FormControl>
+ <InputLabel>{t('settingsAltitudeUnit')}</InputLabel>
+ <Select
+ label={t('settingsAltitudeUnit')}
+ value={item.attributes.altitudeUnit || 'm'}
+ onChange={(e) => setItem({ ...item, attributes: { ...item.attributes, altitudeUnit: e.target.value } })}
+ >
+ <MenuItem value="m">{t('sharedMeters')}</MenuItem>
+ <MenuItem value="ft">{t('sharedFeet')}</MenuItem>
+ </Select>
+ </FormControl>
+ <FormControl>
<InputLabel>{t('settingsVolumeUnit')}</InputLabel>
<Select
label={t('settingsVolumeUnit')}
diff --git a/modern/src/settings/UserPage.js b/modern/src/settings/UserPage.js
index 6e637d49..012d5c66 100644
--- a/modern/src/settings/UserPage.js
+++ b/modern/src/settings/UserPage.js
@@ -187,6 +187,17 @@ const UserPage = () => {
</Select>
</FormControl>
<FormControl>
+ <InputLabel>{t('settingsAltitudeUnit')}</InputLabel>
+ <Select
+ label={t('settingsAltitudeUnit')}
+ value={item.attributes.altitudeUnit || 'm'}
+ onChange={(e) => setItem({ ...item, attributes: { ...item.attributes, altitudeUnit: e.target.value } })}
+ >
+ <MenuItem value="m">{t('sharedMeters')}</MenuItem>
+ <MenuItem value="ft">{t('sharedFeet')}</MenuItem>
+ </Select>
+ </FormControl>
+ <FormControl>
<InputLabel>{t('settingsVolumeUnit')}</InputLabel>
<Select
label={t('settingsVolumeUnit')}
diff --git a/web/l10n/en.json b/web/l10n/en.json
index 8a264fbd..616f6724 100644
--- a/web/l10n/en.json
+++ b/web/l10n/en.json
@@ -14,6 +14,8 @@
"sharedKm": "km",
"sharedMi": "mi",
"sharedNmi": "nmi",
+ "sharedMeters": "m",
+ "sharedFeet": "ft",
"sharedKn": "kn",
"sharedKmh": "km/h",
"sharedMph": "mph",
@@ -175,6 +177,7 @@
"settingsServer": "Server",
"settingsUsers": "Users",
"settingsDistanceUnit": "Distance Unit",
+ "settingsAltitudeUnit": "Altitude Unit",
"settingsSpeedUnit": "Speed Unit",
"settingsVolumeUnit": "Volume Unit",
"settingsTwelveHourFormat": "12-hour Format",