|
|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import maplibregl from "maplibre-gl";
|
|
|
|
|
import Map, { MapProvider } from "react-map-gl";
|
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
|
|
import { Sidebar } from "../modules/Sidebar/Sidebar";
|
|
|
|
|
import { Layers } from "./Layers/Layers";
|
|
|
|
|
import { MapPopup } from "./Popup/Popup";
|
|
|
|
|
@ -22,6 +22,7 @@ import { LAYER_IDS } from "./Layers/constants";
|
|
|
|
|
import { Header } from "./Header";
|
|
|
|
|
import { icons } from "../icons/icons-config";
|
|
|
|
|
import { LastMLRun } from "./LastMLRun";
|
|
|
|
|
import { usePostamatesAndPvzGroups } from "../api.js";
|
|
|
|
|
|
|
|
|
|
export const MapComponent = () => {
|
|
|
|
|
const mapRef = useRef(null);
|
|
|
|
|
@ -33,6 +34,30 @@ export const MapComponent = () => {
|
|
|
|
|
const { mode } = useMode();
|
|
|
|
|
const { tableState, openTable } = useTable();
|
|
|
|
|
|
|
|
|
|
const { data: postamatesAndPvzGroups } = usePostamatesAndPvzGroups();
|
|
|
|
|
|
|
|
|
|
const mapIcons = useMemo(() => {
|
|
|
|
|
if (!postamatesAndPvzGroups) return icons;
|
|
|
|
|
const res = []
|
|
|
|
|
postamatesAndPvzGroups.map((item) => {
|
|
|
|
|
item.groups.map((groupItem) => {
|
|
|
|
|
res.push({name: groupItem.id, url: groupItem.image})
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
return [...res, ...icons];
|
|
|
|
|
}, [icons, postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
const mapLayersIds = useMemo(() => {
|
|
|
|
|
if (!postamatesAndPvzGroups) return [];
|
|
|
|
|
const res = []
|
|
|
|
|
postamatesAndPvzGroups.map((item) => {
|
|
|
|
|
item.groups.map((groupItem) => {
|
|
|
|
|
res.push(LAYER_IDS.pvz + groupItem.id);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
}, [postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setLayersVisibility(MODE_TO_LAYER_VISIBILITY_MAPPER[mode]);
|
|
|
|
|
setPopup(null);
|
|
|
|
|
@ -132,21 +157,22 @@ export const MapComponent = () => {
|
|
|
|
|
LAYER_IDS.working,
|
|
|
|
|
LAYER_IDS.filteredWorking,
|
|
|
|
|
LAYER_IDS.cancelled,
|
|
|
|
|
LAYER_IDS.pvz,
|
|
|
|
|
...mapLayersIds,
|
|
|
|
|
LAYER_IDS.other,
|
|
|
|
|
]}
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
onMouseEnter={handleMouseEnter}
|
|
|
|
|
onMouseLeave={handleMouseLeave}
|
|
|
|
|
onLoad={() => {
|
|
|
|
|
icons.map((icon) => {
|
|
|
|
|
mapIcons.map((icon) => {
|
|
|
|
|
const img = new Image(
|
|
|
|
|
icon.size?.width || 24,
|
|
|
|
|
icon.size?.height || 24
|
|
|
|
|
);
|
|
|
|
|
img.onload = () =>
|
|
|
|
|
mapRef.current.addImage(icon.name, img, { sdf: true });
|
|
|
|
|
mapRef.current.addImage(icon.name, img);
|
|
|
|
|
img.src = icon.url;
|
|
|
|
|
img.crossOrigin = "Anonymous";
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
id="map"
|
|
|
|
|
@ -166,12 +192,12 @@ export const MapComponent = () => {
|
|
|
|
|
<SidebarControl toggleCollapse={toggleCollapseSidebar} />
|
|
|
|
|
|
|
|
|
|
<Basemap />
|
|
|
|
|
<Layers />
|
|
|
|
|
<Layers postGroups={postamatesAndPvzGroups} />
|
|
|
|
|
|
|
|
|
|
<Legend />
|
|
|
|
|
<LastMLRun />
|
|
|
|
|
<SignOut />
|
|
|
|
|
<LayersControl />
|
|
|
|
|
<LayersControl postGroups={postamatesAndPvzGroups} />
|
|
|
|
|
</Map>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-full border-solid border-border border-0 border-t-[1px] z-20">
|
|
|
|
|
|