当前位置:网站首页>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) 这两个都是高程,可以从上图看出,有一些细微的差别,不过影响不大,用这两个任意一个都可以。
边栏推荐
- [function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation
- MySQL startup error: several solutions to the server quit without updating PID file
- PHP notes are super detailed!!!
- Core principles and source code analysis of disruptor
- How to create your own repository for software packages on Debian
- [teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
- PMP笔记记录
- Leetcode solution - 01 Two Sum
- Detailed explanation of findloadedclass
- Redhat7系统root用户密码破解
猜你喜欢

从小数据量分库分表 MySQL 合并迁移数据到 TiDB
![Together, Shangshui Shuo series] day 9](/img/39/c1ba1bac82b0ed110f36423263ffd0.png)
Together, Shangshui Shuo series] day 9

Core principles and source code analysis of disruptor

Alibaba cloud OOS file upload

智牛股--03

Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
![[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history](/img/18/f91d3d21a39743231d01f2e4015ef8.jpg)
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
![[teacher Zhao Yuqiang] index in mongodb (Part 2)](/img/a7/2140744ebad9f1dc0a609254cc618e.jpg)
[teacher Zhao Yuqiang] index in mongodb (Part 2)

Kubernetes resource object introduction and common commands (V) - (configmap)

Kubernetes notes (VIII) kubernetes security
随机推荐
How to create and configure ZABBIX
AtCoder Beginner Contest 258(A-D)
为什么网站打开速度慢?
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
How does win7 solve the problem that telnet is not an internal or external command
Kubernetes notes (V) configuration management
Using the ethtool command by example
[written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
pytorch 搭建神经网络最简版
[together Shangshui Shuo series] day 7 content +day8
Error 1045 (28000) occurs when Linux logs in MySQL: access denied for user 'root' @ 'localhost' (using password: yes)
Kubernetes notes (VIII) kubernetes security
Code generator - single table query crud - generator
2022.DAY592
[Zhao Yuqiang] deploy kubernetes cluster with binary package
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
Disruptor learning notes: basic use, core concepts and principles
[teacher Zhao Yuqiang] MySQL high availability architecture: MHA
C 语言文件操作函数大全 (超详细)
[escape character] [full of dry goods] super detailed explanation + code illustration!