I created a test based off the polyline demo, just change the test boolean to test it
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var myEntityCollection = new Cesium.EntityCollection();
var test=false;
if(test){var prefix=myEntityCollection;}
else{var prefix=viewer.entities;}
var redLine = prefix.add({
name : ‘Red line on the surface’,
polyline : {
positions : Cesium.Cartesian3.fromDegreesArray([-75, 35,
-125, 35]),
width : 5,
material : Cesium.Color.RED
}
});
var glowingLine = prefix.add({
name : ‘Glowing blue line on the surface’,
polyline : {
positions : Cesium.Cartesian3.fromDegreesArray([-75, 37,
-125, 37]),
width : 10,
material : new Cesium.PolylineGlowMaterialProperty({
glowPower : 0.2,
color : Cesium.Color.BLUE
})
}
});
Thanks for your reply. I tried running the above code and it never adds the entities to the map when using the entity collection.
I am sure I am missing something basic, so for now will continue to use the viewer.entities.add for every entity I wish to add.
If anyone can provide any points as to why viewer.entities.add(myEntityCollection); doesnt seem to add the collection to the globe, that would be great.
Ya that code snippet builds up a msg string but doesn’t seem to output it to the console, that’s why I added console.log(msg).
I don’t think viewer.entities.add(myEntityCollection); is a valid statement, even though it doesn’t throw any errors. I believe you need to use viewer.entities.add to add each entity to the scene. I think entityCollection is intended to keep track of a group of entities, but not to add them as a whole group to the scene. I believe entityCollection is an array of unique ids that refer to entity objects, rather than an array of entities objects themselves.
Looking at Michaels example it seems that for primitives you can add collections, but I could be wrong.
well, just for those messing with the same s**t and wandered here like I did — look at CustomDataSource section at cesium docs. have no idea, why such a logically desired feature is not described well while it's relatively convoluted implemented, but God bless it nevertheless exists