'use client' import React, {useEffect, useRef, useState} from 'react'; import deom1 from "../assets/deom1.png"; import deom2 from "../assets/deom2.png"; import Uptow from "../assets/up-two.png"; import markerData from "../assets/markerData.json"; import fameng from "../assets/fameng.png"; import shuifa from "../assets/shuifa.png"; import dataJson from "../assets/index.json"; import "../assets/BaiduMapPage.css"; import {Badge, Card, Col, Modal, Row,} from "antd" // 添加图标导入 import {CheckCircleOutlined, CloseCircleOutlined, ExclamationCircleOutlined, WifiOutlined} from '@ant-design/icons'; import RTMMPicEcharts from "@/components/realTimeMontorModule/RTMMPicEcharts"; import RTMMBarChart from "@/components/realTimeMontorModule/RTMMBarchart"; import Image from "next/image"; // ... 其余代码保持不变 ... // 仅在浏览器环境中声明 window 类型 declare global { interface Window { BMapGL: any; initMap: () => void; } } function GisMapBaidu(props: { height: string }) { const mapRef = useRef(null); const [map, setMap] = useState(null); const [isClient, setIsClient] = useState(false); // 设备列表状态 const [popupFrameVisible, setPopupFrameVisible] = useState(false); const [manholeCoverData, setManholeCoverData] = useState(null); // 标记是否在浏览器环境 useEffect(() => { setIsClient(true); }, []); // 初始化地图 useEffect(() => { if (!isClient || !mapRef.current) return; // 检查是否已加载百度地图 GL JS API if (!window.BMapGL) { // 动态加载百度地图 GL JS API const script = document.createElement('script'); script.src = `https://api.map.baidu.com/api?v=2.0&ak=jWDCUpsk33htQsF6IEwk4ctkERTOFFH0&type=webgl`; script.async = true; script.onload = () => { initializeMap(); }; document.head.appendChild(script); } else { initializeMap(); } return () => { // 清理工作 if (map && map.destroy) { map.destroy(); } }; }, [isClient]); const initializeMap = () => { if (!window.BMapGL || !mapRef.current) return; // 创建地图实例 const mapInstance = new window.BMapGL.Map(mapRef.current); // 设置中心点坐标 const point = new window.BMapGL.Point(110.39573035064166, 28.44628067667752); mapInstance.centerAndZoom(point, 16); // 启用滚轮放大缩小 mapInstance.enableScrollWheelZoom(true); // 设置初始倾斜角度为30度(范围:0-45度) mapInstance.setTilt(45); // 添加控件 mapInstance.setMinZoom(16); mapInstance.setMaxZoom(19); mapInstance.setMapStyleV2({ styleId: '62ce43ad2a1362c23e612b783d7406e7' }); // 添加标记点 if (markerData?.list?.dataOne) { markerData.list.dataOne.forEach((item: any) => { const icon = new window.BMapGL.Icon(fameng.src, new window.BMapGL.Size(23, 25), { anchor: new window.BMapGL.Size(10, 25), }); const markers = new window.BMapGL.Point(item.lng, item.lat); const marker = new window.BMapGL.Marker(markers, {icon}); mapInstance.addOverlay(marker); // 创建信息窗口 const opts = { width: 300, title: item.name }; const infoWindow = new window.BMapGL.InfoWindow( "倾斜角度:188deg
" + "状态:正常运行
" + "信噪比:16db
" + "负责人:张三
" + "联系方式:121234564", opts ); marker.addEventListener('click', () => { mapInstance.openInfoWindow(infoWindow, markers); console.log('点击了标记点', item); // 添加显示弹窗的逻辑 setManholeCoverData(item); setPopupFrameVisible(true); }); }); } if (markerData?.list?.dataTwo) { markerData.list.dataTwo.forEach((item: any) => { const icon = new window.BMapGL.Icon(shuifa.src, new window.BMapGL.Size(23, 25), { anchor: new window.BMapGL.Size(20, 0), }); const markers = new window.BMapGL.Point(item.lng, item.lat); const marker = new window.BMapGL.Marker(markers, {icon}); mapInstance.addOverlay(marker); // 创建信息窗口 const opts = { width: 300, title: item.name }; // const infoWindow = new window.BMapGL.InfoWindow( // "倾斜角度:188deg
" + // "状态:正常运行
" + // "信噪比:16db
" + // "负责人:张三
" + // "联系方式:121234564", opts // ); marker.addEventListener('click', () => { // mapInstance.openInfoWindow(infoWindow, markers); setManholeCoverData({ ...item, neme:item.name, itemCode:'12312442222', type: '供水井盖', state:'1', worker:'东三社区', miaoshu:'检测到倾斜角度异常', time:'2023-08-01 10:00:00', temperature:'25',//温度 humidity:'50',//湿度 flow:'100',//流量 flowSpeed:'2',//流速 waterLevel:'100',//水位 waterQuality:'100',//水质 PHValue:'7.0',//PH值 rongjieyang:'100',//融结氧 ammoniaNitrogen:'100',//氨氮 }); // 添加显示弹窗的逻辑 setPopupFrameVisible(true); }); }); } // 添加线路图层 if (window.BMapGL.LineLayer && dataJson) { const lineLayer = new window.BMapGL.LineLayer({ enablePicked: true, autoSelect: true, pickWidth: 30, pickHeight: 30, opacity: 1, selectedColor: 'blue', style: { sequence: false, marginLength: 18, borderMask: true, strokeWeight: 10, strokeLineJoin: 'round', strokeLineCap: 'round', strokeTextureUrl: ['match', ['get', 'name'], 'demo1', deom1.src, 'demo2', deom2.src, Uptow.src], } }); lineLayer.setData(dataJson); mapInstance.addNormalLayer(lineLayer); } setMap(mapInstance); // 添加点击地图事件 mapInstance.addEventListener('click', (e: any) => { console.log('点击位置经纬度:', e.latlng?.lng, e.latlng?.lat); }); }; if (!isClient) { return (
地图加载中...
); } // 合并return语句,修复Modal无法显示的问题 return ( <>
{/* 添加左侧三个板块区域 */}
{/* 板块1 */}
{/* 板块2 */}
{/* 修改为2行2列的四宫格布局 */} {/* 正常运行状态卡片 */}
{/* 左侧图标 */}
{/* 右侧文字和数值 */}
正常运行
12
{/* 需要注意状态卡片 */}
需要注意
3
{/* 异常状态卡片 */}
异常状态
1
{/* 离线类型卡片 */}
离线类型
2
{/* 板块3 */}
{/* 地图容器区域 */}
setPopupFrameVisible(false)} width={800} className="custom-modal" // 添加mask={false}移除遮罩层 mask={false} // 定位样式保持不变 style={{ position: 'absolute', right: 0, top: 150, textAlign: 'center', }} > {manholeCoverData && (
设备名称: {manholeCoverData.name}
设备编号: {manholeCoverData.itemCode}
设备类型: {manholeCoverData.type}
状态: {manholeCoverData.state === "1" ? "正常" : "异常"} } />
权属单位: {manholeCoverData.worker}
监测描述: {manholeCoverData.miaoshu}
窨井下监测信息
温度: {manholeCoverData.temperature}
湿度: {manholeCoverData.humidity}
流量: {manholeCoverData.flow}
水位: {manholeCoverData.waterLevel}
流速: {manholeCoverData.flowSpeed}
水质: {manholeCoverData.waterQuality}
PH值: {manholeCoverData.PHValue}
氨氮: {manholeCoverData.ammoniaNitrogen}
{'测试图片'}
)}
{/* 添加全局样式覆盖表头背景色 */} ); } export default GisMapBaidu;