From 0623287206dcc9a4898144056bbcc28a0f685572 Mon Sep 17 00:00:00 2001 From: Flomp Date: Tue, 10 Mar 2026 21:48:54 +0100 Subject: [PATCH] initial commit (#881) Co-authored-by: Christian Beutel <> --- .../trail/map_with_elevation_maplibre.svelte | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/web/src/lib/components/trail/map_with_elevation_maplibre.svelte b/web/src/lib/components/trail/map_with_elevation_maplibre.svelte index 7c862265..8f977d16 100644 --- a/web/src/lib/components/trail/map_with_elevation_maplibre.svelte +++ b/web/src/lib/components/trail/map_with_elevation_maplibre.svelte @@ -404,13 +404,17 @@ new PreviewLayer(map, geojson, { preview: { onEnter: (e) => { - const trail = trails.find(t => t.id === (e as any).features[0].properties.trail) - if(!trail) return; - highlightCluster(trail) + const trail = trails.find( + (t) => + t.id === + (e as any).features[0].properties.trail, + ); + if (!trail) return; + highlightCluster(trail, e.lngLat); }, onLeave: (e) => { - unHighlightCluster() - } + // unHighlightCluster(); + }, }, }), ); @@ -510,16 +514,30 @@ // map?.setPaintProperty(id, "line-color", "#648ad5"); } - export async function highlightCluster(trail: Trail) { + export async function highlightCluster( + trail: Trail, + lnglat?: M.LngLatLike, + ) { if (!map || !map.style) { return; } + clusterPopup?.remove(); clusterPopup = createPopupFromTrail(trail); - clusterPopup.setLngLat([trail.lon!, trail.lat!]).addTo(map); - + clusterPopup.setLngLat(lnglat ?? [trail.lon!, trail.lat!]).addTo(map); clusterPopup.on("close", () => { unHighlightCluster(false); }); + map.on("mousemove", unHighlightClusterDistanceNotifier) + } + + function unHighlightClusterDistanceNotifier(e: M.MapMouseEvent) { + if (!clusterPopup || !map) { + return + } + if (map.project(clusterPopup.getLngLat()).dist(map.project(e.lngLat)) > 60) { + clusterPopup.remove(); + map.off("mousemove", unHighlightClusterDistanceNotifier) + } } export async function unHighlightCluster(closePopup: boolean = true) { @@ -736,7 +754,7 @@ } } - let geolocateControl : M.GeolocateControl; + let geolocateControl: M.GeolocateControl; onMount(async () => { const initialState = { @@ -808,14 +826,14 @@ ); geolocateControl = new M.GeolocateControl({ - positionOptions: { - enableHighAccuracy: true, - }, - fitBoundsOptions: { - animate: fitBounds == "animate", - }, - trackUserLocation: true, - }); + positionOptions: { + enableHighAccuracy: true, + }, + fitBoundsOptions: { + animate: fitBounds == "animate", + }, + trackUserLocation: true, + }); map.addControl(geolocateControl); if (showStyleSwitcher) { @@ -912,7 +930,7 @@ if (!page.data.settings?.behavior) return; if (page.data.settings.behavior.allowAutoGeolocate === true) { - if (geolocateControl._watchState === 'OFF') { + if (geolocateControl._watchState === "OFF") { geolocateControl.options.trackUserLocation = true; geolocateControl.trigger(); } @@ -1001,7 +1019,10 @@ @apply bg-menu-item-background-focus w-3 aspect-square rounded-full; } - :global(.maplibregl-user-location-accuracy-circle, .maplibregl-user-location-dot) { + :global( + .maplibregl-user-location-accuracy-circle, + .maplibregl-user-location-dot + ) { pointer-events: none; }