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 && ( + +