Entities - Live data and memory usage

Hi all,

I am working with data that I need to retrieve from a REST API (providing the start and end timestamps of the data I am requesting) and display in Cesium. The way I had built this was to create a CustomDataSource. In my data source’s update function, I check the time. If it exceeds a threshold close to the end of the previously retrieved data, it requests new data for the next x seconds.

The problem with this (as far as I can tell), is that the data is never released. The custom data source’s entity collection will simply continue to grow as more data is added. (Including both new entities and data samples for existing entities)

Is this the right approach? Whenever I request new data, I can clear out the existing entities, but I don’t really want to do that in case the user was tracking an entity with the camera. I could clear out the entity’s data structure, but leave its id and name, but this seems to crash Cesium. Am I making this out to be a bigger problem? Can Cesium somehow handle this internally?

Thanks!

There’s no generic “remove data before” functionality for a given entity or collection, but we have an issue to eventually improve this: https://github.com/AnalyticalGraphicsInc/cesium/issues/2520

That bug also has some code on removing data from a sampled property, which you could easily do for each entity on each update (or run every once and a while to prune old data).

Also, you should be calling suspendEvents/resumeEvents on the entityCollection during your update code. If you do, clearing it out and adding entities back should be transparent to the end user, but I would hesitate to recommend this approach because it’s inefficient. It will also remove all data, which is probably not what you want if you are interpolating.

If you are not using interpolation and always want a view of “now”, this problem could be solved by just using a CallbackProperty instead of a SampledProperty to return the current position of each entity. At that point animating backward/forward would have no effect and you wouldn’t be storing any extra data at all.

There seems to be a bug if you remove an entity and then add an entity back with the same id. I’ve tried reworking my code in various ways, but it seems to be a problem no matter what I do.

I’m using the cesium-sensors plugin, and actually, the rectangular sensor shape works correctly, but all of the built-in primitives within the entity no longer work if an entity with the same id was previously removed.

For example, I do the following:

  • var entity = getOrCreateEntity(‘test’)

  • entity.ellipsoid = whatever

  • entity.rectangularSensor = whatever

At some point, I call remove(entity) for that entity, or entities.removeAll()

I then getOrCreateEntity(‘test’) and reinit the primitives ellipsoid and rectangularSensor as before.

After this point, the entity doesn’t seem to exist. I see the rectangular sensor shape on the map, but not the ellipsoid. If I click on the shape, the info box is displayed but grayed out to indicate that the entity doesn’t exist at that time.

Thanks for any help!

What version of Cesium are you using? I think a fixed an issue like this in 1.7, but I would recommend updating all the way to 1.9. That’s in core Cesium, I can’t speak for the open source sensors plug-in, which is no longer technically supported (although I noticed a couple of pull requests and will try and see about getting them merged in).

Hi Matt,

I was using Cesium 1.7.1. I can try upgrading to 1.9 to see if the issue is resolved.

I realize the cesium-sensors plugin is not officially supported. Do you know if someone will be accepting pull requests or should the community fork the repository to make updates if functionality breaks?

Thanks as always for your help!

The community is more than welcome to fork it and accept pull requests to keep it up to date with Cesium. If a particular repository becomes the de factor fork, I’m sure we would list it in our plugins listing instead of the current one.