当前位置:网站首页>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)
这两个都是高程,可以从上图看出,有一些细微的差别,不过影响不大,用这两个任意一个都可以。
边栏推荐
- Es remote cluster configuration and cross cluster search
- [teacher Zhao Yuqiang] kubernetes' probe
- @Import annotation: four ways to import configuration classes & source code analysis
- [teacher Zhao Yuqiang] MySQL flashback
- There is no one of the necessary magic skills PXE for old drivers to install!!!
- [teacher Zhao Yuqiang] MySQL high availability architecture: MHA
- JS implements the problem of closing the current child window and refreshing the parent window
- [video of Teacher Zhao Yuqiang's speech on wot] redis high performance cache and persistence
- Crontab command usage
- 项目总结--2(Jsoup的基本使用)
猜你喜欢
理解 YOLOV1 第一篇 预测阶段
为什么网站打开速度慢?
[branch and cycle] | | super long detailed explanation + code analysis + a trick game
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
项目总结--04
Convolution operation in convolution neural network CNN
Apache+php+mysql environment construction is super detailed!!!
[together Shangshui Shuo series] day 7 content +day8
Life is a process of continuous learning
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
随机推荐
Download the corresponding version of chromedriver
智牛股项目--05
Troubleshooting of 32GB Jetson Orin SOM failure to brush
Why is the website slow to open?
phpstudy设置项目可以由局域网的其他电脑可以访问
Btrfs and ext4 - features, strengths and weaknesses
[escape character] [full of dry goods] super detailed explanation + code illustration!
Redhat7系统root用户密码破解
pytorch 多分类中的损失函数
[function explanation (Part 2)] | [function declaration and definition + function recursion] key analysis + code diagram
Jedis source code analysis (II): jediscluster module source code analysis
Pytorch builds the simplest version of neural network
Kubernetes notes (I) kubernetes cluster architecture
[teacher Zhao Yuqiang] Flink's dataset operator
[teacher Zhao Yuqiang] MySQL flashback
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
88. 合并两个有序数组
Pytorch dataloader implements minibatch (incomplete)
If function of MySQL
Personal outlook | looking forward to the future from Xiaobai's self analysis and future planning