Merge pull request #3849 from pgiraud/dms_notation_leading_zeros

Pad min. and sec. with leading zeros in DMS notation
This commit is contained in:
Pierre GIRAUD
2015-06-25 09:23:37 +02:00
2 changed files with 4 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ goog.provide('ol.CoordinateFormatType');
goog.provide('ol.coordinate');
goog.require('goog.math');
goog.require('goog.string');
/**
@@ -129,8 +130,8 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres) {
var normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180;
var x = Math.abs(Math.round(3600 * normalizedDegrees));
return Math.floor(x / 3600) + '\u00b0 ' +
Math.floor((x / 60) % 60) + '\u2032 ' +
Math.floor(x % 60) + '\u2033 ' +
goog.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' +
goog.string.padNumber(Math.floor(x % 60), 2) + '\u2033 ' +
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
};

View File

@@ -206,7 +206,7 @@ describe('ol.coordinate', function() {
it('formats a coord as expected', function() {
var coord = [7.85, 47.983333];
var got = ol.coordinate.toStringHDMS(coord);
var expected = '47° 59 0″ N 7° 51 0″ E';
var expected = '47° 59 00″ N 7° 51 00″ E';
expect(got).to.be(expected);
});
});