aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-03-24 12:29:45 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-03-24 12:29:45 +0530
commit85fa5aed51ee16a7f5258ab29a991c9e4007fc04 (patch)
tree32e9b2633bfd1869689c6e7f96baadd7f85e4980 /modern/src/common
parent5b9f7db4f18d79570fa17bd61b82eec4452c2aa8 (diff)
downloadtrackermap-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.tar.gz
trackermap-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.tar.bz2
trackermap-web-85fa5aed51ee16a7f5258ab29a991c9e4007fc04.zip
Implementing coordinate formatting
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/formatter.js25
1 files changed, 25 insertions, 0 deletions
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) + '°';
+ }
+};