From 47cd30da5cd5b27ac1ccf9507e2a80699e623af3 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Wed, 17 Jun 2026 21:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E7=AB=99=E6=A6=82=E8=A7=88=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E5=AE=9A=E4=BD=8D=E5=88=B0=20=E9=BE=99=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Map.jsx | 48 +++++++++++++------ src/components/devices/DeviceOverviewPage.tsx | 1 - src/pages/Home.tsx | 8 +++- src/pages/RealTimeMonitor.tsx | 9 +++- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/components/Map.jsx b/src/components/Map.jsx index 95c2770..a37e4a6 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -401,7 +401,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, } function displayPublishedLayers(publishedLayers, baseUrl) { - console.log('已发布的图层:', publishedLayers) + //console.log('已发布的图层:', publishedLayers) publishedLayers.forEach((layer, index) => { const [workspace, layerName] = layer.name.split(':'); if (workspace && layerName) { @@ -490,9 +490,9 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const layerIdentifier = `${workspace}:${layerName}`; let baseUrl = wmsUrl; const cesiumLayers = []; - //if (index == 2) { - // flyToLayer(layerIdentifier, baseUrl); - //} + if (index == 2) { + flyToLayer(layerIdentifier, baseUrl, 100); + } //getLayerBoundsAndFit(wmsUrl, layerName); if (baseUrl.includes('/gwc/service/wms')) { @@ -597,10 +597,8 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, } } - function flyToLayer(layerIdentifier, baseUrl) { - console.log('定位到图层范围:', layerIdentifier); - if (!viewerRef.current) return; - + function flyToLayer(layerIdentifier, baseUrl, flyHeight = 1000) { + //console.log('开始获取图层范围', layerIdentifier); const url = `${baseUrl}/wms?service=WMS&version=1.1.1&request=GetCapabilities`; fetch(url) @@ -608,6 +606,7 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, .then(xmlText => { const xml = new DOMParser().parseFromString(xmlText, 'text/xml'); const layerElements = xml.getElementsByTagName('Layer'); + let targetBbox = null; for (let i = 0; i < layerElements.length; i++) { const layer = layerElements[i]; @@ -620,16 +619,36 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, const miny = parseFloat(bboxElement.getAttribute('miny')); const maxx = parseFloat(bboxElement.getAttribute('maxx')); const maxy = parseFloat(bboxElement.getAttribute('maxy')); - - const rectangle = window.Cesium.Rectangle.fromDegrees(minx, miny, maxx, maxy); - viewerRef.current.camera.flyTo({ - destination: rectangle, - duration: 2 - }); + targetBbox = [minx, miny, maxx, maxy]; + console.log('读取到图层bbox', targetBbox); } break; } } + + if (!targetBbox) { + console.warn('该图层未找到BoundingBox,无法飞行', layerIdentifier); + return; + } + + const [minx, miny, maxx, maxy] = targetBbox; + // 取图层中心点 + const centerLon = (minx + maxx) / 2; + const centerLat = (miny + maxy) / 2; + + viewerRef.current.camera.flyTo({ + // 固定高度,第三个参数就是高度(单位米) + destination: window.Cesium.Cartesian3.fromDegrees(centerLon, centerLat, flyHeight), + orientation: { + heading: 0, + pitch: window.Cesium.Math.toRadians(-90), // 垂直俯视 + roll: 0 + }, + duration: 2 + }); + }) + .catch(err => { + console.error('获取WMS Capabilities失败', err); }); } @@ -998,7 +1017,6 @@ const CesiumMap = React.forwardRef(({ ifClear, ifClearPlanLine, ifClearNavLine, viewer.scene.requestRender(); return; } - console.log(tracePoints, tracePointRef.current.getMode(), "mode1111111111"); const validPoints = tracePoints.filter(p => { const lng = Number(p.lng); diff --git a/src/components/devices/DeviceOverviewPage.tsx b/src/components/devices/DeviceOverviewPage.tsx index 3464966..b0c32ec 100644 --- a/src/components/devices/DeviceOverviewPage.tsx +++ b/src/components/devices/DeviceOverviewPage.tsx @@ -266,7 +266,6 @@ export default function DeviceOverviewPage({ onViewStatus, selectedSn, onDeviceS ...persistentDroneData, }; }, [selectedDevice, uavState, persistentHostData, persistentDroneData?.wind_speed]); - console.log('实时设备数据:', realtimeDevice); // MQTT消息处理 const handleMqttMessage = (topic, message) => { diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index d1fbc25..e0d9484 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -15,6 +15,7 @@ import { RobotOutlined } from '@ant-design/icons'; import { Line, Bar, Pie } from '@ant-design/charts'; +import CesiumMap from '../components/Map'; import { getWeatherData, getWeatherType } from '../lib/utils'; import WeatherDisplay from '../components/Weather'; import bgMain from '../assets/images/bgmain.jpg'; @@ -335,13 +336,16 @@ export default function StationDashboard() { bodyStyle={{ padding: 0, position: 'relative', overflow: 'hidden', height: 500 }} >