可用来代码触发需要事件动作触发的操作,cesium高度太高在视图中多个entity靠的太近或叠在一起获取的坐标可能就不太准确,就需要作进一步处理
// 获取entities实体
let entitie = viewer.entities.getById('id');
let Cartesian3 = entitie.position._value;
// 添加地形后,用scene把Cartesian3重新转换一下
let cartographic= viewer.scene.globe.ellipsoid.cartesianToCartographic(Cartesian3);
cartesian3 = Cesium.Cartesian3.fromDegrees(
Cesium.Math.toDegrees(cartographic.longitude),
Cesium.Math.toDegrees(cartographic.latitude),
Math.round((viewer.scene.globe.getHeight(cartographic)) * 100) / 100
);
// 获取视图坐标
let position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, cartesian3);
//获取的pick对象
let pick = viewer.scene.pick(position);