Merge pull request #6410 from rjackson64840/fix-toStringHDMS
fixed the degreesToStringHDMS_() function to promote a seconds value …
This commit is contained in:
@@ -112,9 +112,25 @@ ol.coordinate.degreesToStringHDMS_ = function(degrees, hemispheres, opt_fraction
|
|||||||
var normalizedDegrees = ol.math.modulo(degrees + 180, 360) - 180;
|
var normalizedDegrees = ol.math.modulo(degrees + 180, 360) - 180;
|
||||||
var x = Math.abs(3600 * normalizedDegrees);
|
var x = Math.abs(3600 * normalizedDegrees);
|
||||||
var dflPrecision = opt_fractionDigits || 0;
|
var dflPrecision = opt_fractionDigits || 0;
|
||||||
return Math.floor(x / 3600) + '\u00b0 ' +
|
var precision = Math.pow(10, dflPrecision);
|
||||||
ol.string.padNumber(Math.floor((x / 60) % 60), 2) + '\u2032 ' +
|
|
||||||
ol.string.padNumber((x % 60), 2, dflPrecision) + '\u2033 ' +
|
var deg = Math.floor(x / 3600);
|
||||||
|
var min = Math.floor((x - deg * 3600) / 60);
|
||||||
|
var sec = x - (deg * 3600) - (min * 60);
|
||||||
|
sec = Math.ceil(sec * precision) / precision;
|
||||||
|
|
||||||
|
if (sec >= 60) {
|
||||||
|
sec = 0;
|
||||||
|
min += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min >= 60) {
|
||||||
|
min = 0;
|
||||||
|
deg += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return deg + '\u00b0 ' + ol.string.padNumber(min, 2) + '\u2032 ' +
|
||||||
|
ol.string.padNumber(sec, 2, dflPrecision) + '\u2033 ' +
|
||||||
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
|
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -206,13 +206,13 @@ describe('ol.coordinate', function() {
|
|||||||
it('formats with zero fractional digits as default', function() {
|
it('formats with zero fractional digits as default', 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° 58′ 60″ N 7° 50′ 60″ E';
|
var expected = '47° 59′ 00″ N 7° 51′ 00″ E';
|
||||||
expect(got).to.be(expected);
|
expect(got).to.be(expected);
|
||||||
});
|
});
|
||||||
it('formats with given fractional digits, if passed', function() {
|
it('formats with given fractional digits, if passed', function() {
|
||||||
var coord = [7.85, 47.983333];
|
var coord = [7.85, 47.983333];
|
||||||
var got = ol.coordinate.toStringHDMS(coord, 3);
|
var got = ol.coordinate.toStringHDMS(coord, 3);
|
||||||
var expected = '47° 58′ 59.999″ N 7° 50′ 60.000″ E';
|
var expected = '47° 58′ 59.999″ N 7° 51′ 00.000″ E';
|
||||||
expect(got).to.be(expected);
|
expect(got).to.be(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user