Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/components/CoordinatesDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { searchOverlayHelper } from '../utils/externalSearchUtils';

export function CoordinatesDisplay({
flipped,
mapRef,
mapObj,
externalSearchRef,
externalSearchMarkerRef,
}: {
flipped: boolean;
mapRef: React.RefObject<Map | null>;
mapObj: Map;
externalSearchRef: React.RefObject<HTMLDivElement | null>;
externalSearchMarkerRef: React.RefObject<Feature<Geometry> | null>;
}) {
Expand Down Expand Up @@ -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'));
Expand All @@ -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,
Expand All @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/components/OpenLayersMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,14 @@ export function OpenLayersMap({
goForward={goForward}
/>
<GraticuleLayer mapRef={mapRef} flipped={flipTiles} />
<CoordinatesDisplay
flipped={flipTiles}
mapRef={mapRef}
externalSearchRef={externalSearchRef}
externalSearchMarkerRef={externalSearchMarkerRef}
/>
{mapRef.current && (
<CoordinatesDisplay
flipped={flipTiles}
mapObj={mapRef.current}
externalSearchRef={externalSearchRef}
externalSearchMarkerRef={externalSearchMarkerRef}
/>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/layers/GraticuleLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function GraticuleLayer({
mapRef.current.addLayer(graticule1);
mapRef.current.addLayer(graticule2);
}
}, [mapRef, flipped, handleLatLabelFormat, handleLonLabelFormat]);
}, [mapRef.current, flipped]);

return null;
}