From 522ef34f77c86c54cc7586a298d5a6f74f75aef4 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Thu, 12 Mar 2015 20:47:05 +0000 Subject: [PATCH] earth radius: change leaflet and leaflet-draw to use the radius value used by the s2 geometry library this library is used in the ingress backend, so distance calculation, etc are far closer if we use the value from that --- external/L.Geodesic.js | 4 ++-- external/leaflet-src.js | 6 +++--- external/leaflet.draw.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/external/L.Geodesic.js b/external/L.Geodesic.js index 0eecd65f1..9b6dbb69c 100644 --- a/external/L.Geodesic.js +++ b/external/L.Geodesic.js @@ -40,7 +40,7 @@ Modified by qnstie 2013-07-17 to maintain compatibility with Leaflet.draw // to calculate intermediate points. hopeefully this will avoid the rounding issues seen in the full intermediate // points code that have been seen function geodesicConvertLine(startLatLng, endLatLng, convertedPoints) { - var R = 6378137; // earth radius in meters (doesn't have to be exact) + 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; @@ -179,7 +179,7 @@ Modified by qnstie 2013-07-17 to maintain compatibility with Leaflet.draw _calcPoints: function() { - var R = 6378137; //earth radius in meters (approx - taken from leaflet source code) + var R = 6367000.0; //earth radius in meters (approx - taken from leaflet source code) var d2r = Math.PI/180.0; var r2d = 180.0/Math.PI; //console.log("geodesicCircle: radius = "+this._mRadius+"m, centre "+this._latlng.lat+","+this._latlng.lng); diff --git a/external/leaflet-src.js b/external/leaflet-src.js index 93b84b6b8..5c080aa55 100644 --- a/external/leaflet-src.js +++ b/external/leaflet-src.js @@ -1191,7 +1191,7 @@ L.LatLng.prototype = { distanceTo: function (other) { // (LatLng) -> Number other = L.latLng(other); - var R = 6378137, // earth radius in meters + var R = 6367000.0, // earth radius in meters d2r = L.LatLng.DEG_TO_RAD, dLat = (other.lat - this.lat) * d2r, dLon = (other.lng - this.lng) * d2r, @@ -1512,7 +1512,7 @@ L.CRS.EPSG3857 = L.extend({}, L.CRS, { project: function (latlng) { // (LatLng) -> Point var projectedPoint = this.projection.project(latlng), - earthRadius = 6378137; + earthRadius = 6367000.0; return projectedPoint.multiplyBy(earthRadius); } }); @@ -8299,7 +8299,7 @@ L.Control.Scale = L.Control.extend({ _update: function () { var bounds = this._map.getBounds(), centerLat = bounds.getCenter().lat, - halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180), + halfWorldMeters = 6367000.0 * Math.PI * Math.cos(centerLat * Math.PI / 180), dist = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180, size = this._map.getSize(), diff --git a/external/leaflet.draw.js b/external/leaflet.draw.js index cf479e6b9..7dc85e6d4 100644 --- a/external/leaflet.draw.js +++ b/external/leaflet.draw.js @@ -1602,7 +1602,7 @@ L.GeometryUtil = { area += ((p2.lng - p1.lng) * d2r) * (2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r)); } - area = area * 6378137.0 * 6378137.0 / 2.0; + area = area * 6367000.0 * 6367000.0 / 2.0; } return Math.abs(area);