reverses waypoint relation
This commit is contained in:
@@ -15,7 +15,7 @@ export async function GET(event: RequestEvent) {
|
||||
t.expand = {} as any
|
||||
}
|
||||
|
||||
t.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||
t.expand?.waypoints_via_trail?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||
}
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -84,7 +84,7 @@ export async function GET(event: RequestEvent) {
|
||||
l.expand.author.isLocal = false
|
||||
}
|
||||
})
|
||||
t.expand?.waypoints?.forEach(w => {
|
||||
t.expand?.waypoints_via_trail?.forEach(w => {
|
||||
|
||||
w.photos = w.photos.map(p =>
|
||||
`${origin}/api/v1/files/waypoints/${w.id}/${p}`
|
||||
@@ -131,7 +131,7 @@ export async function GET(event: RequestEvent) {
|
||||
await enrichRecord(event.locals.pb, t);
|
||||
|
||||
// sort waypoints by distance
|
||||
t.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||
t.expand?.waypoints_via_trail?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||
return json(t)
|
||||
} catch (e: any) {
|
||||
return handleError(e)
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
let selectedTrailIndex = $derived(selectedTrail ? 0 : null);
|
||||
|
||||
let selectedTrailWaypoints = $derived(
|
||||
(selectedTrail as Trail | null)?.expand?.waypoints,
|
||||
(selectedTrail as Trail | null)?.expand?.waypoints_via_trail,
|
||||
);
|
||||
|
||||
onMount(() => {
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<div id="trail-details">
|
||||
<MapWithElevationMaplibre
|
||||
trails={[trail]}
|
||||
waypoints={trail.expand?.waypoints}
|
||||
waypoints={trail.expand?.waypoints_via_trail}
|
||||
activeTrail={0}
|
||||
bind:markers
|
||||
showTerrain={true}
|
||||
|
||||
@@ -390,7 +390,7 @@
|
||||
currentHeight += getTextHeight($trail.description, doc, width - 32) + 8;
|
||||
}
|
||||
|
||||
if (includeWaypoints && $trail.expand?.waypoints) {
|
||||
if (includeWaypoints && $trail.expand?.waypoints_via_trail) {
|
||||
const header = $_("waypoints", { values: { n: 2 } })
|
||||
let textHeight = getTextHeight(header, doc, width - 32)
|
||||
if (currentHeight + textHeight + 8 > height) {
|
||||
@@ -401,7 +401,7 @@
|
||||
currentHeight += textHeight + 8;
|
||||
doc.setFont("IBMPlexSans-Regular", "normal");
|
||||
|
||||
($trail.expand.waypoints || []).forEach(waypoint => {
|
||||
($trail.expand.waypoints_via_trail || []).forEach(waypoint => {
|
||||
let description = waypoint.description || "";
|
||||
let name = waypoint.name || "";
|
||||
|
||||
@@ -616,7 +616,7 @@
|
||||
<div class="basis-full">
|
||||
<MapWithElevationMaplibre
|
||||
trails={[$trail]}
|
||||
waypoints={$trail.expand?.waypoints}
|
||||
waypoints={$trail.expand?.waypoints_via_trail}
|
||||
activeTrail={0}
|
||||
onzoom={updateScale}
|
||||
bind:map
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
summit_logs_via_trail: z
|
||||
.array(SummitLogCreateSchema)
|
||||
.optional(),
|
||||
waypoints: z
|
||||
waypoints_via_trail: z
|
||||
.array(
|
||||
WaypointCreateSchema.extend({
|
||||
marker: z.any().optional(),
|
||||
@@ -384,11 +384,10 @@
|
||||
}
|
||||
|
||||
function clearWaypoints() {
|
||||
for (const waypoint of $formData.expand!.waypoints ?? []) {
|
||||
for (const waypoint of $formData.expand!.waypoints_via_trail ?? []) {
|
||||
waypoint.marker?.remove();
|
||||
}
|
||||
$formData.expand!.waypoints = [];
|
||||
$formData.waypoints = [];
|
||||
$formData.expand!.waypoints_via_trail = [];
|
||||
}
|
||||
|
||||
function initRouteAnchors(gpx: GPX, addToMap: boolean = false) {
|
||||
@@ -445,29 +444,28 @@
|
||||
}
|
||||
|
||||
function deleteWaypoint(index: number) {
|
||||
const wp = $formData.expand!.waypoints?.splice(index, 1);
|
||||
$formData.waypoints.splice(index, 1);
|
||||
const wp = $formData.expand!.waypoints_via_trail?.splice(index, 1);
|
||||
|
||||
if (!$formData.expand!.waypoints?.length) {
|
||||
$formData.expand!.waypoints = [];
|
||||
if (!$formData.expand!.waypoints_via_trail?.length) {
|
||||
$formData.expand!.waypoints_via_trail = [];
|
||||
}
|
||||
$formData.expand!.waypoints = $formData.expand!.waypoints;
|
||||
$formData.expand!.waypoints_via_trail = $formData.expand!.waypoints_via_trail;
|
||||
|
||||
// updateTrailOnMap();
|
||||
}
|
||||
|
||||
function saveWaypoint(savedWaypoint: Waypoint) {
|
||||
let editedWaypointIndex =
|
||||
$formData.expand!.waypoints?.findIndex(
|
||||
$formData.expand!.waypoints_via_trail?.findIndex(
|
||||
(s) => s.id == savedWaypoint.id,
|
||||
) ?? -1;
|
||||
|
||||
if (editedWaypointIndex >= 0) {
|
||||
$formData.expand!.waypoints![editedWaypointIndex] = savedWaypoint;
|
||||
$formData.expand!.waypoints_via_trail![editedWaypointIndex] = savedWaypoint;
|
||||
} else {
|
||||
savedWaypoint.id = cryptoRandomString({ length: 15 });
|
||||
$formData.expand!.waypoints = [
|
||||
...($formData.expand!.waypoints ?? []),
|
||||
$formData.expand!.waypoints_via_trail = [
|
||||
...($formData.expand!.waypoints_via_trail ?? []),
|
||||
savedWaypoint,
|
||||
];
|
||||
|
||||
@@ -478,15 +476,15 @@
|
||||
function moveMarker(marker: M.Marker, wpId?: string) {
|
||||
const position = marker.getLngLat();
|
||||
const editableWaypointIndex =
|
||||
$formData.expand!.waypoints?.findIndex((w) => w.id == wpId) ?? -1;
|
||||
$formData.expand!.waypoints_via_trail?.findIndex((w) => w.id == wpId) ?? -1;
|
||||
const editableWaypoint =
|
||||
$formData.expand!.waypoints![editableWaypointIndex];
|
||||
$formData.expand!.waypoints_via_trail![editableWaypointIndex];
|
||||
if (!editableWaypoint) {
|
||||
return;
|
||||
}
|
||||
editableWaypoint.lat = position.lat;
|
||||
editableWaypoint.lon = position.lng;
|
||||
$formData.expand!.waypoints = [...($formData.expand!.waypoints ?? [])];
|
||||
$formData.expand!.waypoints_via_trail = [...($formData.expand!.waypoints_via_trail ?? [])];
|
||||
// updateTrailOnMap();
|
||||
}
|
||||
|
||||
@@ -1369,7 +1367,7 @@
|
||||
{$_("waypoints", { values: { n: 2 } })}
|
||||
</h3>
|
||||
<ul>
|
||||
{#each $formData.expand?.waypoints ?? [] as waypoint, i}
|
||||
{#each $formData.expand?.waypoints_via_trail ?? [] as waypoint, i}
|
||||
<li
|
||||
onmouseenter={() => openMarkerPopup(waypoint)}
|
||||
onmouseleave={() => openMarkerPopup(waypoint)}
|
||||
@@ -1501,7 +1499,7 @@
|
||||
<div id="trail-map">
|
||||
<MapWithElevationMaplibre
|
||||
trails={mapTrail}
|
||||
waypoints={$formData.expand?.waypoints}
|
||||
waypoints={$formData.expand?.waypoints_via_trail}
|
||||
drawing={drawingActive}
|
||||
showTerrain={true}
|
||||
onmarkerdragend={moveMarker}
|
||||
|
||||
Reference in New Issue
Block a user