From b4d23bf91bacf467ccea3068a6f6f01d993977a1 Mon Sep 17 00:00:00 2001 From: Kenneth Brewer Date: Thu, 30 Apr 2026 03:21:40 -0400 Subject: [PATCH] Added a temporary marker when the user flies to a location. It will disappear when the add map marker button is clicked. --- .../inertia/components/maps/MapComponent.tsx | 33 ++++++ .../components/maps/MapMarkerFormPopup.tsx | 6 +- .../components/maps/ViewMapMarkerPopup.tsx | 107 ++++++++++-------- admin/inertia/pages/maps.tsx | 24 +++- 4 files changed, 121 insertions(+), 49 deletions(-) diff --git a/admin/inertia/components/maps/MapComponent.tsx b/admin/inertia/components/maps/MapComponent.tsx index 201bc8e..922713d 100644 --- a/admin/inertia/components/maps/MapComponent.tsx +++ b/admin/inertia/components/maps/MapComponent.tsx @@ -88,9 +88,11 @@ export default function MapComponent({ }: MapComponentProps) { const mapRef = useRef(null) const animationFrameRef = useRef(null) + const handledMapCommandIdRef = useRef(null) const { markers, addMarker, updateMarker, deleteMarker } = useMapMarkers() + const [targetIndicator, setTargetIndicator] = useState<{ lng: number; lat: number } | null>(null) const [isDraggingMap, setIsDraggingMap] = useState(false) const [placingMarker, setPlacingMarker] = useState<{ lng: number; lat: number } | null>(null) const [selectedMarkerId, setSelectedMarkerId] = useState(null) @@ -149,10 +151,18 @@ export default function MapComponent({ useEffect(() => { if (!mapCommand) return + if (handledMapCommandIdRef.current === mapCommand.id) return + + handledMapCommandIdRef.current = mapCommand.id if (mapCommand.action === 'fly') { const currentZoom = mapRef.current?.getZoom() ?? 12 + setTargetIndicator({ + lng: mapCommand.lng, + lat: mapCommand.lat, + }) + mapRef.current?.flyTo({ center: [mapCommand.lng, mapCommand.lat], zoom: currentZoom, @@ -165,6 +175,8 @@ export default function MapComponent({ if (mapCommand.action === 'marker') { if (!confirmDiscardMarkerChanges()) return + setTargetIndicator(null) + const currentZoom = mapRef.current?.getZoom() ?? 12 mapRef.current?.flyTo({ @@ -203,6 +215,7 @@ export default function MapComponent({ setSelectedMarkerId(null) setEditingMarkerId(null) setHasUnsavedMarkerChanges(false) + setTargetIndicator(null) }, [confirmDiscardMarkerChanges] ) @@ -239,6 +252,7 @@ export default function MapComponent({ ) const handleFlyTo = useCallback((longitude: number, latitude: number) => { + setTargetIndicator(null) mapRef.current?.flyTo({ center: [longitude, latitude], zoom: 12, duration: 1500 }) }, []) @@ -321,6 +335,20 @@ export default function MapComponent({ /> )} + {targetIndicator && ( + +