You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
1 year ago
|
/*
|
||
|
* @Author: cbwu 504-wuchengbo@htsdfp.com
|
||
|
* @Date: 2024-03-22 09:11:54
|
||
|
* @LastEditors: cbwu
|
||
|
* @LastEditTime: 2024-03-26 13:33:42
|
||
|
* @Description: 坐标系转化
|
||
|
*/
|
||
|
import { Cartesian2, Viewer, Math, Cartographic } from 'cesium'
|
||
|
/**
|
||
|
* 屏幕坐标转笛卡尔坐标
|
||
|
* @param viewer
|
||
|
* @param windowPosition :屏幕二维坐标
|
||
|
* @returns :笛卡尔坐标
|
||
|
*/
|
||
|
function cartesian2ToCartesian3(viewer: Viewer, windowPosition: Cartesian2) {
|
||
|
const ray = viewer.camera.getPickRay(windowPosition)
|
||
|
if (ray != undefined) {
|
||
|
return viewer.scene.globe.pick(ray, viewer.scene)
|
||
|
} else return undefined
|
||
|
}
|
||
|
/**
|
||
|
* 屏幕坐标转地理坐标
|
||
|
* @param viewer
|
||
|
* @param windowPosition :屏幕坐标
|
||
|
* @returns :WGS84坐标
|
||
|
*/
|
||
|
function cartesian2ToWGS84(viewer: Viewer, windowPosition: Cartesian2) {
|
||
|
const cartesian3 = cartesian2ToCartesian3(viewer, windowPosition)
|
||
|
if (cartesian3 != undefined) {
|
||
|
const cartographic = Cartographic.fromCartesian(cartesian3)
|
||
|
const lon = Math.toDegrees(cartographic.longitude) // 经度
|
||
|
const lat = Math.toDegrees(cartographic.latitude) // 纬度
|
||
|
const alt = cartographic.height // 高度
|
||
|
return [lon, lat, alt]
|
||
|
} else return []
|
||
|
}
|
||
|
export { cartesian2ToCartesian3, cartesian2ToWGS84 }
|