diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-03-24 12:29:45 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-03-24 12:29:45 +0530 |
commit | 85fa5aed51ee16a7f5258ab29a991c9e4007fc04 (patch) | |
tree | 32e9b2633bfd1869689c6e7f96baadd7f85e4980 /modern/src | |
parent | 5b9f7db4f18d79570fa17bd61b82eec4452c2aa8 (diff) | |
download | etbsa-traccar-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.tar.gz etbsa-traccar-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.tar.bz2 etbsa-traccar-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.zip |
Implementing coordinate formatting
Diffstat (limited to 'modern/src')
-rw-r--r-- | modern/src/common/formatter.js | 25 | ||||
-rw-r--r-- | modern/src/reports/RouteReportPage.js | 9 |
2 files changed, 30 insertions, 4 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 289a6d9..b70fed3 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -81,3 +81,28 @@ export const formatVolume = (value, unit) => { export const formatHours = (value) => { return moment.duration(value).humanize(); }; + +export const coordinateFormatter = (key, value, unit) => { + var hemisphere, degrees, minutes, seconds; + if (key === 'latitude') { + hemisphere = value >= 0 ? 'N' : 'S'; + } else { + hemisphere = value >= 0 ? 'E' : 'W'; + } + + switch (unit) { + case 'ddm': + value = Math.abs(value); + degrees = Math.floor(value); + minutes = (value - degrees) * 60; + return degrees + '° ' + minutes.toFixed(6) + '\' ' + hemisphere; + case 'dms': + value = Math.abs(value); + degrees = Math.floor(value); + minutes = Math.floor((value - degrees) * 60); + seconds = Math.round((value - degrees - minutes / 60) * 3600); + return degrees + '° ' + minutes + '\' ' + seconds + '" ' + hemisphere; + default: + return value.toFixed(6) + '°'; + } +}; diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index 33ccb34..bbe37e2 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -1,10 +1,10 @@ import React, { useState } from 'react'; import { DataGrid } from '@material-ui/data-grid'; import t from '../common/localization'; -import { formatPosition, formatDistance, formatSpeed, formatBoolean, formatDate, formatNumber } from '../common/formatter'; +import { formatDistance, formatSpeed, formatBoolean, formatDate, formatNumber, coordinateFormatter } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; -import { useAttributePreference } from '../common/preferences'; +import { useAttributePreference, usePreference } from '../common/preferences'; const Filter = ({ setItems }) => { @@ -29,6 +29,7 @@ const Filter = ({ setItems }) => { const RouteReportPage = () => { const distanceUnit = useAttributePreference('distanceUnit'); const speedUnit = useAttributePreference('speedUnit'); + const coordinateFormat = usePreference('coordinateFormat'); const columns = [{ headerName: t('positionFixTime'), @@ -41,13 +42,13 @@ const RouteReportPage = () => { field: 'latitude', type: 'number', flex: 1, - valueFormatter: ({ value }) => formatNumber(value, 5), + valueFormatter: ({ value }) => coordinateFormatter('latitude', value, coordinateFormat), }, { headerName: t('positionLongitude'), field: 'longitude', type: 'number', flex: 1, - valueFormatter: ({ value }) => formatNumber(value, 5), + valueFormatter: ({ value }) => coordinateFormatter('longitude', value, coordinateFormat), }, { headerName: t('positionSpeed'), field: 'speed', |