The Polyline class lets you set the positions of the line to a new array of Cartesian positions.
Here’s a Sandcastle example that you can paste over top of the Polyline example that adds random new positions to a polyline periodically.
require([‘Cesium’], function(Cesium) {
“use strict”;
function createPrimitives(scene, ellipsoid) {
var primitives = scene.primitives;
var polylines = new Cesium.PolylineCollection();
primitives.add(polylines);
var position1 = Cesium.Cartographic.fromDegrees(-120.0, 40.0);
var position2 = Cesium.Cartographic.fromDegrees(-110.0, 30.0);
var positions = [position1, position2];
// A simple polyline with two points.
var polyline = polylines.add({
positions : ellipsoid.cartographicArrayToCartesianArray(positions),
material : Cesium.Material.fromType(‘Color’, {
color : new Cesium.Color(1.0, 1.0, 1.0, 1.0)
})
});
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
setInterval(function() {
var lastPosition = positions[positions.length - 1];
var newPosition = lastPosition.clone();
newPosition.latitude += getRandom(-0.1, 0.1);
newPosition.longitude += getRandom(-0.1, 0.1);
positions.push(newPosition);
polyline.positions = ellipsoid.cartographicArrayToCartesianArray(positions);
}, 500);
}
var viewer = new Cesium.Viewer(‘cesiumContainer’);
createPrimitives(viewer.scene, viewer.centralBody.ellipsoid);
Sandcastle.finishedLoading();
});