mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
refactor elevation queries
This commit is contained in:
@@ -6,7 +6,7 @@ import { currentPopupWaypoint, deleteWaypoint, waypointPopup } from "./WaypointP
|
||||
import { addSelectItem, selectItem, selection } from "$lib/components/file-list/Selection";
|
||||
import { ListTrackSegmentItem, ListWaypointItem, ListWaypointsItem, ListTrackItem, ListFileItem, ListRootItem } from "$lib/components/file-list/FileList";
|
||||
import type { Waypoint } from "gpx";
|
||||
import { resetCursor, setCursor, setGrabbingCursor, setPointerCursor } from "$lib/utils";
|
||||
import { getElevation, resetCursor, setCursor, setGrabbingCursor, setPointerCursor } from "$lib/utils";
|
||||
import { font } from "$lib/assets/layers";
|
||||
import { selectedWaypoint } from "$lib/components/toolbar/tools/Waypoint.svelte";
|
||||
import { MapPin } from "lucide-static";
|
||||
@@ -250,7 +250,7 @@ export class GPXLayer {
|
||||
lat: latLng.lat,
|
||||
lon: latLng.lng
|
||||
});
|
||||
wpt.ele = this.map.queryTerrainElevation([latLng.lng, latLng.lat], { exaggerated: false }) ?? 0;
|
||||
wpt.ele = getElevation(this.map, wpt.getCoordinates());
|
||||
});
|
||||
dragEndTimestamp = Date.now()
|
||||
});
|
||||
|
@@ -4,6 +4,7 @@ import { derived, get, writable } from "svelte/store";
|
||||
import { settings } from "$lib/db";
|
||||
import { _, isLoading, locale } from "svelte-i18n";
|
||||
import { map } from "$lib/stores";
|
||||
import { getElevation } from "$lib/utils";
|
||||
|
||||
const { routing, routingProfile, privateRoads } = settings;
|
||||
|
||||
@@ -123,9 +124,12 @@ function getIntermediatePoints(points: Coordinates[]): Promise<TrackPoint[]> {
|
||||
}
|
||||
}));
|
||||
|
||||
let m = get(map);
|
||||
route.forEach((point) => {
|
||||
point.setSurface("unknown");
|
||||
point.ele = get(map)?.queryTerrainElevation(point.getCoordinates(), { exaggerated: false }) ?? undefined;
|
||||
if (m) {
|
||||
point.ele = getElevation(m, point.getCoordinates());
|
||||
}
|
||||
});
|
||||
|
||||
return new Promise((resolve) => resolve(route));
|
||||
|
@@ -8,6 +8,8 @@ import { applyToOrderedItemsFromFile, applyToOrderedSelectedItemsFromFile, selec
|
||||
import { ListFileItem, ListItem, ListTrackItem, ListLevel, ListTrackSegmentItem, ListWaypointItem, ListRootItem } from '$lib/components/file-list/FileList';
|
||||
import { updateAnchorPoints } from '$lib/components/toolbar/tools/routing/Simplify';
|
||||
import { SplitType } from '$lib/components/toolbar/tools/Scissors.svelte';
|
||||
import { getElevation } from '$lib/utils';
|
||||
|
||||
|
||||
enableMapSet();
|
||||
enablePatches();
|
||||
@@ -894,7 +896,11 @@ export const dbUtils = {
|
||||
});
|
||||
},
|
||||
addOrUpdateWaypoint: (waypoint: WaypointType, item?: ListWaypointItem) => {
|
||||
let ele = get(map)?.queryTerrainElevation([waypoint.attributes.lon, waypoint.attributes.lat], { exaggerated: false }) ?? 0;
|
||||
let m = get(map);
|
||||
if (m === null) {
|
||||
return;
|
||||
}
|
||||
let ele = getElevation(m, waypoint.attributes);
|
||||
if (item) {
|
||||
dbUtils.applyToFile(item.getFileId(), (file) => {
|
||||
let wpt = file.wpt[item.getWaypointIndex()];
|
||||
|
@@ -8,6 +8,8 @@ import { base } from "$app/paths";
|
||||
import { browser } from "$app/environment";
|
||||
import { languages } from "$lib/languages";
|
||||
import { locale } from "svelte-i18n";
|
||||
import type Coordinates from "gpx";
|
||||
import type mapboxgl from "mapbox-gl";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
@@ -67,6 +69,11 @@ export const flyAndScale = (
|
||||
};
|
||||
};
|
||||
|
||||
export function getElevation(map: mapboxgl.Map, coordinates: Coordinates): number {
|
||||
let elevation = map.queryTerrainElevation(coordinates, { exaggerated: false });
|
||||
return elevation === null ? 0 : elevation;
|
||||
}
|
||||
|
||||
let previousCursors: string[] = [];
|
||||
export function setCursor(cursor: string) {
|
||||
let m = get(map);
|
||||
|
Reference in New Issue
Block a user