diff --git a/frontend/src/components/Map.tsx b/frontend/src/components/Map.tsx index bc10edd..751b12e 100644 --- a/frontend/src/components/Map.tsx +++ b/frontend/src/components/Map.tsx @@ -381,6 +381,26 @@ export function Map(props: MapProps) { .setMaxWidth("450px") .addTo(mapRef.current); popup.on('close', () => root.unmount()); + + // Pan map to ensure popup is fully visible + requestAnimationFrame(() => { + const popupEl = popup.getElement(); + if (!popupEl || !mapRef.current) return; + const popupRect = popupEl.getBoundingClientRect(); + const mapRect = mapRef.current.getContainer().getBoundingClientRect(); + const padding = 20; + let dx = 0, dy = 0; + if (popupRect.left < mapRect.left + padding) + dx = popupRect.left - mapRect.left - padding; + if (popupRect.right > mapRect.right - padding) + dx = popupRect.right - mapRect.right + padding; + if (popupRect.top < mapRect.top + padding) + dy = popupRect.top - mapRect.top - padding; + if (popupRect.bottom > mapRect.bottom - padding) + dy = popupRect.bottom - mapRect.bottom + padding; + if (dx !== 0 || dy !== 0) + mapRef.current.panBy([dx, dy], { duration: 300 }); + }); } }