diff --git a/src/components/CoordinatesDisplay.tsx b/src/components/CoordinatesDisplay.tsx index f316284..868f212 100644 --- a/src/components/CoordinatesDisplay.tsx +++ b/src/components/CoordinatesDisplay.tsx @@ -8,12 +8,12 @@ import { searchOverlayHelper } from '../utils/externalSearchUtils'; export function CoordinatesDisplay({ flipped, - mapRef, + mapObj, externalSearchRef, externalSearchMarkerRef, }: { flipped: boolean; - mapRef: React.RefObject; + mapObj: Map; externalSearchRef: React.RefObject; externalSearchMarkerRef: React.RefObject | null>; }) { @@ -56,17 +56,15 @@ export function CoordinatesDisplay({ }, []); useEffect(() => { - if (!mapRef.current) return; - const currentMapRef = mapRef.current; + const currentMapRef = mapObj; const updateCoords = (e: MapBrowserEvent) => setCoordinates(e.coordinate); currentMapRef.on('pointermove', updateCoords); return () => currentMapRef.un('pointermove', updateCoords); - }, [mapRef]); + }, []); const onSubmit = useCallback( (e: FormEvent) => { e.preventDefault(); - if (!mapRef.current) return; const formData = new FormData(e.target as HTMLFormElement); const raStr = String(formData.get('ra')); const decStr = String(formData.get('dec')); @@ -79,9 +77,9 @@ export function CoordinatesDisplay({ [ra, dec], flipped ); - mapRef.current.getView().setCenter(transformedCoords); + mapObj.getView().setCenter(transformedCoords); searchOverlayHelper( - mapRef.current, + mapObj, externalSearchRef, externalSearchMarkerRef, transformedCoords, @@ -93,7 +91,7 @@ export function CoordinatesDisplay({ setShowCoordInputs(false); (e.target as HTMLFormElement).reset(); }, - [mapRef, externalSearchRef, externalSearchMarkerRef, flipped] + [mapObj, externalSearchRef, externalSearchMarkerRef, flipped] ); // Return early if coordinates aren't defined diff --git a/src/components/OpenLayersMap.tsx b/src/components/OpenLayersMap.tsx index 4049df5..f7819b7 100644 --- a/src/components/OpenLayersMap.tsx +++ b/src/components/OpenLayersMap.tsx @@ -571,12 +571,14 @@ export function OpenLayersMap({ goForward={goForward} /> - + {mapRef.current && ( + + )} ); } diff --git a/src/components/layers/GraticuleLayer.tsx b/src/components/layers/GraticuleLayer.tsx index ad3d015..beb560b 100644 --- a/src/components/layers/GraticuleLayer.tsx +++ b/src/components/layers/GraticuleLayer.tsx @@ -77,7 +77,7 @@ export function GraticuleLayer({ mapRef.current.addLayer(graticule1); mapRef.current.addLayer(graticule2); } - }, [mapRef, flipped, handleLatLabelFormat, handleLonLabelFormat]); + }, [mapRef.current, flipped]); return null; }