Hi,
I am using SampledPositionPorperty to get a 3d model movement over time. If the positions all are loaded from a file, it works well.
The problem comes when I want to load the positions dynamically from a server (i.e. kafka deployment) that sends messages (positions) let’s say every 5 seconds. What happens is that the clock starts before getting any position and the model doesn’t show up. How could I achieve the behavior of the model showing up and the clock waiting till next position is added to SampledPositionProperty? Am I mistaken in my approach?
This is an example of my code so far:
function runSimulationWebSocketKafka(){
const timeStepInSeconds = 1;
const totalSeconds = timeStepInSeconds * (100 - 1);
const start = Cesium.JulianDate.fromIso8601("2020-03-09T12:10:00Z");
const stop = Cesium.JulianDate.addSeconds(start, totalSeconds, new Cesium.JulianDate());
// viewer clock at desired time
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
viewer.timeline.zoomTo(start, stop);
// Speed up the playback speed 1x.
viewer.clock.multiplier = 1;
// Loop at the end
//viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
// Clock pauses till next position is given
viewer.clock.clockRange = Cesium.ClockRange.CLAMPED;
// Start playing the scene.
viewer.clock.shouldAnimate = true;
// The SampledPositionedProperty stores the position and timestamp for each sample along the radar sample series.
const positionProperty = new Cesium.SampledPositionProperty();
// add positions from kafka
ws.onmessage = function (event) {
kafkaData = JSON.parse(event.data);
console.log('kafka_data: ', kafkaData.latitude)
const time = Cesium.JulianDate.addSeconds(start, count * timeStepInSeconds, new Cesium.JulianDate());
const position = Cesium.Cartesian3.fromDegrees(kafkaData.longitude, kafkaData.latitude, 0);
positionProperty.addSample(time, position);
}
Thank you for your help.
Iñaki