(null);
+ const canRevealStandalone = follow && zoom >= PLACE_FOCUS_ZOOM;
+ const standalonePlaceId = canRevealStandalone && selection === standaloneSelection ? selectedPlaceId : null;
+
+ const registerClusterGroup = useCallback((group: unknown) => {
+ clusterGroupRef.current = (group as ClusterGroupLike | null) ?? null;
+ }, []);
+ const registerMarker = useCallback((id: number, marker: L.Marker | null) => {
+ if (marker) markersRef.current.set(id, marker);
+ else markersRef.current.delete(id);
+ }, []);
+ const markerElement = useCallback((id: number) => markersRef.current.get(id)?.getElement() ?? null, []);
+
+ const revealSelectedPlace = useCallback(
+ (afterClustering = true) => {
+ const id = selection.id;
+ if (id == null || standalonePlaceId === id) return;
+ revealInCluster(
+ clusterGroupRef.current,
+ markersRef.current.get(id),
+ afterClustering && canRevealStandalone ? () => setStandaloneSelection(selection) : undefined
+ );
+ },
+ [selection, canRevealStandalone, standalonePlaceId]
+ );
+
+ useEffect(() => {
+ if (selectedPlaceId == null) return;
+ revealSelectedPlace(false);
+ // Let Leaflet finish re-clustering and the marker group's batched updates before
+ // drawing the selected pin by itself. The rest of a dense group keeps its bubble.
+ const frame = requestAnimationFrame(() => revealSelectedPlace());
+ return () => cancelAnimationFrame(frame);
+ }, [selectedPlaceId, places, revealSelectedPlace]);
+
+ return { registerClusterGroup, registerMarker, markerElement, standalonePlaceId, revealSelectedPlace };
+}
diff --git a/client/src/components/Map/useSelectionCameraGL.test.ts b/client/src/components/Map/useSelectionCameraGL.test.ts
index 02d5d33ae..28de7b382 100644
--- a/client/src/components/Map/useSelectionCameraGL.test.ts
+++ b/client/src/components/Map/useSelectionCameraGL.test.ts
@@ -43,10 +43,10 @@ function setup(selectedPlaceId: number, follow = true) {
}
describe('useSelectionCameraGL', () => {
- it('SELCAM-GL-001: flies to a new selection, padded by the panels, at least to zoom 14', () => {
+ it('SELCAM-GL-001: focuses a new selection at street level with room for the panels (#3306)', () => {
const { map } = setup(1);
expect(map.flyTo).toHaveBeenCalledWith(
- expect.objectContaining({ center: [50, 70], zoom: 14, padding: padding(0) })
+ expect.objectContaining({ center: [50, 70], zoom: 16, padding: padding(0) })
);
});
diff --git a/client/src/components/Map/useSelectionCameraGL.ts b/client/src/components/Map/useSelectionCameraGL.ts
index 87f77f3a8..c26718dfc 100644
--- a/client/src/components/Map/useSelectionCameraGL.ts
+++ b/client/src/components/Map/useSelectionCameraGL.ts
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react';
import type { ViewportPadding } from '../../utils/mapViewport';
import { isUnderChrome } from './mapChromePadding';
-import { selectedPlaceTarget, type MapTarget } from './selectedPlaceTarget';
+import { PLACE_FOCUS_ZOOM, selectedPlaceTarget, type MapTarget } from './selectedPlaceTarget';
/** The part of a MapLibre/Mapbox map the selection camera drives. */
interface SelectionCameraMap {
@@ -61,7 +61,7 @@ export function useSelectionCameraGL({
try {
map.flyTo({
center: [lng, lat],
- zoom: Math.max(map.getZoom(), 14),
+ zoom: Math.max(map.getZoom(), PLACE_FOCUS_ZOOM),
pitch: enableMapbox3d ? 45 : 0,
duration: 400,
padding,