Refresh Entity with Real-Time Data on Cesium

I have been attempting to showcase an entity moving within Cesium through the use of live/dynamic data. After trying various techniques and consulting past forums, particularly those from 2015-2016, I am still struggling to make it work.

Despite my efforts, nothing seems to be loading properly on the screen whenever I implement the methods suggested on stackoverflow and Cesium forums. It consistently displays a blank screen each time.

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;
    }
});

Answer №1

It appears that the issue lies within dronePositions.addSample method.
The first parameter of addSample, time, should fall within the time range set by your viewer's clock.

Below is the corrected code snippet.

Sandcastle

const {
    BoundingSphere,
    Cartesian3,
    ClockRange,
    JulianDate,
    SampledPositionProperty,
    VelocityOrientationProperty,
    Viewer
} = window.Cesium;

const viewer = new Viewer("cesiumContainer", {
    shouldAnimate: true
});

const startTime = JulianDate.fromDate(new Date(2019, 5, 10, 13));
const stopTime = JulianDate.addSeconds(startTime, 10, new JulianDate());

viewer.clock.startTime = startTime.clone();
viewer.clock.stopTime = stopTime.clone();
viewer.clock.shouldAnimate = true;
viewer.clock.clockRange = ClockRange.LOOP_STOP;

viewer.timeline.zoomTo(startTime, stopTime);

const latitude = 38;
const longitude = 127;
const altitude = 10;

const dronePositions = new SampledPositionProperty();

const startPoint = Cartesian3.fromDegrees(longitude, latitude, altitude);

dronePositions.addSample(startTime, startPoint);

const endPoint = Cartesian3.fromDegrees(longitude + 0.001, latitude, altitude);

dronePositions.addSample(stopTime, endPoint);

const airplaneUri = "../SampleData/models/CesiumDrone/CesiumDrone.glb";

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 VelocityOrientationProperty(dronePositions)
});

viewer.camera.flyToBoundingSphere(BoundingSphere.fromPoints([startPoint, endPoint]));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize inline scripts within the views of Yii2 for enhanced functionality

I stumbled upon a jQuery code online that allows for the integration of Google Maps, and I'm looking to implement it in my application to ensure accurate address retrieval. You can find the jQuery code here. Currently, I am working with yii2 Advanced ...

Issues with sending an AJAX POST request to a PHP script

Hello, I am trying to send a variable from an AJAX JavaScript file to a PHP file. Here is what I have done so far: var request = createRequest(); var deletenode = node.id; window.alert("nodeid=" + deletenode); var vars = "deletenode ...

Tips for retrieving a selected date from an HTML textbox labeled as "Date"

My goal was to find the differences between two dates by utilizing an HTML Date textbox. <input type="text" name="datein" id="datein" value="" class="inputtexbox datepicker" style="display: none" is-Date/> <input type="text" name="dateto" id=" ...

The imported path is not found in Tsconfig

Hey there! I've been working on getting my project's imports to play nice with typescript import paths. Every time I encounter this error : Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'app' imported from dist/index.js It seems l ...

The overall outcome determined by the score in JavaScript

Currently, I am working with a dataset where each person is matched with specific shopping items they have purchased. For instance, Joe bought Apples and Grapes. To gather this information, individuals need to indicate whether they have made a purchase. I ...

AngularJS encountered an unidentified provider: $routeProviderProvider

I've hit a roadblock with an unfamiliar provider error and can't seem to figure out what I'm missing. Here's the setup: in main.js 'use strict'; angular.module('myApp') .controller('MainCtrl', ['n ...

Incorporate an icon into a text input field using Material UI and React

I have a form with a text input element: <FormControl className='searchOrder'> <input className='form-control' type='text' placeholder='Search order' aria-label='Search&ap ...

Tips for utilizing the select feature within an ng-repeat loop while maintaining the selected value when fetching data from an API

I am currently facing an issue with using select inside ng-repeat. I am attempting to correctly map the value coming from my API to the select as the selected value. However, I seem to be missing something from my end. Can someone please help me identify a ...

Retrieving outcomes from a sequence of callback functions in Node.Js

I've been struggling to get my exports function in Node.Js / Express app to return the desired value after going through a series of callback functions. I've spent hours trying to fix it with no success. Can someone provide some guidance? Here is ...

tool for showcasing data on a webpage with a specific layout

Which chart library is best suited for presenting data in the formats shown in the images below? Can HighCharts handle these formats? Does Google Charts allow for a combination of bubbles and lines? ...

Creating a variable to store the data retrieved from a package

Imagine you have a functioning code snippet like this: const myPackage = require('myPackage'); myPackage.internal_func(parameter).then(console.log); This outputs a JSON object, for example: { x: 'valX', y: 'valY' } ...

Obtaining the data from the React material-UI Autocomplete box

I have been exploring the React Material-UI documentation (https://material-ui.com/components/autocomplete/) and came across a query. Within the demo code snippet, I noticed the following: <Autocomplete options={top100Films} getOptionL ...

"execute loop in a strange and peculiar manner using JavaScript

Implement a loop to place markers on the map: for (i = 0; i <= 6; i++) { _coord = prj_markers[i]; alert(i); instance.set_marker(instance, provider, i, _coord, divBlock); } This code displays "0" in an alert once and executes instance.set_m ...

Issue with Material-UI tab not showing the component upon page load

After setting up material-ui tabs with react-router, I encountered an issue where only the tab names Tab A and Tab B are displayed upon page render. The desired behavior is for the TabAReport component to be automatically rendered without requiring user in ...

"In Typescript, receiving the error message "Attempting to call an expression that is not callable" can be resolved

I am in the process of creating a function that matches React's useState signature: declare function useState<S>( initialState: S | (() => S), ): [S, React.Dispatch<React.SetStateAction<S>>]; Below is an excerpt from the functi ...

What is the best way to access an external array using ng-repeat in AngularJS?

My dataset consists of 3 separate arrays. "areas": { "default": [ { "area": "Master Bedroom", "uuid": "986e3f42-1797-49ae-b060-181a33b9", "description": "", "new": [ { "value": "986e3f42-1797-49ae-b060-181a3 ...

Ways to execute additional grunt tasks from a registered plugin

I am currently in the process of developing a custom Grunt plugin to streamline a frequently used build process. Normally, I find myself copying and pasting my GruntFile across different projects, but I believe creating a plugin would be more efficient. Th ...

How to programmatically update one input value in AngularJS and trigger validation as if it was manually entered by the user?

I'm currently using Angular 1.3.0rc2 and facing an issue with setting one input field based on another input field after the blur event. When I try to set the value of an input field that only has a synchronous validator, everything works fine by usi ...

The persistent problem with constantly polling the $.ajax request

One issue I'm facing involves a continuous polling $.ajax request. The challenge lies in initiating it immediately first, and then running it at intervals set in the setTimeout call. Take a look at the example code here. myObj = {}; var output = ...

The post page remains out of reach for Ajax

I've been struggling for hours to identify the issue with this code. I realized that I am unable to access the updateuser.php file even though it is in the same directory and the filenames are correct. Can someone please review the code below and let ...