zcloud-gbs-bi-react/src/pages/Container/Map/index.js

114 lines
4.2 KiB
JavaScript
Raw Normal View History

2026-01-05 14:53:49 +08:00
import { useFullscreen, useMount } from "ahooks";
import { message } from "antd";
import autoFit from "autofit.js";
2026-01-15 18:01:40 +08:00
import { useMemo, useRef, useState } from "react";
2026-01-05 14:53:49 +08:00
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
import BottomUtils from "./components/BottomUtils";
import CenterUtils from "./components/CenterUtils";
import Content from "./components/Content";
import Header from "./components/Header";
import RightUtils from "./components/RightUtils";
import { Context } from "./js/context";
import InitMap from "./js/initMap";
import mitt from "./js/mitt";
2026-01-07 13:51:33 +08:00
import {
changeCoverMaskVisibleMittKey,
clickBranchOfficePointMittKey,
clickPortPointMittKey,
} from "./js/mittKey";
2026-01-05 14:53:49 +08:00
import "./index.less";
2026-01-16 17:18:09 +08:00
function Map(props) {
2026-01-05 14:53:49 +08:00
const query = useGetUrlQuery();
const viewer = useRef(null); // cesium地图实例
const mapMethods = useRef(null); // cesium地图方法实例
const fullscreenRef = useRef(null); // 全屏容器的ref
const [isFullscreen, { toggleFullscreen }] = useFullscreen(fullscreenRef);
const [coverMaskVisible, setCoverMaskVisible] = useState(false); // 是否显示透明遮罩,用于分片加载点位时阻止点击事件
const [currentPort, setCurrentPort] = useState(""); // 当前选中的港口
const [currentBranchOffice, setCurrentBranchOffice] = useState(""); // 当前选中的分公司
const [area, setArea] = useState(""); // 当前选中的港口为秦皇岛港时的区域
const [bottomUtilsCurrentIndex, setBottomUtilsCurrentIndex] = useState(""); // 当前选中的下方按钮的索引
const [pureMap, setPureMap] = useState(false); // 是否选中了右侧的纯净地图
2026-01-07 16:38:01 +08:00
const [headerTitle, setHeaderTitle] = useState("秦港股份安全监管平台"); // 当前头部的标题
2026-01-05 14:53:49 +08:00
useMount(() => {
autoFit.init({ dw: 1920, dh: 1080, el: "#contentContainer", resize: true });
2026-01-07 16:38:01 +08:00
sessionStorage.removeItem("mapCurrentBranchOfficeId");
2026-01-05 14:53:49 +08:00
const initMap = new InitMap();
const { viewer: viewerInstance, mapMethods: mapMethodsInstance }
= initMap.initMap();
viewer.current = viewerInstance;
mapMethods.current = mapMethodsInstance;
if (query.mapType === "港口") {
initMap.externalEntryPort(query);
}
else {
2026-01-15 18:01:40 +08:00
setTimeout(() => {
mapMethodsInstance.flyTo();
mapMethodsInstance.addPortPoint();
}, 500);
2026-01-05 14:53:49 +08:00
}
mitt.on(clickPortPointMittKey, (data) => {
setCurrentPort(data.id);
2026-01-07 16:38:01 +08:00
if (data.id === "00003") {
setHeaderTitle("秦港股份安全监管平台");
}
else {
2026-01-05 14:53:49 +08:00
setCurrentBranchOffice(data.corpinfoId);
2026-01-07 16:38:01 +08:00
setHeaderTitle(`${data.name}安全监管平台`);
}
2026-01-05 14:53:49 +08:00
});
mitt.on(clickBranchOfficePointMittKey, (data) => {
setCurrentBranchOffice(data.id);
2026-01-07 16:38:01 +08:00
setHeaderTitle(`${data.corpName || data.name}安全监管平台`);
2026-01-05 14:53:49 +08:00
});
mitt.on(changeCoverMaskVisibleMittKey, (data) => {
setCoverMaskVisible(data);
if (!data) {
2026-01-07 13:51:33 +08:00
message.success("地图绘制完成");
2026-01-05 14:53:49 +08:00
}
});
return () => {
autoFit.off();
mitt.off(clickPortPointMittKey);
mitt.off(clickBranchOfficePointMittKey);
mitt.off(changeCoverMaskVisibleMittKey);
};
});
const providerValues = useMemo(
() => ({ viewer, mapMethods, currentPort, currentBranchOffice, area, bottomUtilsCurrentIndex, pureMap }),
[viewer, mapMethods, currentPort, currentBranchOffice, area, bottomUtilsCurrentIndex, pureMap],
);
return (
<div ref={fullscreenRef}>
<Context.Provider value={providerValues}>
<div id="cesiumContainer" />
<div id="contentContainer">
2026-01-07 16:38:01 +08:00
<Header headerTitle={headerTitle} />
2026-01-05 14:53:49 +08:00
<CenterUtils setArea={setArea} />
<RightUtils isFullscreen={isFullscreen} toggleFullscreen={toggleFullscreen} setPureMap={setPureMap} />
<BottomUtils setBottomUtilsCurrentIndex={setBottomUtilsCurrentIndex} />
2026-01-16 17:18:09 +08:00
<Content history={props.history} />
2026-01-05 14:53:49 +08:00
</div>
</Context.Provider>
<div
style={{ display: coverMaskVisible ? "block" : "none" }}
className="coverMaskContainer"
2026-01-07 13:51:33 +08:00
onClick={() => message.warning("正在绘制地图,请等待绘制完成在进行操作")}
2026-01-05 14:53:49 +08:00
/>
</div>
);
}
export default Map;