adds list trail selection from map

This commit is contained in:
Christian Beutel
2024-09-14 20:02:00 +02:00
parent 01ffaf9b8f
commit 7e56d4354d
3 changed files with 22 additions and 14 deletions

View File

@@ -95,5 +95,5 @@
d="M43.857 43.3045C44.0569 43.0652 44.4246 43.0652 44.6245 43.3045L46.6259 45.7008C46.8978 46.0263 46.6663 46.5213 46.2421 46.5213H42.2394C41.8152 46.5213 41.5837 46.0263 41.8556 45.7008L43.857 43.3045Z" d="M43.857 43.3045C44.0569 43.0652 44.4246 43.0652 44.6245 43.3045L46.6259 45.7008C46.8978 46.0263 46.6663 46.5213 46.2421 46.5213H42.2394C41.8152 46.5213 41.5837 46.0263 41.8556 45.7008L43.857 43.3045Z"
fill="#242734" fill="#242734"
/> />
<text x="178" y="64" fill="white" font-size="0.75rem">v0.8.2</text> <text x="178" y="64" fill="white" font-size="0.75rem">v0.9.0</text>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -15,12 +15,14 @@
import { createEventDispatcher, onMount } from "svelte"; import { createEventDispatcher, onMount } from "svelte";
import { _ } from "svelte-i18n"; import { _ } from "svelte-i18n";
import Dropdown from "../base/dropdown.svelte"; import Dropdown from "../base/dropdown.svelte";
import { trail } from "$lib/stores/trail_store";
export let trails: Trail[]; export let trails: Trail[];
export let map: any | null = null; export let map: any | null = null;
export let options: any = {}; export let options: any = {};
export let activeTrailIndex: number | null = 0; export let activeTrailIndex: number | null = 0;
export let markers: any[] = []; export let markers: any[] = [];
export let bindRoutePopup: boolean = true;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@@ -222,10 +224,9 @@
activeTrailIndex = null; activeTrailIndex = null;
markers = []; markers = [];
if (polyline._selected) { if (polyline && polyline._selected) {
activeTrailIndex = trails.findIndex( activeTrailIndex = trails.findIndex(
(t) => t.id == (t) => t.id == polyline.options.id,
polyline.options.id,
); );
for (const waypoint of trails.at(activeTrailIndex!)?.expand for (const waypoint of trails.at(activeTrailIndex!)?.expand
@@ -234,6 +235,11 @@
marker.addTo(markerLayerGroup!); marker.addTo(markerLayerGroup!);
markers.push(marker); markers.push(marker);
} }
dispatch(
"select",
trails.find((t) => t.id == polyline.options.id),
);
} }
}); });
@@ -243,11 +249,7 @@
}); });
gpxGroup.on("route_loaded", ({ route }: { route: any }) => { gpxGroup.on("route_loaded", ({ route }: { route: any }) => {
const trail = trails.find( const trail = trails.find((t) => t.id == route.options.id);
(t) =>
t.id ==
route.options.id,
);
if (!trail) { if (!trail) {
return; return;
@@ -255,8 +257,9 @@
const thumbnail = trail.photos.length const thumbnail = trail.photos.length
? getFileURL(trail, trail.photos[trail.thumbnail]) ? getFileURL(trail, trail.photos[trail.thumbnail])
: "/imgs/default_thumbnail.webp"; : "/imgs/default_thumbnail.webp";
route.bindPopup( if (bindRoutePopup) {
`<a href="/trail/view/${trail.id}" data-sveltekit-preload-data="off"> route.bindPopup(
`<a href="/trail/view/${trail.id}" data-sveltekit-preload-data="off">
<li class="flex items-center gap-4 cursor-pointer text-black max-w-80"> <li class="flex items-center gap-4 cursor-pointer text-black max-w-80">
<div class="shrink-0"><img class="h-14 w-14 object-cover rounded-xl" src="${thumbnail}" alt=""> <div class="shrink-0"><img class="h-14 w-14 object-cover rounded-xl" src="${thumbnail}" alt="">
</div> </div>
@@ -277,7 +280,8 @@
</div> </div>
</li> </li>
</a>`, </a>`,
); );
}
}); });
gpxGroup.addTo(map); gpxGroup.addTo(map);

View File

@@ -175,6 +175,10 @@
bind:map bind:map
bind:this={mapWithElevationMultiple} bind:this={mapWithElevationMultiple}
bind:markers bind:markers
on:select={(e) => {
selectedTrail = e.detail
}}
bindRoutePopup={false}
options={{ itinerary: true, flyToBounds: true }} options={{ itinerary: true, flyToBounds: true }}
></MapWithElevationMultiple> ></MapWithElevationMultiple>
</div> </div>