当前位置:网站首页>Cesium 点击获三维坐标(经纬度高程)
Cesium 点击获三维坐标(经纬度高程)
2022-07-03 06:03:00 【最凶残的小海豹】
下面代码适用于 获取地形表面的三维坐标。
注意:
- 适用于拾取有地形高程的点
- 不适用于模型、倾斜摄影等表面高度(请看我的另一篇文章)
- 需要开启深度检测
depthTestAgainstTerrain = true。
// 开启深度检测
viewer.scene.globe.depthTestAgainstTerrain = true
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (evt) {
// 返回一个ray和地球表面的一个交点的Cartesian3坐标。
let ray = viewer.camera.getPickRay(evt.position);
let cartesian = viewer.scene.globe.pick(ray, viewer.scene);
// // 空间坐标转世界坐标(弧度)
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
// 弧度转为角度(经纬度)
let lon = Cesium.Math.toDegrees(cartographic.longitude); //经度值
let lat = Cesium.Math.toDegrees(cartographic.latitude); //纬度值
// 地形高度(下面两个二选一就行)
let height = cartographic.height;
let height2 = viewer.scene.globe.getHeight(cartographic)
console.log('经纬度高程是:', {
x: lon, y: lat, height: height, height2: height2 })
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
取消左键点击事件
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)

高程部分:cartographic.height 和 viewer.scene.globe.getHeight(cartographic) 这两个都是高程,可以从上图看出,有一些细微的差别,不过影响不大,用这两个任意一个都可以。
边栏推荐
- [written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
- How does win7 solve the problem that telnet is not an internal or external command
- Alibaba cloud OOS file upload
- Apple submitted the new MAC model to the regulatory database before the spring conference
- 理解 YOLOV1 第一篇 预测阶段
- [teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
- Loss function in pytorch multi classification
- MySQL 5.7.32-winx64 installation tutorial (support installing multiple MySQL services on one host)
- Leetcode problem solving summary, constantly updating!
- Error 1045 (28000) occurs when Linux logs in MySQL: access denied for user 'root' @ 'localhost' (using password: yes)
猜你喜欢

2022.DAY592

pytorch 搭建神经网络最简版

Kubernetes cluster environment construction & Deployment dashboard

项目总结--01(接口的增删改查;多线程的使用)

@Import annotation: four ways to import configuration classes & source code analysis

理解 期望(均值/估计值)和方差
![[teacher Zhao Yuqiang] redis's slow query log](/img/a7/2140744ebad9f1dc0a609254cc618e.jpg)
[teacher Zhao Yuqiang] redis's slow query log

项目总结--2(Jsoup的基本使用)

从小数据量 MySQL 迁移数据到 TiDB

智牛股--03
随机推荐
BeanDefinitionRegistryPostProcessor
[teacher Zhao Yuqiang] RDB persistence of redis
SVN分支管理
Life is a process of continuous learning
Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
[function explanation (Part 2)] | [function declaration and definition + function recursion] key analysis + code diagram
理解 期望(均值/估计值)和方差
Kubernetes notes (II) pod usage notes
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
[trivia of two-dimensional array application] | [simple version] [detailed steps + code]
一起上水碩系列】Day 9
How to create and configure ZABBIX
Alibaba cloud OOS file upload
PMP笔记记录
Installation du plug - in CAD et chargement automatique DLL, Arx
智牛股项目--05
Why should there be a firewall? This time xiaowai has something to say!!!
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Synthetic keyword and NBAC mechanism
[teacher Zhao Yuqiang] MySQL flashback