David
David

Reputation: 21

Dynamically change polygon position in cesium

I'm trying to draw few polygons that dynamically change their position.

The problem is that by using:

onUpdatePolygonData(data){

/// DO SOME CALCULATIONS TO GET point1, point2 point3...

if(Cesium.defined(entity.polygon)
     entity.polygon.hierarchy = new Cesium.PolygonHierarchy([point1, point2, point3])  
else entity.polygon = viewer.entities.add({ 
     polygon = new Cesium.PolygonGraphics({
          hierarchy: new Cesium.PolygonHierarchy([point1, point2, point3])
     })
});
}

The result is disturbing blinking on the map.

Updating location occurs roughly once in 40ms though seems like frequency of updates have nothing to do with it.

Anyone knows a way to make the changes smoother?

Thanks for help, David.

Upvotes: 1

Views: 1321

Answers (1)

Baruch Levin
Baruch Levin

Reputation: 372

You need to use Callbackproperty, it executed every frame so it won't blink and be smoother.

In typescript you can write:

let poly = viewer.entities.add({
    polygon: {
        hierarchy: new CallbackProperty (() => {
              return new PolygonHierarchy([point1, point2, 
        point3]) ;
        }, false) 
});

Upvotes: 1

Related Questions