电站概览地图定位到 龙源

This commit is contained in:
mmc
2026-06-17 21:05:35 +08:00
parent ec4005c1f8
commit 47cd30da5c
4 changed files with 46 additions and 20 deletions

View File

@@ -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);