From 792403d97b0b0e06b9faba5c18c4886bf9f7586b Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Wed, 21 Jan 2026 15:48:47 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 packages/utils/map/index.js |   75 +++++++++++++++++++++++++++++++------
 1 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/packages/utils/map/index.js b/packages/utils/map/index.js
index fa9ec9a..b2bee02 100644
--- a/packages/utils/map/index.js
+++ b/packages/utils/map/index.js
@@ -1,16 +1,4 @@
-/*
- * @Author       : yuan
- * @Date         : 2025-12-26 11:01:31
- * @LastEditors  : yuan
- * @LastEditTime : 2025-12-31 16:00:54
- * @FilePath     : \packages\utils\map\index.js
- * @Description  : 
- * Copyright 2025 OBKoro1, All Rights Reserved. 
- * 2025-12-26 11:01:31
- */
-
 import * as Cesium from 'cesium'
-
 
 // 获取正射影像4至点
 export function getOrthoImageBoundaryPoints (data) {
@@ -29,4 +17,65 @@
 		east,
 		north
 	)
-}
\ No newline at end of file
+}
+
+/**
+ * 飞到中心点并且所有点在可视范围
+ *  @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,
+					},
+				})
+			}
+		},
+	})
+}

--
Gitblit v1.9.3