mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-05 01:42:54 +00:00
extract redundant code in helper function
This commit is contained in:
@@ -9,6 +9,7 @@ import { browser } from "$app/environment";
|
||||
import { languages } from "$lib/languages";
|
||||
import { locale } from "svelte-i18n";
|
||||
import type mapboxgl from "mapbox-gl";
|
||||
import { type TrackPoint, type Coordinates, crossarcDistance } from "gpx";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
@@ -68,6 +69,20 @@ export const flyAndScale = (
|
||||
};
|
||||
};
|
||||
|
||||
export function getClosestLinePoint(points: TrackPoint[], point: TrackPoint | Coordinates, details: any = {}): TrackPoint {
|
||||
let closest = points[0];
|
||||
let closestDist = Number.MAX_VALUE;
|
||||
for (let i = 0; i < points.length - 1; i++) {
|
||||
let dist = crossarcDistance(points[i], points[i + 1], point);
|
||||
if (dist < closestDist) {
|
||||
closest = points[i];
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
details['distance'] = closestDist;
|
||||
return closest;
|
||||
}
|
||||
|
||||
export function getElevation(map: mapboxgl.Map, coordinates: Coordinates): number {
|
||||
let elevation = map.queryTerrainElevation(coordinates, { exaggerated: false });
|
||||
return elevation === null ? 0 : elevation;
|
||||
|
Reference in New Issue
Block a user