cesium绘制轨迹以及轨迹回放

//加轨迹线
let lineData = [106,39,132,48,120,32];
let entities = viewer.entities.add({
    polyline:{
        positions:Cesium.Cartesian3.fromDegreeArray(lineData),
        width:5,
        material:new Cesium.Color.fromCssColorString("#FF0000"),
        clampToGround:true
    }
})

//模型沿着轨迹移动(图标移动过的路径变色)
let moveData = [{
    time:1656047671018,
    x:106,
    y:39,
    z:0
},{
    time:1656047771018,
    x:132,
    y:48,
    z:0
},{
    time:1656047871018,
    x:120,
    y:32,
    z:0
}];
var date = new Date(moveData[0].time);
var start = Cesium.JulianDate.fromDate(date); //获取第一个点的时间
viewer.clock.startTime = start;  //将多个点的第一个点设为轨迹播放的开始时间
viewer.clock.currentTime = start; //修改时间轴的当前时间
viewer.clock.shouldAnimate = true; //开始播放
var property = new Cesium.SampledPositionProperty();
for (var z = 0; z < moveData.length; z++) {
    var item = moveData[z];
    var thisTime = Cesium.JulianDate.fromDate(new Date(item.time));
    var position = Cesium.Cartesian3.fromDegrees(item.x, item.y, item.z);

    // 添加每一个链接点的信息,到达的时间以及坐标位置
    property.addSample(thisTime, position);
}
//设置贴地
property.setInterpolationOptions({
    interpolationDegree: 2,
    interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
});
var times = property._property._times;
var startTime = times[0].clone();
var stopTime = times[times.length - 1].clone();
var entitydd = viewer.entities.add({
	availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
		start: startTime,
		stop: stopTime
	})]),
	position: property, // 点集
	model: {
		uri: 'http://data.marsgis.cn/gltf/mars/weixin.gltf',
		scale: 1,
		minimumPixelSize: 90
	},//model方式 和billboard二选一
    billboard:{
        image:"附件本地地址",
        scale:0.5,
        pixelOffset:new Cesium.Cartesian(0,-20),
        heightReference:Cesium.HeightReference.CLAMP_TO_GROUND,
        clampToGround:true  //是否贴地
    },//billboard方式 和model二选一
	path: {
		leadTime: 0,
		resolution: 1,
		material: new Cesium.PolylineGlowMaterialProperty({
			glowPower: 0.1,
			color: Cesium.Color.GREEN
		}),
		width: 10
	}
});

你可能感兴趣的:(cesium,javascript)