Dynamic Property Updating of GroundPrimitive

What is the correct method to update the positions property of a CorridorGeometry or PolygonGeometry once it has been added to the scene.groundPrimitives collection? I know for Entities that we can just use the CallbackProperty. I have tried to just add additional Cartesian3 to the array but this doesn't seem to update the geometry.

Best Regards,
Chris

Hello Chris,

At the Primitive API level (which includes primitive geometry types like CorridorGeometry and PolygonGeometry), the only way to update the geometry is to remove it from the primitive collection and add a new geometry with the new values.

We do recommend that people use the Entity API for creating geometry that needs to change because it handles the updating for you.

If you are interested in getting your entities to display on terrain, take a look at this pending pull request: https://github.com/AnalyticalGraphicsInc/cesium/pull/3406

It’s not quite ready to be merged into master, but you can see what changes need to be made to have the entities draw on terrain.

Best,

Hannah

Hey Hannah,

Ok so just to confirm, if I need to change any property of a primitive then I need to remove and re-add to the collection with the updated properties?

Best Regards,
Chris

Not remove and re-add, you have to create a new polygon each time in order to changes the positions. Here’s a Sandcastle example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var add = 0;
var lon = -115;

function getPositions(){
add += 1;
return Cesium.Cartesian3.fromDegreesArray([
lon, 37.0,
lon, 32.0,
lon + 1 + add, 32.0,
lon + 1 + add, 37.0
]);
}

var primitive;
function addPolygon() {
primitive = viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.PolygonGeometry.createGeometry(Cesium.PolygonGeometry.fromPositions({
positions : getPositions(),
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
})),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
}
}),
appearance : new Cesium.PerInstanceColorAppearance({
closed : true,
translucent : false
}),
asynchronous: false
}));
}

Sandcastle.addDefaultToolbarButton(‘Create Polygon’, function() {
viewer.scene.primitives.remove(primitive);
addPolygon();
});

``

This example also shows how to draw the polygon synchronously to avoid flashing when you go to change the polygon properties.

Best,

Hannah