import { useFullscreen, useMount } from "ahooks"; import { message } from "antd"; import autoFit from "autofit.js"; import { useEffect, 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 useInitMap from "./js/initMap"; import mitt from "./js/mitt"; import { changeCoverMaskVisibleMittKey, clickBranchOfficePointMittKey, clickPortPointMittKey, } from "./js/mittKey"; import "./index.less"; function Map(props) { const query = useGetUrlQuery(); const { viewer, mapMethods, initMap, externalEntryPort } = useInitMap(); 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); // 是否选中了右侧的纯净地图 const [headerTitle, setHeaderTitle] = useState("秦港股份安全监管平台"); // 当前头部的标题 useMount(() => { autoFit.init({ dw: 1920, dh: 1080, el: "#contentContainer", resize: true }); sessionStorage.removeItem("mapCurrentBranchOfficeId"); initMap(); if (query.mapType === "港口") { const entered = externalEntryPort(query); if (!entered) message.warning("港口入口参数不完整,无法定位到对应港口"); } else { setTimeout(() => { mapMethods.current.flyTo(); mapMethods.current.addPortPoint(); }, 500); } mitt.on(clickPortPointMittKey, (data) => { setCurrentPort(data.id); if (data.id === "00003") { setHeaderTitle("秦港股份安全监管平台"); } else { setCurrentBranchOffice(data.corpinfoId); setHeaderTitle(`${data.name}安全监管平台`); } }); mitt.on(clickBranchOfficePointMittKey, (data) => { setCurrentBranchOffice(data.id); setHeaderTitle(`${data.corpName || data.name}安全监管平台`); }); mitt.on(changeCoverMaskVisibleMittKey, (data) => { setCoverMaskVisible(data); if (!data) { message.success("地图绘制完成"); } }); return () => { autoFit.off(); mitt.off(clickPortPointMittKey); mitt.off(clickBranchOfficePointMittKey); mitt.off(changeCoverMaskVisibleMittKey); }; }); useEffect(() => { query.accessTicket && window.sessionStorage.setItem("accessTicket", query.accessTicket); query.clientId && window.sessionStorage.setItem("clientId", query.clientId); query.orgId && window.sessionStorage.setItem("orgId", query.orgId); query.token && window.sessionStorage.setItem("token", query.token); }, []); const providerValues = useMemo( () => ({ viewer, mapMethods, currentPort, currentBranchOffice, area, bottomUtilsCurrentIndex, pureMap }), [viewer, mapMethods, currentPort, currentBranchOffice, area, bottomUtilsCurrentIndex, pureMap], ); return (