Last active
January 5, 2021 01:51
-
-
Save wewindy/2abecd870d4e04d6034b9b3ac4591f35 to your computer and use it in GitHub Desktop.
cesiumClickShowLngLat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description 需要 Cesium.js 环境 | |
*/ | |
const viewer = new Cesium.Viewer("cesiumContainer"); | |
viewer.scene.globe.depthTestAgainstTerrain = true; | |
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); | |
handler.setInputAction(function(click){ | |
const cart = viewer.scene.pickPosition(click.position); | |
const geo = Cesium.Cartographic.fromCartesian(cart); | |
const msg = `${geo.longitude * Cesium.Math.DEGREES_PER_RADIAN}, ${geo.latitude * Cesium.Math.DEGREES_PER_RADIAN}`; | |
console.log(msg); | |
},Cesium.ScreenSpaceEventType.LEFT_CLICK); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment