Skip to content

Instantly share code, notes, and snippets.

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