diff --git a/web/src/components/LeafletMap.tsx b/web/src/components/LeafletMap.tsx
index f71122ce4..6cffccee6 100644
--- a/web/src/components/LeafletMap.tsx
+++ b/web/src/components/LeafletMap.tsx
@@ -1,8 +1,8 @@
import { DivIcon, LatLng } from "leaflet";
import { MapPinIcon } from "lucide-react";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import ReactDOMServer from "react-dom/server";
-import { MapContainer, Marker, TileLayer, useMapEvents } from "react-leaflet";
+import { MapContainer, Marker, TileLayer, useMap, useMapEvents } from "react-leaflet";
const markerIcon = new DivIcon({
className: "relative border-none",
@@ -17,6 +17,7 @@ interface MarkerProps {
const LocationMarker = (props: MarkerProps) => {
const [position, setPosition] = useState(props.position);
+ const initializedRef = useRef(false);
const map = useMapEvents({
click(e) {
@@ -33,9 +34,12 @@ const LocationMarker = (props: MarkerProps) => {
});
useEffect(() => {
- map.attributionControl.setPrefix("");
- map.locate();
- }, []);
+ if (!initializedRef.current) {
+ map.attributionControl.setPrefix("");
+ map.locate();
+ initializedRef.current = true;
+ }
+ }, [map]);
// Keep marker and map in sync with external position updates
useEffect(() => {
@@ -50,6 +54,27 @@ const LocationMarker = (props: MarkerProps) => {
return position === undefined ? null :