当前位置:网站首页>Cesium 点击获取经纬度(二维坐标)
Cesium 点击获取经纬度(二维坐标)
2022-06-28 00:06:00 【最凶残的小海豹】
下面代码适用于 二维坐标
,获取椭球体表面的经纬度坐标。
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(event => {
// 屏幕坐标转为空间坐标
let cartesian = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid);
if (cartesian == undefined) {
console.log('没有获取到坐标')
} else {
// 空间坐标转世界坐标(弧度)
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
// 弧度转为角度(经纬度)
let lon = Cesium.Math.toDegrees(cartographic.longitude); // 经度值
let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度值
console.log('经纬度是:', {
x: lon, y: lat });
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
取消左键点击事件
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
注意: pickEllipsoid
在加载地形的情况下有一定误差,地形凹凸程度越大,误差越大,所以上述方面只能用于 二维坐标
的获取。
三维坐标请看我的另一篇文章
边栏推荐
猜你喜欢
基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
fiddle如何使用代理
TIA botu_ Concrete method of making analog input and output Global Library Based on SCL language
766. toplitz matrix
Intranet penetration with FRP
评价——秩和比综合评价
The number of nodes of a complete binary tree [non-O (n) solution > Abstract dichotomy]
评价——灰色关联分析
万字长文看懂商业智能(BI)|推荐收藏
随机推荐
Intensive reading of transformer thesis paragraph by paragraph
Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
想开户买股票,在网上办理股票开户安全吗?
[Yocto RM] 4 - Source Directory Structure
【sylixos】NEW_1 型字符驱动示例
力扣今日题-522. 最长特殊序列
数据库的新选择 Amazon Aurora
Evaluation - grey correlation analysis
Supervised, unsupervised and semi supervised learning
[Yocto RM]8 - OpenEmbedded Kickstart (.wks) Reference
评价——灰色关联分析
如何理解 Transformer 中的 Query、Key 与 Value
网络爬虫是什么
Capacitor
Ten MySQL locks, one article will give you full analysis
Arrays.asList()坑
The number of nodes of a complete binary tree [non-O (n) solution > Abstract dichotomy]
frp实现内网穿透
Web3 technology initial experience and related learning materials
[embedded foundation] serial port communication