import React, { useEffect, useRef, useState } from "react"; import { Marker, useMapEvents } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import L from "leaflet"; import { Box, Button, Typography } from "@mui/material"; import dynamic from "next/dynamic"; import MapLoading from "@/core/components/MapLayer/Loading"; import HereIcon from "@/assets/images/examine_marker_active.png"; const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { loading: () => , ssr: false, }); const createCustomIcon = (size, iconUrl, labelText) => { if (labelText) { return L.divIcon({ html: `
icon
${labelText}
`, iconSize: size, iconAnchor: [size[0] / 2, size[1]], popupAnchor: [0, -size[1]], }); } return L.icon({ iconUrl: iconUrl, iconSize: size, iconAnchor: [size[0] / 2, size[1]], popupAnchor: [0, -size[1]], }); }; const MapInteraction = ({ setValue, startLat, startLng }) => { const [isMarkerLocked, setIsMarkerLocked] = useState(!!(startLat && startLng)); // وضعیت قفل مارکر const [markerPosition, setMarkerPosition] = useState( startLat && startLng ? { lat: startLat, lng: startLng } : null ); const markerRef = useRef(); const map = useMapEvents({ move(e) { if (!isMarkerLocked && markerRef.current) { markerRef.current.setLatLng(e.target.getCenter()); } }, zoom(e) { if (!isMarkerLocked && markerRef.current) { markerRef.current.setLatLng(e.target.getCenter()); } }, }); useEffect(() => { if (startLat && startLng) { const position = { lat: startLat, lng: startLng }; map.setView(position, 15); } }, [startLat, startLng, map]); const handleMarkerClick = () => { if (!isMarkerLocked) { const center = map.getCenter(); setValue("start_point", { lat: center.lat.toString(), lng: center.lng.toString() }); setMarkerPosition({ lat: center.lat, lng: center.lng }); // به‌روزرسانی موقعیت مارکر setIsMarkerLocked(true); } }; const handleUnlockMarker = () => { setValue("start_point", null); // حذف مقدار قبلی setIsMarkerLocked(false); // باز کردن قفل مارکر setMarkerPosition(null); // تنظیم مارکر به مرکز نقشه }; return ( <> {isMarkerLocked && ( )} ); }; const MapInfoOneMarker = ({ setValue, errors, StartPoint = null }) => { return ( {errors.start_point && ( {errors.start_point.message} )} ); }; export default MapInfoOneMarker;