UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

21 lines (16 loc) 555 B
/* * L.CRS.Earth is the base class for all CRS representing Earth. */ L.CRS.Earth = L.extend({}, L.CRS, { wrapLng: [-180, 180], R: 6378137, // distance between two geographical points using spherical law of cosines approximation distance: function (latlng1, latlng2) { var rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad); return this.R * Math.acos(Math.min(a, 1)); } });