import { DivIcon, LatLng } from "leaflet";
import { MapPinIcon } from "lucide-react";
import { useEffect, useState } from "react";
import ReactDOMServer from "react-dom/server";
import { MapContainer, Marker, TileLayer, useMapEvents } from "react-leaflet";
const markerIcon = new DivIcon({
className: "relative border-none",
html: ReactDOMServer.renderToString(),
});
interface MarkerProps {
position: LatLng | undefined;
onChange: (position: LatLng) => void;
readonly?: boolean;
}
const LocationMarker = (props: MarkerProps) => {
const [position, setPosition] = useState(props.position);
const map = useMapEvents({
click(e) {
if (props.readonly) {
return;
}
setPosition(e.latlng);
map.locate();
// Call the parent onChange function.
props.onChange(e.latlng);
},
locationfound() {},
});
useEffect(() => {
map.attributionControl.setPrefix("");
map.locate();
}, []);
return position === undefined ? null : ;
};
interface MapProps {
readonly?: boolean;
latlng?: LatLng;
onChange?: (position: LatLng) => void;
}
const DEFAULT_CENTER_LAT_LNG = new LatLng(48.8584, 2.2945);
const LeafletMap = (props: MapProps) => {
const position = props.latlng || DEFAULT_CENTER_LAT_LNG;
return (
{}} />
);
};
export default LeafletMap;