Polygon shape callback property error (outerpositions undefined))

Hi,
I’m currently just trying to get a polygon to update after being drawn by changing its hierarchy array.
This is the current code I have

var viewer = new Cesium.Viewer(“cesiumContainer”);
var coordinatesArray = [-72.0, 40.0, -70.0, 35.0, -75.0, 30.0, -70.0, 30.0, -68.0, 40.0];
var coordinates = new Cesium.Cartesian3.fromDegreesArray(coordinatesArray);

function drawPolygon(){

var polygonCreate = viewer.entities.add({        
    polygon : {
        hierarchy: coordinates,
        material: Cesium.Color.fromCssColorString("green"),

    }
});

return polygonCreate;

}

//drawPolygon();

function drawPolygonWithUpdate(){

var polygonCreate = viewer.entities.add({        
    polygon : {
        hierarchy: new Cesium.CallbackProperty(function () {
  return coordinates;
}, false),
        material: Cesium.Color.fromCssColorString("green"),

    }
});

return polygonCreate;

}
drawPolygonWithUpdate();

setTimeout(positionUpdate(), 20000);
function positionUpdate()
{
coordinates = new Cesium.Cartesian3.fromDegreesArray([-100, 30.0,-84.0, 39.0, -97.0, 30.0, -112.0, 28.0]);

}

Here is the sandcastle link

However this code can also be plugged into cesium sandcastle and will display the error received, which is “outerPositions is undefined”.
drawPolygon displays a polygon without any issues. To get the working version just comment the drawPolygonWithUpdate calls and uncomment the drawPolygon call.

My goal is to create a polygon by adding it to the viewer.entities, and then changing the location of the polygon by passing in different coordinates to hierarchy.

The example here Entity position doesn't apply to polygons · Issue #7180 · CesiumGS/cesium · GitHub from hpinkos shows also what I try to achieve but the example, which was meant to work also throws the same error I get (“outerPositions is undefined”).
Is there a new way of updating polygons or is there a mistake that I made in my code?

Any feedback and help would be very much appreciated.

I think this is because the callback expects an object with a positions property. See here:
edited sandcastle

Hi Mark,

Thank you so much for your response, this helps me out a lot. It’s nice to see this working.

i would like to ask what if we have multiple polygon on the map and we click any one of them and get there Refrance (id / name) like this

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

handler.setInputAction(function(click) {

var pickedObject = scene.pick(click.position);

if (Cesium.defined(pickedObject)) {

    console.log("pickedObject.id.id ", pickedObject.id.id);

    console.log("pickedObject.id.name ", pickedObject.id.name);

    console.log("pickedObject.id..polygon.hierarchy ", pickedObject.id.polygon.hierarchy.valueOf());

    var data = pickedObject.id.polygon.hierarchy.valueOf();

    console.log("data ", data.positions.valueOf());

    }, false);

}

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

here how can i apply the callback the specfic polygon.