主要利用CallbackProperty来实时更新直线末端位置。效果如下图
function traceTarget(sourEntity,tarEntity){
viewer.entities.add({
polyline : {
positions : new Cesium.CallbackProperty(function(time, result) {
var sourpos = sourEntity.position.getValue(time);
var cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(sourpos);
var lon1 = Cesium.Math.toDegrees(cartographic1.longitude);
var lat1 = Cesium.Math.toDegrees(cartographic1.latitude);
var height1 = cartographic1.height;
var tarpos = tarEntity.position.getValue(time);
var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(tarpos);
var lon2 = Cesium.Math.toDegrees(cartographic.longitude);
var lat2 = Cesium.Math.toDegrees(cartographic.latitude);
var height2 = cartographic.height;
return Cesium.Cartesian3. fromDegreesArrayHeights([lon1, lat1, height1, lon2, lat2, height2],Cesium.Ellipsoid.WGS84, result);
}),
width : 5,
material : new Cesium.PolylineGlowMaterialProperty({
glowPower:0.3,
color:Cesium.Color.BLUE.withAlpha(0.9)
})
}
})
}