add Ox.formatDegrees

This commit is contained in:
rolux 2012-03-31 18:28:48 +02:00
parent 1d86f10e79
commit 18ba0d5347

View file

@ -371,6 +371,29 @@ Ox.formatDateRangeDuration = function(start, end, utc) {
}).join(' ');
};
/*@
Ox.formatDegrees <f> 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 <f> Formats a duration as a string
> Ox.formatDuration(3599.999)