Force render update after removing polygon position

Good Morning,

I'm trying to get the polygon on the map to update after I've removed positions from it's hierarchy. When I add positions, it updates beautifully; however removing the positions keeps the old polygon shape until I click to keep drawing.

My code for updating the polygon is as such:

var mPosCartographicArray = scene.globe.ellipsoid.cartesianArrayToCartographicArray(mPos);
                    var entityRectangle = Cesium.Rectangle.fromCartographicArray(mPosCartographicArray);
                    var entityCenter = Cesium.Rectangle.center(entityRectangle);
                    entityCenter = Cesium.Cartesian3.fromRadians(entityCenter.longitude, entityCenter.latitude);
                    currentEntity.position = entityCenter;
                    overlayEntities.suspendEvents();
                    console.log(mPos);
                    currentEntity.polygon.hierarchy = new Cesium.PolygonHierarchy(mPos);
                    overlayEntities.resumeEvents();
                    currentEntity.polygon.material = new Cesium.ColorMaterialProperty(myColor);
                    currentEntity.polygon.show = inOverlay.show;
                    currentEntity.label.text = inOverlay.name;
                    currentEntity.label.show = inOverlay.show;

Is there a way to force a visual update?

How are you updating the positions? Assuming you are not updating the positions too often, you can just re-assign the value.

currentEntity.polygon.hierarchy = new Cesium.PolygonHierarchy(mPos);

I'm updating the positions just like that. they're being passed in upon user addition of positions or removal. However, I did find that it's just when there are three positions left. If there are three positions and I remove one then it doesn't update the polygon. If there are four and I remove one, it becomes a triangle as expected.

Can you create a small Sandcastle example that shows the problem so that I can debug it? I can’t reproduce this on my end.

What version of Cesium are you using?

1.7.1 and I'll see what I can come up with.

I’m replying to this from the e-mail chain instead of the forum in order to attach. I was able to recreate the issue. I hope it attached correctly

Polygon Removal Example.html (5.98 KB)

Okay, so I replyed via e-mail but I'm not sure if that ended up working, so I'll post my sandcastle text here:
var viewer = new Cesium.Viewer('cesiumContainer');

var scene = viewer.scene;
var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.onclick = function() {
    canvas.focus();
};
var ellipsoid = scene.globe.ellipsoid;

// disable the default event handlers
scene.screenSpaceCameraController.enableRotate = false;
scene.screenSpaceCameraController.enableTranslate = false;
scene.screenSpaceCameraController.enableZoom = false;
scene.screenSpaceCameraController.enableTilt = false;
scene.screenSpaceCameraController.enableLook = false;

var mPos = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
                                                        -115.0, 32.0,
                                                        -107.0, 33.0]);
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
var redPolygon = viewer.entities.add({
    name : 'Red polygon on surface',
    polygon : {
        hierarchy : mPos,
        material : Cesium.Color.RED
    }
});

handler.setInputAction(function(movement) {
    mPos.pop();
   var mPosCartographicArray = scene.globe.ellipsoid.cartesianArrayToCartographicArray(mPos);
                    var entityRectangle = Cesium.Rectangle.fromCartographicArray(mPosCartographicArray);
                    var entityCenter = Cesium.Rectangle.center(entityRectangle);
                    entityCenter = Cesium.Cartesian3.fromRadians(entityCenter.longitude, entityCenter.latitude);
                    redPolygon.position = entityCenter;
                    redPolygon.polygon.hierarchy = new Cesium.PolygonHierarchy(mPos);
                    redPolygon.label = new Cesium.LabelGraphics({
                                text: 'new label',
                                scale: 0.4
                    });
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);

I think I see the problem. If I add extra points to mPos, such as -107.0, 34.0, -107.0, 35.0, -107.0, 36.0, everything works as expected until it gets down to 2 points. Once the Polygon has less than 3 points it should disappear, the fact that it isn’t is definitely a bug that needs to be fixed. It looks like the problem is that when a geometry because “invalid”, we don’t remove the previous valid geometry. The bug is specific to static data with a single geometry and doesn’t trigger with dynamic geometry.

I opened a new issue to fix this (probably for 1.8): https://github.com/AnalyticalGraphicsInc/cesium/issues/2591

Alrighty,

well thanks for looking into it, I really appreciate the responsiveness.