99 lines
3.7 KiB
JavaScript
99 lines
3.7 KiB
JavaScript
|
|
import { useFullscreen, useMount } from "ahooks";
|
||
|
|
import { message } from "antd";
|
||
|
|
import autoFit from "autofit.js";
|
||
|
|
import { useMemo, useRef, useState } from "react";
|
||
|
|
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";
|
||
|
|
import { changeCoverMaskVisibleMittKey, clickBranchOfficePointMittKey, clickPortPointMittKey } from "./js/mittKey";
|
||
|
|
import "./index.less";
|
||
|
|
|
||
|
|
function Map() {
|
||
|
|
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); // 是否选中了右侧的纯净地图
|
||
|
|
|
||
|
|
useMount(() => {
|
||
|
|
autoFit.init({ dw: 1920, dh: 1080, el: "#contentContainer", resize: true });
|
||
|
|
|
||
|
|
const initMap = new InitMap();
|
||
|
|
const { viewer: viewerInstance, mapMethods: mapMethodsInstance }
|
||
|
|
= initMap.initMap();
|
||
|
|
viewer.current = viewerInstance;
|
||
|
|
mapMethods.current = mapMethodsInstance;
|
||
|
|
|
||
|
|
if (query.mapType === "港口") {
|
||
|
|
initMap.externalEntryPort(query);
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
mapMethodsInstance.flyTo();
|
||
|
|
mapMethodsInstance.addPortPoint();
|
||
|
|
}
|
||
|
|
|
||
|
|
mitt.on(clickPortPointMittKey, (data) => {
|
||
|
|
setCurrentPort(data.id);
|
||
|
|
if (data.id !== "00003")
|
||
|
|
setCurrentBranchOffice(data.corpinfoId);
|
||
|
|
});
|
||
|
|
mitt.on(clickBranchOfficePointMittKey, (data) => {
|
||
|
|
setCurrentBranchOffice(data.id);
|
||
|
|
});
|
||
|
|
mitt.on(changeCoverMaskVisibleMittKey, (data) => {
|
||
|
|
setCoverMaskVisible(data);
|
||
|
|
if (!data) {
|
||
|
|
message.success("点位标注完成");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
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">
|
||
|
|
<Header />
|
||
|
|
<CenterUtils setArea={setArea} />
|
||
|
|
<RightUtils isFullscreen={isFullscreen} toggleFullscreen={toggleFullscreen} setPureMap={setPureMap} />
|
||
|
|
<BottomUtils setBottomUtilsCurrentIndex={setBottomUtilsCurrentIndex} />
|
||
|
|
<Content />
|
||
|
|
</div>
|
||
|
|
</Context.Provider>
|
||
|
|
<div
|
||
|
|
style={{ display: coverMaskVisible ? "block" : "none" }}
|
||
|
|
className="coverMaskContainer"
|
||
|
|
onClick={() => message.warning("正在标注点位,请等待标注完成在进行操作")}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
export default Map;
|