当前位置:网站首页>Cesium 获取经纬度的几种方法
Cesium 获取经纬度的几种方法
2022-07-23 20:04:00 【GISer小辉】
Cesium 获取经纬度的几种方法
1 获取经纬度
本文均采用鼠标左键单击事件作为示例,如有需求,请自行查阅其他事件获取屏幕坐标Cartesian2对象。
1.1 获取椭球上的点的经纬度(椭球上的点)
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(event) {
let cartesian = viewer.camera.pickEllipsoid(event.position);
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
let alt = cartographic.height; // 高度,椭球面height永远等于0
let coordinate = {
longitude: Number(lng.toFixed(6)),
latitude: Number(lat.toFixed(6)),
altitude: Number(alt.toFixed(2))
};
console.log(coordinate);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1.2 获取地表面的点的经纬度(地形上的点)
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(event){
let ray = viewer.camera.getPickRay(event.position);
let cartesian = viewer.scene.globe.pick(ray, viewer.scene);
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
let alt = cartographic.height; // 高度
let coordinate = {
longitude: Number(lng.toFixed(6)),
latitude: Number(lat.toFixed(6)),
altitude: Number(alt.toFixed(2))
};
console.log(coordinate);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
1.3 获取场景里的点的经纬度(模型上的点)
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (event) {
let cartesian = viewer.scene.pickPosition(event.position);
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
let alt = cartographic.height; // 高度
let coordinate = {
longitude: Number(lng.toFixed(6)),
latitude: Number(lat.toFixed(6)),
altitude: Number(alt.toFixed(2))
};
console.log(coordinate);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
2 可能用到的Cesium API
2.1 函数:Camera-pickEllipsoid(windowPosition, ellipsoid, result)
【官方解释】
Pick an ellipsoid or map.
【中文翻译】
选择一个椭球或地图。如果选择了椭球面或地图,返回椭球面或地图上的点,以世界坐标表示。如果未选择椭球或映射,则返回 undefined 。
【入参】
windowPosition,类型:Cartesian2,一个像素的x和y坐标。
ellipsoid(可选,默认值:Ellipsoid.WGS84),类型:Ellipsoid,要选择的椭球。
result(可选),类型:Cartesian3,将结果存储在其上的对象。
【出参】
类型:Cartesian3,椭球面或地图上的点。
2.2 函数:Camera-getPickRay(windowPosition, result)
【官方解释】
Create a ray from the camera position through the pixel at windowPosition in world coordinates.
【中文翻译】
在世界坐标中通过窗口位置的像素从摄像机位置创建一条射线。
【入参】
windowPosition,类型:Cartesian2,一个像素的x和y坐标。
result(可选),类型:Ray,将结果存储在其上的对象。
【出参】
类型:Ray,返回射线的笛卡尔坐标和方向。
2.3 函数:Globe-pick(ray, scene, result)
【官方解释】
Find an intersection between a ray and the globe surface that was rendered. The ray must be given in world coordinates.
【中文翻译】
找到射线和渲染的地球球体表面之间的相交,射线必须在世界坐标中给出。如果没有找到交点,则返回 undefined 。
【入参】
ray,类型:Ray,测试交点的射线。
scene,类型:Scene,场景scene对象。
result(可选),类型:Cartesian,将结果存储在其上的对象。
【出参】
类型:Cartesian,相交点的笛卡尔坐标。
2.4 函数:Scene-pickPosition(windowPosition, result)
【官方解释】
Returns the cartesian position reconstructed from the depth buffer and window position.
The position reconstructed from the depth buffer in 2D may be slightly different from those reconstructed in 3D and Columbus view. This is caused by the difference in the distribution of depth values of perspective and orthographic projection.
Set Scene#pickTranslucentDepth to true to include the depth of translucent primitives; otherwise, this essentially picks through translucent primitives.
【中文翻译】
返回由深度缓冲和窗口位置共同重建的笛卡尔坐标。
该位置在2D视图的深度缓冲(depth buffer)下重建可能会与在3D视图、哥伦布视图(即2.5D视图)重建稍有不同,这是由透视和正射影的深度值分布不同引起的。
如果需要包含透明的原始类型(primitives),请设置 Scene#pickTranslucentDepth 到 true ,否则,此次选择(pick)将会穿过透明的原始类型(primitives)。
【入参】
windowPosition,类型:Cartesian2,执行选中操作的窗口坐标。
result(可选),类型:Cartesian3,将结果存储在其上的对象。
【出参】
类型:Cartesian,重建的笛卡尔坐标。
【抛出异常】
DeveloperError:开发异常,不支持从深度缓冲中选取,请检查 pickPositionSupported 。
2.5 静态函数:Cartographic-Cesium.Cartographic.fromCartesian(cartesian, ellipsoid, result)
【官方解释】
Creates a new Cartographic instance from a Cartesian position. The values in the resulting object will be in radians.
【中文翻译】
从笛卡尔坐标创建一个新的地图实例(Cartographic instance)。结果对象中的值将以弧度为单位。如果笛卡尔坐标位于椭圆体的中心(即Cesium.Cartesian.ZERO),则返回 undefined 。
【入参】
cartesian,类型:Cartesian3,要转换为地图表示的笛卡尔坐标。
ellipsoid(可选,默认值:Ellipsoid.WGS84),类型:Ellipsoid,该坐标所在的椭球。
result(可选),类型:Cartographic,将结果存储在其上的对象。
【出参】
类型:Cartographic,创建的地图实例。
边栏推荐
- AtCoder——Subtree K-th Max
- Cesium 键盘鼠标控制相机漫游(源码+原理讲解)
- Parity rearrangement of Bm14 linked list
- Leetcode 216. combined sum III
- 哈希表、无序集合、映射的原理与实现
- 解决1秒钟内,用户快速点击,重复请求的问题
- New product listing | A-share floor derivatives market point
- 源启数字化:既有模式,还是开源创新?|砺夏行动
- QT with OpenGL (frame cache)
- Is the link of Huatai Securities' low commission account opening safe? How to handle low commission
猜你喜欢

Phar deserialization

-2021最新对比学习(Contrastive Learning)相关必读论文整理分享

Mysql的前世今生,Hello,Mysql

哈希表、无序集合、映射的原理与实现

Data warehouse 4.0 notes - data warehouse environment construction - DataGrid preparation and data preparation

今日睡眠质量记录81分

OpenLayers实例-Accessible Map-可访问的地图

MySQL's past and present life, Hello, MySQL

dokcer镜像理解

OpenLayers实例-Advanced View Positioning-高级视图定位
随机推荐
如何在OneFlow中新增算子
使用代码设置activity为透明
13 ways of Excel automation to avoid repeating tasks in Microsoft Excel
Viewing the "Empathy" energy of iqoo 10 pro from 200W super flash charging
NLP hotspots from ACL 2022 onsite experience
After the input error of next numerical data type () occurs, it can still be input normally next time
深度学习-NLP经典论文、课程、论文等资源整理分享
20. Ref and props
Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 6
task03笔记2
网上开通证券账户安全吗?
AtCoder B - Pizza
安装Win11找不到固态硬盘如何解决?
OpenLayers官方实例全集
数仓4.0笔记——数仓环境搭建—— DataGrip准备和数据准备
What antenna is used for ant interface_ There is an interface at the back of the TV that says standard ant 75 Euro input. What does it mean, antenna? Can you connect the closed route "Suggested collec
数组——704. 二分查找
How important is 5g dual card and dual access?
QT 设置缓存和编译输出路径
phar反序列化