I have a problem with adding Entity to the EntityCollection. I want to add them to the collection to later delete the whole collection with a single button.
var entities = viewer.entities;
var entity = new Cesium.Entity();
var collection = new Cesium.EntityCollection();
function createEntity(name, x, y, z, description) {
entity = entities.add({
id : name,
position : Cesium.Cartesian3.fromDegrees(x,y,z),
name : name,
description : ‘description’,
billboard : {
image : ‘picture/logou/’+nazwa+’.png’,
sizeInMeters : true
}
});
collection.add(entity);
viewer.zoomTo(entity, new Cesium.HeadingPitchRange(0, 0, 1000));
I think you are going to need a custom data source to hold your EntityCollection. See the Sandcastle “Custom DataSource” example under DataSources in the Gallery for inspiration.
I think an easier way, if all you care about is keeping track of them and removing them later, is simply to add them to an array, and then loop over that array and remove all its items.
Thank you very much for the hint of solving the problem, it helped me a lot. Out of curiosity, what was wrong with my code, where I added the “Entity” to the "EntityCollection? Maybe in the future I will need a collection It looks logical and easy in the documentation, but it does not work.
The EntityCollection you created isn’t attached to the viewer/scene. That’s why I suggested the custom DataSource approach, because there is a mechanism to add that to the viewer while there isn’t one for adding an EntityCollection.