When to use entity and when primitive?


Describe my problem:
Everything in my app is dynamic. For example I create 10 billboards which move on the globe with callbackproperty, and after minute they destroyed and another lets say 40 billboards created and move on the globe.
But there are not only billboards which move, there also independently polygon, polyline labels etc which move and destroyed.

The question:

  1. Because my app is dynamic, what is the best implementation: make them primitives or entities and why?

2.Now to destroy billboard(for example of course), i just remove by id from the collection. Is it the proper way to destroy?

3.And in general, when to use entity and when primitive? Because you can implement the same thing in both ways…

Thanks in advance

1 Like

Great question!

We described the difference between the two in our Creating Entities tutorial, which you can check out here: https://cesium.com/docs/tutorials/creating-entities/. Entity is built on top of Primitive to abstract out some of the low-level details.

We would recommend using Entity in general because it does what Primitive does and more.

If you are using a PrimitiveCollection to store your primitives, you can use remove(object) or removeAll(), and set the destroyPrimitives flag to the appropriate value. Documentation.

If you are using an EntityCollection, you can use remove(entity), removeAll(), removeById(id) which is what you proposed.

1 Like