Pad min. and sec. with leading zeros in DMS notation
FIxes 3776
This commit is contained in:
@@ -3,6 +3,7 @@ goog.provide('ol.CoordinateFormatType');
|
|||||||
goog.provide('ol.coordinate');
|
goog.provide('ol.coordinate');
|
||||||
|
|
||||||
goog.require('goog.math');
|
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 normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180;
|
||||||
var x = Math.abs(Math.round(3600 * normalizedDegrees));
|
var x = Math.abs(Math.round(3600 * normalizedDegrees));
|
||||||
return Math.floor(x / 3600) + '\u00b0 ' +
|
return Math.floor(x / 3600) + '\u00b0 ' +
|
||||||
Math.floor((x / 60) % 60) + '\u2032 ' +
|
goog.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' +
|
||||||
Math.floor(x % 60) + '\u2033 ' +
|
goog.string.padNumber(Math.floor(x % 60), 2) + '\u2033 ' +
|
||||||
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
|
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ describe('ol.coordinate', function() {
|
|||||||
it('formats a coord as expected', function() {
|
it('formats a coord as expected', function() {
|
||||||
var coord = [7.85, 47.983333];
|
var coord = [7.85, 47.983333];
|
||||||
var got = ol.coordinate.toStringHDMS(coord);
|
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);
|
expect(got).to.be(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user