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.