From 1cdfc709aec2ab5d7fe9fe2460be0a4f0200aab4 Mon Sep 17 00:00:00 2001 From: Pierre GIRAUD Date: Thu, 25 Jun 2015 08:40:43 +0200 Subject: [PATCH] Pad min. and sec. with leading zeros in DMS notation FIxes 3776 --- src/ol/coordinate.js | 5 +++-- test/spec/ol/coordinate.test.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ol/coordinate.js b/src/ol/coordinate.js index 41f3f8b546..3a9b2a5c45 100644 --- a/src/ol/coordinate.js +++ b/src/ol/coordinate.js @@ -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); }; diff --git a/test/spec/ol/coordinate.test.js b/test/spec/ol/coordinate.test.js index 5914fe15c0..dd0176b55a 100644 --- a/test/spec/ol/coordinate.test.js +++ b/test/spec/ol/coordinate.test.js @@ -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); }); });