"use client"; import { MapProps } from "@/types"; import { useMemo, useRef, ChangeEvent } from "react"; import { useTranslations } from "next-intl"; import { useSetAtom } from "jotai"; import { mapBoundsAtom } from "@/app/atoms"; import L from "leaflet"; import { MapContainer, TileLayer, Marker } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css"; import "leaflet-defaulticon-compatibility"; import MapEvents from "@/app/[lang]/components/MapEvents"; const Map = ({ position, setPosition, center }: MapProps) => { const t = useTranslations("Map"); const latValue = position.lat.toFixed(4); const lngValue = position.lng.toFixed(4); const setMapBounds = useSetAtom(mapBoundsAtom); const markerRef = useRef(null); const handleLatChange = ({ target }: ChangeEvent) => { const newLat = Number(target.value); setPosition((prevPosition) => ({ ...prevPosition, lat: newLat })); }; const handleLngChange = ({ target }: ChangeEvent) => { const newLng = Number(target.value); setPosition((prevPosition) => ({ ...prevPosition, lng: newLng })); }; const eventHandlers = useMemo( () => ({ dragend() { const marker = markerRef.current; if (marker != null) { setPosition(marker.getLatLng()); } }, }), [setPosition], ); return ( <>
{ if (map) { setMapBounds(map.getBounds()); } }} >
); }; export default Map;