From 18ba0d53471ad826b1ed7f373420173c40e3846a Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 31 Mar 2012 18:28:48 +0200 Subject: [PATCH] add Ox.formatDegrees --- source/Ox/js/Format.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index a08cd9df..50e3c58b 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -371,6 +371,29 @@ Ox.formatDateRangeDuration = function(start, end, utc) { }).join(' '); }; +/*@ +Ox.formatDegrees Formats degrees as D°MM'SS" + > Ox.formatDegrees(-111.11, 'lng') + "111\u00B006'36\"W" +@*/ +Ox.formatDegrees = function(deg, mode) { + var days = 0, + sec = Math.round(Math.abs(deg) * 3600), + sign = deg < 0 ? '-' : '', + split = Ox.formatDuration(sec).split(':'); + if (split.length == 4) { + days = parseInt(split.shift(), 10); + } + split[0] = days * 24 + parseInt(split[0], 10); + return (!mode ? sign : '') + + split[0] + '\u00B0' + split[1] + "'" + split[2] + '"' + + ( + mode == 'lat' ? (deg < 0 ? 'S' : 'N') + : mode == 'lng' ? (deg < 0 ? 'W' : 'E') + : '' + ); +}; + /*@ Ox.formatDuration Formats a duration as a string > Ox.formatDuration(3599.999)