[leaflet] use the earth 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
This commit is contained in:
McBen
2016-12-31 07:47:05 +01:00
parent 611aeb1759
commit 2bdc063ab7

View File

@ -1160,7 +1160,7 @@ L.LatLng.prototype = {
distanceTo: function (other) { // (LatLng) -> Number distanceTo: function (other) { // (LatLng) -> Number
other = L.latLng(other); 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, d2r = L.LatLng.DEG_TO_RAD,
dLat = (other.lat - this.lat) * d2r, dLat = (other.lat - this.lat) * d2r,
dLon = (other.lng - this.lng) * d2r, dLon = (other.lng - this.lng) * d2r,
@ -1481,7 +1481,7 @@ L.CRS.EPSG3857 = L.extend({}, L.CRS, {
project: function (latlng) { // (LatLng) -> Point project: function (latlng) { // (LatLng) -> Point
var projectedPoint = this.projection.project(latlng), var projectedPoint = this.projection.project(latlng),
earthRadius = 6378137; earthRadius = 6367000.0;
return projectedPoint.multiplyBy(earthRadius); return projectedPoint.multiplyBy(earthRadius);
} }
}); });
@ -8277,7 +8277,7 @@ L.Control.Scale = L.Control.extend({
_update: function () { _update: function () {
var bounds = this._map.getBounds(), var bounds = this._map.getBounds(),
centerLat = bounds.getCenter().lat, 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, dist = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180,
size = this._map.getSize(), size = this._map.getSize(),