From 35a6c47ae46932751e4c5f34459202543c382eba Mon Sep 17 00:00:00 2001 From: daf111 Date: Mon, 14 Jan 2019 15:24:41 -0300 Subject: [PATCH 1/2] Labels in DMS Added the possibility to select an alternative format for the labels in degrees, minutes and seconds (DMS). For this, a new option called "labelsFormat" was created. The possible values are "decimal" (labels in decimal of degree, as up to now) or "dms" (labels in degrees, minutes and seconds). --- L.SimpleGraticule.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/L.SimpleGraticule.js b/L.SimpleGraticule.js index 4b7ef96..fc7b134 100644 --- a/L.SimpleGraticule.js +++ b/L.SimpleGraticule.js @@ -9,6 +9,7 @@ L.SimpleGraticule = L.LayerGroup.extend({ showOriginLabel: true, redraw: 'move', hidden: false, + labelsFormat: 'dms', //Posibles options: decimal or dms zoomIntervals : [] }, @@ -138,6 +139,10 @@ L.SimpleGraticule = L.LayerGroup.extend({ } else { latLng = new L.LatLng(val, bounds.getWest()); } + + if (this.options.labelsFormat == 'dms') { + val = this.degToDms(val); + } return L.marker(latLng, { interactive: false, @@ -149,6 +154,36 @@ L.SimpleGraticule = L.LayerGroup.extend({ }) }); }, + + degToDms: function (deg) { + var vecAux = new Array(); + var d = Math.floor (deg); + var minfloat = (deg-d)*60; + var m = Math.floor(minfloat); + var secfloat = (minfloat-m)*60; + var s = Math.round(secfloat); + // After rounding, the seconds might become 60. These two + // if-tests are not necessary if no rounding is done. + if (s==60) { + m++; + s=0; + } + if (m==60) { + d++; + m=0; + } + + vecAux[0] = d + "°"; + vecAux[1] = m + "'"; + if (m < 10) { + vecAux[1] = "0" + m + "'"; + } + vecAux[2] = s + "''"; + if (s < 10) { + vecAux[2] = "0" + s + "''"; + } + return vecAux.join(''); + }, addOriginLabel: function() { return L.marker([0, 0], { From 6665c5d6994384e6154fa5a36f913061ef1e8e6e Mon Sep 17 00:00:00 2001 From: daf111 Date: Thu, 28 Feb 2019 11:48:20 -0300 Subject: [PATCH 2/2] degToDms function The function was corrected because it failed when trying to format negative coordinates. --- L.SimpleGraticule.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/L.SimpleGraticule.js b/L.SimpleGraticule.js index fc7b134..cfb955f 100644 --- a/L.SimpleGraticule.js +++ b/L.SimpleGraticule.js @@ -156,6 +156,8 @@ L.SimpleGraticule = L.LayerGroup.extend({ }, degToDms: function (deg) { + var multiplier = (deg < 0)?-1:1; + deg = Math.abs(deg); var vecAux = new Array(); var d = Math.floor (deg); var minfloat = (deg-d)*60;