Cesium 点击查询
代码
let clickHandler = null; // function initClickHandler() { //初始化 clickHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); //绑定左点击事件 clickHandler.setInputAction((click) => { //获取球面坐标 可用于定位 或者渲染点位数据 let position = viewer.scene.camera.pickEllipsoid( click.position, viewer.scene.globe.ellipsoid ); //获取射线 const pickRay = viewer.camera.getPickRay(click.position); //imageryLayers 拾取 下面方法会返回一个契约函数 const promise = viewer.imageryLayers.pickImageryLayerFeatures( pickRay, viewer.scene ); // entity 拾取 const entity = viewer.scene.pick(click.position); }, Cesium.ScreenSpaceEventType.LEFT_CLICK); //绑定右点击事件 可用于清除 clickHandler.setInputAction(() => { clearHandler(); }, Cesium.ScreenSpaceEventType.RIGHT_CLICK); } //清除点击事件 function clearHandler() { if (clearHandler != null) { clearHandler.destroy(); clearHandler = null; } }