当前位置:网站首页>Three methods for cesium to obtain the longitude and latitude at the mouse click
Three methods for cesium to obtain the longitude and latitude at the mouse click
2022-07-19 05:20:00 【Wxy4Z1zzz】
1、 Get the longitude and latitude of the point on the ellipsoid ( Points on an ellipsoid )
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); // longitude
let lat = Cesium.Math.toDegrees(cartographic.latitude); // latitude
let alt = cartographic.height; // Height , Ellipsoid height Always equal to 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);
2、 Get the longitude and latitude of the point on the ground surface ( Points on the terrain )
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); // longitude
let lat = Cesium.Math.toDegrees(cartographic.latitude); // latitude
let alt = cartographic.height; // 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);
3、 Get the longitude and latitude of the points in the scene ( Point on Model )
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); // longitude
let lat = Cesium.Math.toDegrees(cartographic.latitude); // latitude
let alt = cartographic.height; // 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);
边栏推荐
猜你喜欢
随机推荐
Two or three things to know about operation and maintenance safety
Continue from the previous issue: the remaining two methods of the rotation chart
Pointer advanced simple summary
Cesium BIND Mouse Events and remove Mouse Events
uniapp 使用uview实现折叠面板
H5如何获取内网IP和公网IP
Leetcode53. maximum subarray and
手把手教你复现Log4j2核弹级漏洞
Mongo DB aggregate operations and indexes
LeetCode53. 最大子数组和
第一个智能合约程序Faucet.sol
markdown笔记以及Typora相关快捷键
es6新增-对象部分
RK356x U-Boot研究所(命令篇)3.4 mem内存相关命令的用法
cookie是否有效时间限定?如何设置cookie?手把手教你设置
多功能(实现)封装函数
2020-10-22
Baidu map realizes thermal map
How to deal with the mismatch between subtitle files and video files
Installation and fast use of Mongo DB stand-alone version








