|  |  |  | @ -2,17 +2,12 @@ | 
		
	
		
			
				|  |  |  |  |  * @Author: cbwu 504-wuchengbo@htsdfp.com | 
		
	
		
			
				|  |  |  |  |  * @Date: 2024-03-22 15:42:49 | 
		
	
		
			
				|  |  |  |  |  * @LastEditors: cbwu | 
		
	
		
			
				|  |  |  |  |  * @LastEditTime: 2024-04-13 10:49:17 | 
		
	
		
			
				|  |  |  |  |  * @LastEditTime: 2024-04-01 14:05:43 | 
		
	
		
			
				|  |  |  |  |  * @Description: 地理计算 | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | import { | 
		
	
		
			
				|  |  |  |  |   Cartesian3, | 
		
	
		
			
				|  |  |  |  |   Cartographic, | 
		
	
		
			
				|  |  |  |  |   EllipsoidGeodesic, | 
		
	
		
			
				|  |  |  |  |   Math as Cesium_Math, | 
		
	
		
			
				|  |  |  |  |   Matrix4, | 
		
	
		
			
				|  |  |  |  |   Transforms, | 
		
	
		
			
				|  |  |  |  | } from 'cesium' | 
		
	
		
			
				|  |  |  |  | import {Cartesian3, Cartographic, EllipsoidGeodesic, Math as Cesium_Math, Matrix4, Transforms, Viewer} from 'cesium' | 
		
	
		
			
				|  |  |  |  | import {Angle} from "@/utils/map/angle.ts"; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * 计算空间中一点到一条直线的最短距离的交点(在不考虑地球曲率的情况下) | 
		
	
		
			
				|  |  |  |  |  * @param lineStart 直线的起点:[longitude1, latitude1, height1] | 
		
	
	
		
			
				
					|  |  |  | @ -91,50 +86,42 @@ function isOnLineSegment( | 
		
	
		
			
				|  |  |  |  |   */ | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * 计算距离,单位米 | 
		
	
		
			
				|  |  |  |  |  * @param p1 起点 | 
		
	
		
			
				|  |  |  |  |  * @param p2 终点 | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | function getDistance(p1: Cartesian3, p2: Cartesian3): number { | 
		
	
		
			
				|  |  |  |  |   let point1cartographic = Cartographic.fromCartesian(p1) | 
		
	
		
			
				|  |  |  |  |   let point2cartographic = Cartographic.fromCartesian(p2) | 
		
	
		
			
				|  |  |  |  | function getDistance(p1:Cartesian3, p2: Cartesian3): number | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |   let point1cartographic = Cartographic.fromCartesian(p1); | 
		
	
		
			
				|  |  |  |  |   let point2cartographic = Cartographic.fromCartesian(p2); | 
		
	
		
			
				|  |  |  |  |   /**根据经纬度计算出距离**/ | 
		
	
		
			
				|  |  |  |  |   let geodesic = new EllipsoidGeodesic() | 
		
	
		
			
				|  |  |  |  |   geodesic.setEndPoints(point1cartographic, point2cartographic) | 
		
	
		
			
				|  |  |  |  |   return geodesic.surfaceDistance / 1000 | 
		
	
		
			
				|  |  |  |  |   return geodesic.surfaceDistance/1000 | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * 计算方位角,单位度 | 
		
	
		
			
				|  |  |  |  |  * @param p1 起点 | 
		
	
		
			
				|  |  |  |  |  * @param p2 终点 | 
		
	
		
			
				|  |  |  |  |  * @param digits 保留小数位数,默认为保留1位小数 | 
		
	
		
			
				|  |  |  |  |  * @param digits 保留小数位数,默认保留1位小数 | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | function getAzimuth(p1: Cartesian3, p2: Cartesian3, digits = 1): string { | 
		
	
		
			
				|  |  |  |  | function getAzimuth(p1:Cartesian3, p2: Cartesian3, digits=1): string | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |   // 建立局部坐标系:北为y,东为x,p1为原点
 | 
		
	
		
			
				|  |  |  |  |   const localMatrix = Transforms.eastNorthUpToFixedFrame(p1) | 
		
	
		
			
				|  |  |  |  |   //求世界坐标到局部坐标的变换矩阵
 | 
		
	
		
			
				|  |  |  |  |   const worldToLocalMatrix = Matrix4.inverse(localMatrix, new Matrix4()) | 
		
	
		
			
				|  |  |  |  |   //p1在局部坐标系的位置,即局部坐标原点
 | 
		
	
		
			
				|  |  |  |  |   const localPosition1 = Matrix4.multiplyByPoint( | 
		
	
		
			
				|  |  |  |  |     worldToLocalMatrix, | 
		
	
		
			
				|  |  |  |  |     p1, | 
		
	
		
			
				|  |  |  |  |     new Cartesian3(), | 
		
	
		
			
				|  |  |  |  |   ) | 
		
	
		
			
				|  |  |  |  |   const localPosition1 = Matrix4.multiplyByPoint(worldToLocalMatrix, p1, new Cartesian3()) | 
		
	
		
			
				|  |  |  |  |   //p2在局部坐标系的位置
 | 
		
	
		
			
				|  |  |  |  |   const localPosition2 = Matrix4.multiplyByPoint( | 
		
	
		
			
				|  |  |  |  |     worldToLocalMatrix, | 
		
	
		
			
				|  |  |  |  |     p2, | 
		
	
		
			
				|  |  |  |  |     new Cartesian3(), | 
		
	
		
			
				|  |  |  |  |   ) | 
		
	
		
			
				|  |  |  |  |   const localPosition2 = Matrix4.multiplyByPoint(worldToLocalMatrix, p2, new Cartesian3()) | 
		
	
		
			
				|  |  |  |  |   //弧度
 | 
		
	
		
			
				|  |  |  |  |   const angle = Math.atan2( | 
		
	
		
			
				|  |  |  |  |     localPosition2.x - localPosition1.x, | 
		
	
		
			
				|  |  |  |  |     localPosition2.y - localPosition1.y, | 
		
	
		
			
				|  |  |  |  |   ) | 
		
	
		
			
				|  |  |  |  |   const angle = Math.atan2(localPosition2.x - localPosition1.x, localPosition2.y - localPosition1.y) | 
		
	
		
			
				|  |  |  |  |   //转为角度
 | 
		
	
		
			
				|  |  |  |  |   let theta = angle * (180 / Math.PI) | 
		
	
		
			
				|  |  |  |  |   let theta = angle * (180 / Math.PI); | 
		
	
		
			
				|  |  |  |  |   theta = theta < 0 ? theta + 360 : theta | 
		
	
		
			
				|  |  |  |  |   return theta.toFixed(digits) | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | @ -154,10 +141,25 @@ function getPolygonArea(vertexs: Cartesian3[]) { | 
		
	
		
			
				|  |  |  |  |   return Math.abs(area) | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | export { | 
		
	
		
			
				|  |  |  |  |   getClosestPoint, | 
		
	
		
			
				|  |  |  |  |   isOnLineSegment, | 
		
	
		
			
				|  |  |  |  |   getDistance, | 
		
	
		
			
				|  |  |  |  |   getAzimuth, | 
		
	
		
			
				|  |  |  |  |   getPolygonArea, | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * 获取坐标点的海拔高度 | 
		
	
		
			
				|  |  |  |  |  * @param viewer 地图Viewer | 
		
	
		
			
				|  |  |  |  |  * @param pos 坐标点 Cartographic|Cartesian3|[lon,lat] | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | export function getElevation(viewer: Viewer, pos: Cartographic|Cartesian3|number[]){ | 
		
	
		
			
				|  |  |  |  |   let cartographic = undefined | 
		
	
		
			
				|  |  |  |  |   if(pos instanceof Array){ | 
		
	
		
			
				|  |  |  |  |      cartographic = Cartographic.fromDegrees(Angle.degree2rad(pos[0]), Angle.degree2rad(pos[1])) | 
		
	
		
			
				|  |  |  |  |     return viewer.scene.globe.getHeight(cartographic) | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   else if(pos instanceof Cartesian3){ | 
		
	
		
			
				|  |  |  |  |     cartographic = Cartographic.fromCartesian(pos) | 
		
	
		
			
				|  |  |  |  |     return viewer.scene.globe.getHeight(cartographic) | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   else{ | 
		
	
		
			
				|  |  |  |  |     return viewer.scene.globe.getHeight(pos) | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | export { getClosestPoint, isOnLineSegment, getDistance, getAzimuth, getPolygonArea } | 
		
	
	
		
			
				
					|  |  |  | 
 |