From a782e0e47184f1e506831d28f88a39d6e4c87312 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 16 Sep 2026 13:01:17 +0200 Subject: [PATCH] fix(map): make stops that share a spot reachable again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A trip that models one building as several stops — drop the bags, check in, the museum inside the hotel — drew every pin on the same pixel, and only the top one could be clicked, hovered or seen. Clustering is the mechanism for exactly that: the plugin keeps children no zoom level can separate in one cluster and fans them apart on click. disableClusteringAtZoom pinned the group's own maximum zoom to 8, which both removed every cluster above it and moved the only fan trigger into a zoom band a trip planner never operates in, so the spiderfyOnMaxZoom set beside it could never fire. The cutoff is gone. maxClusterRadius is a function of zoom instead: the same generous radius as before in the overview, a pin's width above it, so stops that are genuinely apart keep their own pins and a pile becomes a counted bubble that fans open. Selecting a buried stop from the places rail now opens the bubble it is hiding in rather than doing nothing visible, and it does that without moving the camera, which stays the selection's own concern. The GL renderer has no fan to open, so folding a pin there removes the only thing that was left rather than providing a way in. It folds at a far tighter radius — genuine coincidence, where nothing was reachable to begin with — and draws the selected member of a pile, so the rail reaches it there too. A map object without a projector now skips folding instead of dropping every marker. The public share page spreads the same options and has no rail to fall back on, which made it the worse case; it is fixed by the same change. Closes #2344 --- client/src/components/Map/MapView.test.tsx | 100 ++++++++++++++- client/src/components/Map/MapView.tsx | 53 +++++++- client/src/components/Map/MapViewGL.test.tsx | 108 ++++++++++++++++ client/src/components/Map/MapViewGL.tsx | 30 ++++- .../components/Map/coincidentPlaces.test.ts | 55 ++++++++ client/src/components/Map/coincidentPlaces.ts | 79 ++++++++++++ .../src/components/Map/markerCluster.test.ts | 121 ++++++++++++++++++ client/src/components/Map/markerCluster.ts | 47 ++++++- .../unit/pages/SharedTripPage.map.test.tsx | 20 ++- 9 files changed, 598 insertions(+), 15 deletions(-) create mode 100644 client/src/components/Map/coincidentPlaces.test.ts create mode 100644 client/src/components/Map/coincidentPlaces.ts create mode 100644 client/src/components/Map/markerCluster.test.ts diff --git a/client/src/components/Map/MapView.test.tsx b/client/src/components/Map/MapView.test.tsx index 3a35c46d3..e81ec544f 100644 --- a/client/src/components/Map/MapView.test.tsx +++ b/client/src/components/Map/MapView.test.tsx @@ -56,6 +56,37 @@ vi.mock('../../hooks/useGeolocation', () => ({ // after the map already rendered. const thumbCallbacks = vi.hoisted(() => new Map void>()) +// The cluster group and the Leaflet markers MapView reaches for when a selection lands +// on a stop that shares its coordinates and so has no pin of its own. `stacked` decides +// whether the group answers with a bubble or with the marker itself. +const clusterMock = vi.hoisted(() => { + const spiderfy = vi.fn() + return { + spiderfy, + stacked: false, + asked: [] as unknown[], + markers: new Map(), + /** + * One marker double per pin, not per coordinate. Stops that share a coordinate are + * the whole point here, and a registry keyed by place id only proves anything when + * the two markers on that coordinate can be told apart. + */ + stub(node: Element) { + const existing = clusterMock.markers.get(node) + if (existing) return existing + const fresh = { pin: node } + clusterMock.markers.set(node, fresh) + return fresh + }, + group: { + getVisibleParent(marker: unknown) { + clusterMock.asked.push(marker) + return clusterMock.stacked ? { spiderfy } : marker + }, + }, + } +}) + vi.mock('react-leaflet', () => ({ // center/zoom are surfaced so tests can assert the camera the map is built // with; maxZoom because a cluster refuses to attach to a map without one. @@ -63,9 +94,16 @@ vi.mock('react-leaflet', () => ({
{children}
), TileLayer: () =>
, - Marker: ({ children, eventHandlers, position, icon, zIndexOffset }: any) => ( + Marker: ({ children, eventHandlers, position, icon, zIndexOffset, ref }: any) => (
{ if (node && zIndexOffset === 500) eventHandlers?.add?.({ target: { getElement: () => node } }) }} + ref={node => { + if (node && zIndexOffset === 500) eventHandlers?.add?.({ target: { getElement: () => node } }) + // Stands in for the L.Marker react-leaflet hands back, so MapView's registry has + // something to look a selected stop up by. Only the markers the cluster group + // holds get one: a place pin is all this double stands in for, and the route-via + // markers outside the group expect a Leaflet marker of their own. + ref?.(node?.closest('[data-testid="cluster-group"]') ? clusterMock.stub(node) : null) + }} data-testid="marker" data-lat={position[0]} data-lng={position[1]} @@ -118,8 +156,8 @@ vi.mock('react-leaflet', () => ({ vi.mock('react-leaflet-cluster', () => ({ // The real cluster group calls iconCreateFunction itself; the probe button // lets a test invoke it with a chosen child count. - default: ({ children, iconCreateFunction }: any) => ( -
+ default: ({ children, iconCreateFunction, ref }: any) => ( +
{ ref?.(node ? clusterMock.group : null) }}>