能拿到实体的经纬度数据可以反过来计算这一经纬度在地球上的高度,根据经纬度高度再去计算笛卡尔坐标系下的坐标,再将笛卡尔坐标转换成屏幕坐标,用这个屏幕坐标去拾取当前屏幕上这个位置的实体
闪烁的效果实现的很粗糙,就是拿到实体数据之后设置延时来改变实体的颜色
也可以加上飞行效果,让视角调整到显示该实体
let position = null
let pickedObject = null
let retrievedEntity = null
// 根据经纬度计算高度
let baseHeight = viewer.scene.sampleHeight(
new Cesium.Cartographic(
Cesium.Math.toRadians(lng),
Cesium.Math.toRadians(lat)
)
);
position = Cesium.Cartographic.fromDegrees(lng, lat, baseHeight);
let cartesian3 = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
let cartesian2 = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, cartesian3);
// 转成屏幕坐标
pickedObject = viewer.scene.pick(cartesian2);
retrievedEntity = pickedObject
// 拿到实体
retrievedEntity = pickedObject.id
// 模拟闪烁效果
retrievedEntity.polygon.material = Cesium.Color.LIME;
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.YELLOW.withAlpha(0.8)
},500)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.LIME
},1000)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.YELLOW.withAlpha(0.8)
},1500)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.LIME
},2000)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.YELLOW.withAlpha(0.8)
},2500)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.LIME
},3000)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.YELLOW.withAlpha(0.8)
},3500)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.LIME
},4000)
setTimeout(()=>{
retrievedEntity.polygon.material = Cesium.Color.YELLOW.withAlpha(0.8)
},4500)