145 lines
3.9 KiB
TypeScript
145 lines
3.9 KiB
TypeScript
"use client";
|
|
import React, { useRef, useState } from "react";
|
|
import { getLocations } from "@/utils/CitizenReport";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { ThreeDots } from "react-loader-spinner";
|
|
import ReactMapboxGl, { Marker, ZoomControl } from "react-mapbox-gl";
|
|
import marker from "@/assets/images/location.svg";
|
|
import RequestCard from "../Requests/RequestCard";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const accessToken = process.env.REACT_APP_ACCESS_TOKEN || "";
|
|
|
|
const MapContainer = ReactMapboxGl({
|
|
accessToken: accessToken,
|
|
minZoom: 8,
|
|
maxZoom: 15,
|
|
// zoom: 9,
|
|
});
|
|
|
|
const OnMapRequests = () => {
|
|
const [selected, setSelected] = useState(null);
|
|
|
|
// refs
|
|
const detailsRef = useRef(null);
|
|
const wrappersRef = useRef(null);
|
|
|
|
const defaultCoords = {
|
|
// latitude: instances[0].latitude,
|
|
// longitude: instances[0].longitude,
|
|
};
|
|
|
|
// hooks
|
|
// const [detailsClicked, setDetailsClicked] = useClick({
|
|
// element: detailsRef,
|
|
// // whitelists,
|
|
// });
|
|
|
|
// functions
|
|
// const showDetails = (request) => {
|
|
// setSelected(request);
|
|
// setDetailsClicked(true);
|
|
// };
|
|
|
|
const showDetails = () => {
|
|
// setSelected(request);
|
|
// setDetailsClicked(true);
|
|
};
|
|
|
|
// const onMapClicked = (e, x) => {
|
|
// setSelected(null);
|
|
// };
|
|
|
|
const {
|
|
data: LocationData,
|
|
isLoading,
|
|
isError,
|
|
isSuccess,
|
|
refetch,
|
|
} = useQuery({
|
|
queryKey: ["Locations"],
|
|
queryFn: () => getLocations(),
|
|
// refetchOnWindowFocus: false,
|
|
});
|
|
|
|
if (isSuccess) {
|
|
console.log(LocationData?.locations[0].locations);
|
|
const fetchedContent = LocationData?.locations[0].locations;
|
|
console.log(fetchedContent);
|
|
}
|
|
|
|
if (isError) {
|
|
console.log("have a errorrrrrrr ");
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{isLoading ? (
|
|
<div className="flex justify-center text-center w-36">
|
|
<ThreeDots
|
|
visible={true}
|
|
height="50"
|
|
width="50"
|
|
color="#003778"
|
|
radius="9"
|
|
ariaLabel="three-dots-loading"
|
|
wrapperStyle={{}}
|
|
wrapperClass=""
|
|
/>
|
|
</div>
|
|
) : (
|
|
<MapContainer
|
|
// center={[
|
|
// store.instance?.longitude || defaultCoords.longitude,
|
|
// store.instance?.latitude || defaultCoords.latitude,
|
|
// ]}
|
|
center={[54.3683, 32.4279]}
|
|
containerStyle={{ height: "100%", width: "100%", borderRadius: 20 }}
|
|
style={`https://api.parsimap.ir/styles/parsimap-streets-v11?key=${process.env.REACT_APP_PMI_TOKEN}`}
|
|
// onClick={onMapClicked}
|
|
>
|
|
{/* {LocationData?.map((d) => (
|
|
<Marker coordinates={[d.longitude, d.latitude]}>
|
|
<img src={marker} onClick={() => showDetails(d)} />
|
|
</Marker>
|
|
))} */}
|
|
{LocationData?.map(() => (
|
|
<Marker>
|
|
<img src={marker} onClick={() => showDetails()} />
|
|
</Marker>
|
|
))}
|
|
|
|
<Marker
|
|
// coordinates={[
|
|
// selected?.address?.longitude || defaultCoords.latitude,
|
|
// selected?.address?.latitude || defaultCoords.longitude,
|
|
// ]}
|
|
>
|
|
<div
|
|
ref={detailsRef}
|
|
// className={cn.join("mapDetailsBox", selected ? "show" : "")}
|
|
// style={{ width: wrappersRef?.current?.offsetWidth - 20 || 200 }}
|
|
>
|
|
{/* {selected && <RequestCard request={selected} />} */}
|
|
</div>
|
|
</Marker>
|
|
<ZoomControl />
|
|
</MapContainer>
|
|
|
|
// <MapContainer
|
|
// style="mapbox://styles/mapbox/streets-v11" // You can choose different styles
|
|
// center={[54.3683, 32.4279]} // Coordinates for Tehran, Iran
|
|
// containerStyle={{
|
|
// height: "400px",
|
|
// width: "100%",
|
|
// }}
|
|
// />
|
|
)}
|
|
|
|
{isError && <p>Map Failed</p>}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default OnMapRequests;
|