From 39c4fbace00eb74c921222b72b3cd61ca9d9615c Mon Sep 17 00:00:00 2001 From: johndoe Date: Mon, 5 Aug 2019 13:21:30 +0300 Subject: [PATCH] use constants --- src/L.Geodesic.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/L.Geodesic.js b/src/L.Geodesic.js index ed76d42..08730c9 100644 --- a/src/L.Geodesic.js +++ b/src/L.Geodesic.js @@ -1,4 +1,9 @@ (function () { + // constants + var d2r = Math.PI/180.0; + var r2d = 180.0/Math.PI; + var earthR = 6367000.0; // earth radius in meters (doesn't have to be exact) + function geodesicPoly(Klass, fill) { return Klass.extend({ initialize: function (latlngs, options) { @@ -28,9 +33,6 @@ // to calculate intermediate points. hopefully this will avoid the rounding issues seen in the full intermediate // points code that have been seen function geodesicConvertLine(startLatLng, endLatLng, convertedPoints) { - var R = 6367000.0; // earth radius in meters (doesn't have to be exact) - var d2r = Math.PI/180.0; - var r2d = 180.0/Math.PI; // maths based on https://edwilliams.org/avform.htm#Int @@ -41,7 +43,7 @@ var dLng = lng2-lng1; - var segments = Math.floor(Math.abs(dLng * R / 5000)); + var segments = Math.floor(Math.abs(dLng * earthR / 5000)); if (segments > 1) { // pre-calculate some constant values for the loop @@ -152,13 +154,10 @@ }, _calcPoints: function() { - var R = 6367000.0; //earth radius in meters - var d2r = Math.PI/180.0; - var r2d = 180.0/Math.PI; //console.log("geodesicCircle: radius = "+this._radius+"m, centre "+this._latlng.lat+","+this._latlng.lng); // circle radius as an angle from the centre of the earth - var radRadius = this._radius / R; + var radRadius = this._radius / earthR; //console.log(" (radius in radians "+radRadius);