Skip to content

Instantly share code, notes, and snippets.

@wewindy
Last active January 5, 2021 01:51
Show Gist options
  • Save wewindy/2abecd870d4e04d6034b9b3ac4591f35 to your computer and use it in GitHub Desktop.
Save wewindy/2abecd870d4e04d6034b9b3ac4591f35 to your computer and use it in GitHub Desktop.
cesiumClickShowLngLat.js
/**
* @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