UNPKG

isochrone-explorer

Version:

A powerful isochrone and routing engine based on Dijkstra's algorithm for accurate travel time calculations.

21 lines (16 loc) 681 B
function calculateDistance(coord1, coord2) { const R = 6371e3; const φ1 = coord1.lat * Math.PI / 180; const φ2 = coord2.lat * Math.PI / 180; const Δφ = (coord2.lat - coord1.lat) * Math.PI / 180; const Δλ = (coord2.lon - coord1.lon) * Math.PI / 180; const a = Math.sin(Δφ / 2) ** 2 + Math.cos1) * Math.cos2) * Math.sin(Δλ / 2) ** 2; const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return R * c; } function reducePointsToPolygon(points) { return points.map(([lat, lon]) => [lon, lat]); } module.exports = { calculateDistance, reducePointsToPolygon };