How to change the visibility state of a collection of primitives?

1. A concise explanation of the problem you’re experiencing.

I need to hide(show) all primitives in a collection so I thought that the collection#show property was the way to go but it looks like it has no effect.

Enumerating the collections’ primitives and hiding(showing) them one by one works as expected (via the primitive’s show property).

I tried with a callback property but no luck too (I might be doing something wrong though).

Is the collection#show property meant to show/hide all the items at once and if so how to properly use it?

Furthermore is it supposed to be operated with a callback property too?

A Sandcastle-ready code example with all my three attempts follows.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var scene = viewer.scene;

var polyline;

var material = Cesium.Material.fromType(‘PolylineArrow’);

material.uniforms.color = new Cesium.Color(0,1.0,0,1.0);

var polylines = scene.primitives.add(new Cesium.PolylineCollection());

polyline = polylines.add({

positions : Cesium.PolylinePipeline.generateCartesianArc({

positions : Cesium.Cartesian3.fromDegreesArray([-110.0, 42.0,

-77.0, 12.0])


width : 10.0,

show : true,

material: material



positions : Cesium.PolylinePipeline.generateCartesianArc({

positions : Cesium.Cartesian3.fromDegreesArray([-120.0, 42.0,

-77.0, 12.0])


width : 10.0,

show : true,

material: material


// This works

//setTimeout( ()=> { for(var i=0;i<polylines.length;++i) polylines.get(i).show = false; },2000 );

// This doesn’t

setTimeout( ()=> { = false; },2000 );

// This doesn’t either


var visible = true;

var isConstant = false; = new Cesium.CallbackProperty( ()=> { return visible; }, isConstant );

setTimeout( ()=> { visible = false; }, 2000);


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I need to let the user selectively choose which set of primitives are visible.

4. The Cesium version you’re using, your operating system and browser.

Cesium 1.59, Win 10 64Bit, Chrome 75.0.3770.100 64 bitt official build



A polyline collection does not actually have a show property:

I think enumerating the lines and setting the show is the right way to go about this.

Thanks Omar, unfortunately scene.primitives.add() made me think I was dealing with a PrimitiveCollection instead of the just added item (which is the PolylineCollection you correctly pointed out).
My bad, sorry I wasted your time.


No worries, glad we got it sorted!