[cesium-dev] bug ? removing and then immediately adding primitive does not remove the primitive

There is a bug in your code. The first primitive is removed fine, but when you create the new primitive you don’t every assign it the the “primitive” variable. Here is the corrected code:

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

var x = new Cesium.GeometryInstance({

geometry: new Cesium.EllipseGeometry({center:Cesium.Cartesian3.fromDegrees(-100, 40),semiMinorAxis:300000,semiMajorAxis:400000}),

attributes: {

color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)

}

});

var primitive = new Cesium.Primitive({

geometryInstances: ,

appearance : new Cesium.PerInstanceColorAppearance({

translucent:false,

closed:true

})});

var collection = new Cesium.PrimitiveCollection();

collection.add(primitive);

viewer.scene.primitives.add(collection);

setInterval(function(){

collection.remove(primitive); // does not work.

x.geometry._center.x += 10000;

x.geometry._center.y += 10000;

x.geometry._center.z += 10000;

primitive = collection.add(new Cesium.Primitive({ // If i comment out this line the removal does work.

geometryInstances: ,

appearance : new Cesium.PerInstanceColorAppearance({

translucent:false,

closed:true

})}));

}, 500);

Also, if you want to avoid the blinking (at the cost of interactivity) you can pass “asynchronous:false,” as part of the Primitive constructor options.