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

417 views
Skip to first unread message

xl...@tiscali.it

unread,
Jul 26, 2019, 5:49:52 AM7/26/19
to cesium-dev
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
});
polylines.add({
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( ()=> { polylines.show = false; },2000 );

// This doesn't either
/*
var visible = true;
var isConstant = false;
polylines.show = 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

TIA



xygig

unread,
Aug 8, 2019, 6:45:46 AM8/8/19
to cesium-dev
Bump

Omar Shehata

unread,
Aug 14, 2019, 11:17:40 AM8/14/19
to cesium-dev
A polyline collection does not actually have a show property: https://cesiumjs.org/Cesium/Build/Documentation/PolylineCollection.html?classFilter=PolylineCol

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

On Thursday, August 8, 2019 at 6:45:46 AM UTC-4, xygig wrote:
Bump

xygig

unread,
Aug 21, 2019, 2:43:05 PM8/21/19
to cesium-dev
Ooops! 
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.
Cheers

Omar Shehata

unread,
Aug 21, 2019, 4:08:36 PM8/21/19
to cesium-dev
No worries, glad we got it sorted!
Reply all
Reply to author
Forward
0 new messages