starts transition to maplibre

This commit is contained in:
Christian Beutel
2024-11-26 00:19:41 +01:00
parent b9ae01846b
commit b6b409e855
21 changed files with 2143 additions and 34 deletions

View File

@@ -2,7 +2,7 @@ import * as xml2js from 'isomorphic-xml2js';
import Metadata from './metadata';
import Route from './route';
import Track from './track';
import { allDatesToISOString, calculateDistance, removeEmpty } from './utils';
import { allDatesToISOString, haversineDistance, removeEmpty } from './utils';
import Waypoint from './waypoint';
const defaultAttributes = {
@@ -104,7 +104,7 @@ export default class GPX {
totalElevationLoss += Math.abs(elevationDiff)
}
const distance = calculateDistance(
const distance = haversineDistance(
prevPoint.$.lat ?? 0,
prevPoint.$.lon ?? 0,
point.$.lat ?? 0,

View File

@@ -20,7 +20,7 @@ function allDatesToISOString(obj: Record<string, any>) {
});
}
function calculateDistance(lat1: number, lon1: number, lat2: number, lon2: number): number {
function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number): number {
const R = 6371; // Radius of the Earth in km
const dLat = (lat2 - lat1) * (Math.PI / 180); // Convert degrees to radians
const dLon = (lon2 - lon1) * (Math.PI / 180);
@@ -33,4 +33,4 @@ function calculateDistance(lat1: number, lon1: number, lat2: number, lon2: numbe
return distance;
}
export { removeEmpty, allDatesToISOString, calculateDistance };
export { removeEmpty, allDatesToISOString, haversineDistance };