how to toggle visibility on entity groups? Similarly to layers

I have entities which are logically grouped by parent-child relationship. I would like to be able to

toggle visibility of such a group by their parent. What is the best way to achieve this in terms of performance and

without abusing the api?

I’m trying to achieve the same as ‘imageryLayers’ works, but for entities. Currently, only visibility is what I’m trying to implement.

In the future, I’d like to set ‘global effects’ per such ‘entity layer’ such as global tint (implemented with ambient lightning maybe?)

or translucency for all entities in a ‘layer’.

Reading and digging through the forum and api led me to use CustomDataSource as the way to implement it.

So far this is what I’ve done :

  1. Created a CustomDataSource for each parent, and filled it’s entities’ with my data

  2. Added and removed that CustomDataSource from the viewer to toggle it’s entities visibility.

After playing with the visibility twice or more, the ‘_visualizers.length’ in the DataSourceDisplay becomes undefined, throwing an exception.

I guess they are destroyed and not recycled after the data source is removed. Maybe I just need to keep the EntityCollection and create a new

data source each time?

If my solution of using CustomDataSource is the right way, then implementing global effects would

require writing some visualizers and shaders to take the effect parameters into account? Or there’s a better way?

Thanks!

I believe the “Entity.show” property cascades to child entities as well. Other properties, though, would probably be harder to work with.

Thanks for the reply.

I’ve tried exploring Entity’s ‘_children’ field, but it is not working as I expect it to be (maybe a bug in 1.11?).

Here’s what I do:

I’m creating an entity in the via ‘viewer.entities.add…’ and I can see it. Then using DrawHelper plugin i’m creating an entity this way :

parentEntity._children.push(new Cesium.Entity({

position : p,

label :{

text: ‘child’,

font: ‘500 14pt/16pt arial’,

style : Cesium.LabelStyle.FILL_AND_OUTLINE,

fillColor: Cesium.Color.WHITE,

outlineColor: Cesium.Color.WHITE,

verticalOrigin: Cesium.VerticalOrigin.TOP,

pixelOffset: new Cesium.Cartesian2(0, -36),

debugShowBoundingVolume :true

},

point :{

pixelSize : 8,

color : Cesium.Color.YELLOW,

outlineColor : Cesium.Color.RED,

outlineWidth : 1,

}

}));

``

While parentEntity is displayed on the map, the children aren’t… The documentation does refer to the

‘show’ property of an Entity as affecting it’s children, however the ‘_children’ is a private field and not documented at all,

it’s an array rather than a Cesium Collection. I’m not sure if I’m using it right, or is it not a completed feature yet…

Then it came to me… Maybe, I should add the child entities to the collection and just link with the _children of the parentEntity?

So I tried to push the child entity id and the even the entity itself - neither works when setting parent’s show to false, they are all

still appearing (except the parent of course)

If you look at the implementation of the Entity.parent, it appears that the logic for having the child refer to the parent AND the parent refer to the child is implemented there. So, rather than directly fiddling with the “private” _children property, I think you’re supposed to say childEntity.parent = parentEntity, and let it hook things up.

Looks promising, missed it out! I’ll definitely will look into it and update in a few days. Thanks a lot!

It worked Mark! Thanks a lot.

Regarding my other problem (the global effects), I’ve currently used ReferenceProperty for each property that should be affected

ad it works good for now. Not sure how will it perform on hundreds or thousands of entities though, but I’ll stick to it now