Hello,
I’m new to Cesium and need to display a path (polyline) (showing a model or billboard time-bound to it) which gets added new points to it as time passes (the polyline is a trajectory which keeps dynamically growing when new positions are available as time passes).
I made a test in the SandCastle.
To reproduce it please open the ‘Interpolation demo’ (needed to have the 3D model available in the SandCastle itself) found at
then replace the code with mine (running on Cesium 1.47, chrome Version 67.0.3396.99 (Official Build) (64-bit) and Windows 7 64bit):
var viewer = new Cesium.Viewer(‘cesiumContainer’, {
scene3DOnly: true,
selectionIndicator: false,
baseLayerPicker: false,
creditsDisplay: false
//sceneModePicker: true
});
var startPos = {lat: 42.341456, lon: -7.242144};
var deltaPos = { dlat: 42.341530 - startPos.lat, dlon: -7.241753 - startPos.lon };
var currPos = startPos;
var sampledPosProp = new Cesium.SampledPositionProperty();
var sampledPosPropEnt = null;
var start = null;
var clock = new Cesium.Clock({
startTime : Cesium.JulianDate.fromIso8601(“2013-12-25”),
currentTime : Cesium.JulianDate.fromIso8601(“2013-12-25”),
stopTime : Cesium.JulianDate.fromIso8601(“2013-12-26”),
clockRange : Cesium.ClockRange.LOOP_STOP,
clockStep : Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER
});
var addNewSample = function() {
currPos.lat += deltaPos.dlat;
currPos.lon += deltaPos.dlon;
clock.tick();
var stop = clock.currentTime;
//console.log(stop+’ ‘+currPos.lat+’ '+currPos.lon);
var position = Cesium.Cartesian3.fromDegrees(currPos.lon, currPos.lat, 0.0);
sampledPosProp.addSample(stop,position);
if(start===null){
start = stop.clone();
} else {
let oldSampledPosPropEnt=sampledPosPropEnt;
viewer.timeline.zoomTo(start, stop);
sampledPosPropEnt = viewer.entities.add({
//Set the entity availability to the same interval as the simulation time.
availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start : start,
stop : stop
})]),
//Use our computed positions
position : sampledPosProp,
//Automatically compute orientation based on position movement.
orientation : new Cesium.VelocityOrientationProperty(sampledPosProp),
//Load the Cesium plane model to represent the entity
model : {
uri : ‘…/…/SampleData/models/CesiumAir/Cesium_Air.gltf’,
minimumPixelSize : 64
},
//Show the path as a yellow line sampled in 1 second increments.
path : {
resolution : 1,
material : new Cesium.PolylineGlowMaterialProperty({
glowPower : 0.1,
color : Cesium.Color.YELLOW
}),
width : 10
}
});
if(oldSampledPosPropEnt!==null){
viewer.entities.remove(oldSampledPosPropEnt);
}else{
//console.log(‘zooming!’);
//viewer.flyTo(sampledPosPropEnt);
viewer.camera.lookAt(position, new Cesium.Cartesian3(0.0, 0.0, 1000.0));
}
}
};
clock.canAnimate=true;
clock.shouldAnimate=true;
setInterval(addNewSample,2000);
Waiting a couple a seconds after load the trajectory should be visible.
Clicking anywhere on the timeline you should now see the airplane model and changing the timeline cursor position should move it on the simulated trajectory.
This code has 2 major drawbacks:
1 - it has to destroy and recreate the entity so that the new point (added at each new time interval elapsed) is displayed (performance hit)
2 - each time the entity is destroyed and recreated the airplane model is so and that shows up with an unpleasant airplane model flickering.
I wouldn’t like to have to resort to the basic polyline primitive because I should code on my own all the model/polyline display and timeline synch logic which is already existing in the entity used above.
I’d also like to have have the picking feature available later.
Anyway to check if it would be possible I tried the code in
https://groups.google.com/forum/#!msg/cesium-dev/CclK7a5cLmI/gCmd4Km4834J (first Peter Sweeney post)
but not even in this case the polyline gets properly displayed after new points are added to it (it looks like it’s static).
What is the proper way (or alternatives) to accomplish my goal?
TIA for any help or hints.