I am trying to show an entity moving within Cesium using live/dynamic data. I have tried multiple techniques from reading from earlier forums, mostly from 2015-2016. I just would like to know how to get it to work.
This is what I have currently. I have tried every method I have found on stackoverflow and Cesium forums and every time nothing will even load. It’s a blank screen every time.
// Get your token from https://cesium.com/ion/tokens
Cesium.Ion.defaultAccessToken = 'xxxx';
const viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain()
});
const osmBuildings = viewer.scene.primitives.add(Cesium.createOsmBuildings());
const data = JSON.parse('C:/Users/moose/Documents/Cesium/telemetryGet.json');
var telemetry = Cesium.Cartesian3.fromDegrees(data.longitude, data.latitude, data.altitude);
var dronePositions = new Cesium.SampledPositionProperty();
dronePositions.addSample( Cesium.JulianDate.fromDate(new Date()), telemetry);
// Load the glTF model from Cesium ion.
const airplaneUri = await Cesium.IonResource.fromAssetId(1634734);
const DroneEntity = viewer.entities.add({
position: dronePositions,
// Attach the 3D model instead of the green point.
model: { uri: airplaneUri },
// Automatically compute the orientation from the position.
orientation: new Cesium.VelocityOrientationProperty(telemetry),
});
viewer.selectedEntity = DroneEntity;
// setTimeout(loadModel, 1000);
viewer.zoomTo(viewer.entities);
var clock = viewer.clock;
var lastUpdated = clock.currentTime;
clock.onTick.addEventListener(function() {
var dt = Cesium.JulianDate.secondsDifference(clock.currentTime, lastUpdated);
if (dt >= 1.0) {
// Add a new sample position
lastUpdated = clock.currentTime;
}
});
add your points into dronePositions at the appropriate time just like setting the start and end point.
do not forget that time should drop in the time range of the clock