How to check visibility of entity?

I have added a polyline using:


How to I show and hide with a button by checking to see if entities are visible or not?

The following check does not work.

if(viewer.entities.values[0] {

viewer.entities.values[0] = new Cesium.ConstantProperty(false);

} else {

viewer.entities.values[0] = new Cesium.ConstantProperty(true);


The above does not work. I also tried…

if(viewer.entities.values[0].show) {

viewer.entities.values[0].show = new Cesium.ConstantProperty(false);

} else {

viewer.entities.values[0].show = new Cesium.ConstantProperty(true);


What is the right way?

I have done just;


if(viewer.entities.values[0].show) {

viewer.entities.values[0].show = false;

} else {

viewer.entities.values[0].show = true;


Sai, the reason your initial code does not work is because is not a boolean but an object. You would need to do to retrieve the boolean value.

That being said, if you want to toggle an entire entity on/off, Brian has the right idea and is actually a simply boolean value (because it’s meant for just this type of UI use case).

If all you care about is toggling, a would change Brian’s code to

var entity = viewer.entities.values[0]; = !;

which avoid repeated lookups and avoid the need for if logic.