I would like to make an entity description time dynamic. How can I do this? My initial thought was to create a SampledProperty instance for the description property, but I am not sure what type to initialize it with. I tried putting in String, but it threw an exception because String is not "packable".
Furthermore, I might as well ask your advice for implementing my more advanced scenario. I have several data values I would like to be shown in my description, but some of these values are from different sources and at different time intervals.
So as a simple example, say I have a speed value that I get every 1 second, and an odometer value I get every 5 seconds. In my info window, I would like the speed value to update every 1 second, but the odometer value would update every 5 seconds.
What would you advise is the best way to do this with the Cesium API?
Maybe use the onTick function to update .value of textAreas and/or .innerHTML of divs in the infoBox. You can access the infoBox iframe element using viewer.infoBox._element. Unfortunately it’s a private property. Maybe you can get to it without using a private property http://stackoverflow.com/questions/1451208/access-iframe-elements-in-javascript
The data will be pushed from the server to the client. The server handles the intervals for each piece of data and pushes it to the client, so the client does not need to explicitly make requests or handle the intervals. For each source, I have a JavaScript function that is called when the data is received.
For example, continuing with my previous example, if one source was providing speed at a 1 second interval, I would have a JavaScript function something like SpeedReceived(entityID, time, speed) that gets triggered every 1 second by the server.
If I had another source providing odometer reading at a 5 second interval, I would have a JavaScript function something like OdometerReceived(entityID, time, odometer) that gets triggered every 5 seconds by the server.
(In my real project, there are more than just two individual values... each source contains an object of many values, but I am simplifying it for discussion)
The easiest way to do what you want is to use a CallbackProperty
var descriptionProperty = new CallbackProperty(function(time) {
//Return any string you want, as an example, this just returns the current wall time as a string
return Cesium.JulianDate.now().toString();
}, false);
If you have an entity with other properties that you want to use to build the string, that’s easy as well. This will allow you to take advantage of the interpolation for those numeric properties. For example, if we wanted to throw the current position into the mix.
var entity = …
var descriptionProperty = new Cesium.CallbackProperty(function(time) {
//Return any string you want, as an example, this just returns the current wall time as a string
var currentPosition = entity.position.getValue(time);
I’ve had a long standing issue to add a SampledStringProperty that makes building time-dynamic strings out of other properties easy (and doable from CZML), but CallbackProperty makes it easy enough to do that most use cases don’t need anything else.
Thanks Matt. I think this will point me in the right direction for what I need! I need to store additional custom data related to time, but I think I can possibly create my own custom Property for my object type, or even just put it in an array, and then grab the required data from inside the CallbackProperty as you described.
On this topic, is it possible to use a TimeIntervalCollectionProperty to preset different strings for different time intervals? I have been trying to do this and it doesn’t seem to be working.