diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx index de5fd44..c61dbe3 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx @@ -35,7 +35,11 @@ const SidebarListItems = ({ menuItem, dispatch }) => { {menuItem.badges && ( {menuItem.badges.map((badge, i) => ( - + ))} )} diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx index 0066097..755b34c 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx @@ -33,7 +33,11 @@ const SidebarSubitems = ({ subitem, dispatch }) => { {subitem.badges && ( {subitem.badges.map((badge, i) => ( - + ))} )} diff --git a/src/core/components/FlyToLocation.jsx b/src/core/components/FlyToLocation.jsx new file mode 100644 index 0000000..0f63772 --- /dev/null +++ b/src/core/components/FlyToLocation.jsx @@ -0,0 +1,32 @@ +import { useEffect, useState } from "react"; +import { useMap } from "react-leaflet"; + +const FlyToUserLocation = ({ Component }) => { + const [userPosition, setUserPosition] = useState(null); + const map = useMap(); + + const handleLocateUser = () => { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + (position) => { + setUserPosition([position.coords.latitude, position.coords.longitude]); + }, + (error) => { + console.error("Location error:", error); + } + ); + } else { + alert("مرورگر شما از موقعیت‌یاب پشتیبانی نمی‌کند."); + } + }; + + useEffect(() => { + if (userPosition) { + map.flyTo(userPosition, 16); + } + }, [userPosition, map]); + + return ; +}; + +export default FlyToUserLocation; diff --git a/src/core/components/MapInfoOneMarker.jsx b/src/core/components/MapInfoOneMarker.jsx index a68d4bf..8a887da 100644 --- a/src/core/components/MapInfoOneMarker.jsx +++ b/src/core/components/MapInfoOneMarker.jsx @@ -1,11 +1,13 @@ -import React, { useEffect, useRef, useState } from "react"; -import { Marker, useMapEvents } from "react-leaflet"; -import "leaflet/dist/leaflet.css"; -import L from "leaflet"; -import { Alert, Box, Button, Stack, Typography, Zoom } from "@mui/material"; -import dynamic from "next/dynamic"; -import MapLoading from "@/core/components/MapLayer/Loading"; import HereIcon from "@/assets/images/examine_marker_active.png"; +import MapLoading from "@/core/components/MapLayer/Loading"; +import { MyLocation } from "@mui/icons-material"; +import { Alert, Box, Button, Stack, Typography, Zoom } from "@mui/material"; +import L from "leaflet"; +import "leaflet/dist/leaflet.css"; +import dynamic from "next/dynamic"; +import { useEffect, useRef, useState } from "react"; +import { Marker, useMapEvents } from "react-leaflet"; +import FlyToUserLocation from "./FlyToLocation"; const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { loading: () => , @@ -113,20 +115,36 @@ const MapInteraction = ({ setValue, startLat, startLng, title }) => { - {isMarkerLocked && ( - - - - )} + + ( + + )} + /> + ); }; diff --git a/src/core/components/MapInfoTwoMarker.jsx b/src/core/components/MapInfoTwoMarker.jsx index 9b114d3..668635c 100644 --- a/src/core/components/MapInfoTwoMarker.jsx +++ b/src/core/components/MapInfoTwoMarker.jsx @@ -7,6 +7,8 @@ import dynamic from "next/dynamic"; import MapLoading from "@/core/components/MapLayer/Loading"; import EndIcon from "@/assets/images/examine_marker_active.png"; import StartIcon from "@/assets/images/examine_marker.png"; +import FlyToUserLocation from "./FlyToLocation"; +import { MyLocation } from "@mui/icons-material"; const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { loading: () => , @@ -137,12 +139,12 @@ const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { - @@ -197,16 +199,38 @@ const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { - )} + + ( + + )} + /> + ); }; diff --git a/src/core/utils/pageMenu.js b/src/core/utils/pageMenu.js index 6b0d367..2ce4083 100644 --- a/src/core/utils/pageMenu.js +++ b/src/core/utils/pageMenu.js @@ -290,7 +290,10 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: [{ key: "safetyAndPrivacy.step_one", color: 'warning' }, { key: "safetyAndPrivacy.step_two", color: 'error' }], + badges: [ + { key: "safetyAndPrivacy.step_one", color: "warning" }, + { key: "safetyAndPrivacy.step_two", color: "error" }, + ], Subitems: [ { id: "safetyAndPrivacyManagmentOparation", @@ -519,6 +522,6 @@ export const pageMenu = [ icon: , permissions: [""], }, - ] - } + ], + }, ];