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