From b4d75c3917bab54f677dab0570ff028c0609a99a Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Wed, 21 Jan 2026 15:40:04 +0800
Subject: [PATCH] feat: flyVisual
---
applications/drone-command/src/utils/cesium/mapUtil.js | 61 ------------------------------
1 files changed, 0 insertions(+), 61 deletions(-)
diff --git a/applications/drone-command/src/utils/cesium/mapUtil.js b/applications/drone-command/src/utils/cesium/mapUtil.js
index 89bf787..767f5b0 100644
--- a/applications/drone-command/src/utils/cesium/mapUtil.js
+++ b/applications/drone-command/src/utils/cesium/mapUtil.js
@@ -449,67 +449,6 @@
}
}
-/**
- * 飞到中心点并且所有点在可视范围
- * @param positionsData 二维数组,每项为 [lon, lat] 或 三维数组 [lon, lat, height]
- * @param viewer Cesium.Viewer 实例
- * @param multiple 缩放倍数-默认为4
- * @param pitch 俯仰角-默认为-90
- */
-export function flyVisual({ positionsData, viewer, multiple = 4, pitch = -90 }) {
- if (!Array.isArray(positionsData) || positionsData.length === 0) return
-
- // 如果是一个点,加两个点方便后续生成外包围盒
- if (positionsData.length === 1) {
- const [lon, lat, height = 0] = positionsData[0]
- positionsData = [
- [lon + 0.001, lat + 0.001, height],
- [lon - 0.001, lat - 0.001, height],
- [lon, lat, height],
- ]
- }
- const positions = positionsData.map(([lon, lat, height = 0]) =>
- Cesium.Cartesian3.fromDegrees(Number(lon), Number(lat), Number(height || 0))
- )
-
- // 计算最高高度和中心点经纬度
- let maxHeight = -Infinity
- let sumLon = 0,
- sumLat = 0
- for (const [lon, lat, height] of positionsData) {
- sumLon += Number(lon)
- sumLat += Number(lat)
- maxHeight = Math.max(maxHeight, Number(height || 0))
- }
- const centerLon = sumLon / positionsData.length
- const centerLat = sumLat / positionsData.length
- const boundingSphere = Cesium.BoundingSphere.fromPoints(positions)
- // 暂时飞向 BoundingSphere
- viewer.camera.flyToBoundingSphere(Cesium.BoundingSphere.fromPoints(positions), {
- duration: 0,
- offset: {
- heading: Cesium.Math.toRadians(0),
- pitch: Cesium.Math.toRadians(pitch),
- range: boundingSphere.radius * multiple,
- },
- complete: () => {
- // 飞行完成后检查相机高度是否小于最高点
- const cameraHeight = Cesium.Cartographic.fromCartesian(viewer.camera.position).height
- if (cameraHeight < maxHeight) {
- viewer.camera.flyTo({
- destination: Cesium.Cartesian3.fromDegrees(centerLon, centerLat, maxHeight + 100), // 加100米缓冲
- duration: 1.5,
- orientation: {
- heading: viewer.camera.heading,
- pitch: viewer.camera.pitch,
- roll: viewer.camera.roll,
- },
- })
- }
- },
- })
-}
-
// 获取视口地图中心点
export function getMapCenterPoint(viewer) {
const centerResult = viewer.camera.pickEllipsoid(
--
Gitblit v1.9.3