From 85fa5aed51ee16a7f5258ab29a991c9e4007fc04 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Wed, 24 Mar 2021 12:29:45 +0530 Subject: Implementing coordinate formatting --- modern/src/common/formatter.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'modern/src/common/formatter.js') diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 289a6d94..b70fed3a 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) + '°'; + } +}; -- cgit v1.2.3 From cfa8947f3a4adda1ed649210da4adfe21f44af21 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 25 Mar 2021 10:37:56 +0530 Subject: renaming coordinateFormatter function --- modern/src/common/formatter.js | 2 +- modern/src/reports/RouteReportPage.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modern/src/common/formatter.js') diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index b70fed3a..0d8ac4c9 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -82,7 +82,7 @@ export const formatHours = (value) => { return moment.duration(value).humanize(); }; -export const coordinateFormatter = (key, value, unit) => { +export const formatCoordinate = (key, value, unit) => { var hemisphere, degrees, minutes, seconds; if (key === 'latitude') { hemisphere = value >= 0 ? 'N' : 'S'; diff --git a/modern/src/reports/RouteReportPage.js b/modern/src/reports/RouteReportPage.js index bbe37e2f..b8bad00d 100644 --- a/modern/src/reports/RouteReportPage.js +++ b/modern/src/reports/RouteReportPage.js @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { DataGrid } from '@material-ui/data-grid'; import t from '../common/localization'; -import { formatDistance, formatSpeed, formatBoolean, formatDate, formatNumber, coordinateFormatter } from '../common/formatter'; +import { formatDistance, formatSpeed, formatBoolean, formatDate, formatCoordinate } from '../common/formatter'; import ReportFilter from './ReportFilter'; import ReportLayoutPage from './ReportLayoutPage'; import { useAttributePreference, usePreference } from '../common/preferences'; @@ -42,13 +42,13 @@ const RouteReportPage = () => { field: 'latitude', type: 'number', flex: 1, - valueFormatter: ({ value }) => coordinateFormatter('latitude', value, coordinateFormat), + valueFormatter: ({ value }) => formatCoordinate('latitude', value, coordinateFormat), }, { headerName: t('positionLongitude'), field: 'longitude', type: 'number', flex: 1, - valueFormatter: ({ value }) => coordinateFormatter('longitude', value, coordinateFormat), + valueFormatter: ({ value }) => formatCoordinate('longitude', value, coordinateFormat), }, { headerName: t('positionSpeed'), field: 'speed', -- cgit v1.2.3