业务描述:在场景中添加一个车辆,并实时改变车辆的位置,可选方案比较多,根据实际情况有不同的实现方式。
1、知道车辆所有轨迹的点坐标,用entity方式添加模型,position用SampledPositionProperty记录每个点的时间和位置,并设置好clock。
2、知道车辆所有轨迹的点坐标,采用CZML方式
3、只知道当前位置的坐标,用entity方式添加模型,position用CallbackProperty方式实时改变。应用场景:摄像头实时采集车辆信息,使用webSocket的方式把位置推送到客户端。
此处只实现第三种方式的
viewer.entities.add({
// 位置position: new Cesium.CallbackProperty(() => {return new Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1])}, false),
// 设置headingorientation: new Cesium.CallbackProperty(() => {return Cesium.Transforms.headingPitchRollQuaternion(new Cesium.Cartesian3.fromDegrees(lnglat[0], lnglat[1]),new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(heading),))}, false),model: {uri: "./data/car.gltf",heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,}});
代码解析:
lnglat:值是实时改变的
heading :值是实时改变的