I am currently working on an application using the Cesium Viewer. I need to be able to display a collection of forms that will be dynamically updated. I am having trouble understanding the best way to do this.
I am currently using Entities and using CallbackProperties to allow shape updates.
You can do it in a sand castle to understand how I do it. There is a polygon object that is used as the basis for cesiumCallback, and it is edited by another piece of code. (simulated using setTimeout)
var viewer = new Cesium.Viewer('cesiumContainer', {}); var polygon = {}; polygon.coordinates = [ {longitude: 0, latitude: 0, altitude: 0}, {longitude: 10, latitude: 10, altitude: 0}, {longitude: 10, latitude: 0, altitude: 0} ]; // converts generic style options to cesium one (aka color -> material) var polOpts = {}; // function for getting location polOpts.hierarchy = new Cesium.CallbackProperty(function() { var hierarchy = []; for (var i = 0; i < polygon.coordinates.length; i++) { var coordinate = polygon.coordinates[i]; hierarchy.push(Cesium.Cartesian3.fromDegrees(coordinate.longitude, coordinate.latitude, coordinate.altitude)); } return hierarchy; }, false); viewer.entities.add({polygon: polOpts}); setInterval(function(polygon){ polygon.coordinates[0].longitude--; }.bind(this, polygon), 1000);
The resulting polygon is a class that generally describes the polygon, so it has an array of coordinates and style parameters, as well as a rendering method that calls this renderPolygon method, which runs on its own. This shape rendering method works for everything I need, but it is not very efficient. There are two cases of updating shapes; one type of shape will be updated over a long period of time, like a slow speed, just in a few seconds. Another is forms that will be updated many times, for example thousands, in a few seconds, and then will not change again for a long time, if ever.
I had two ideas on how to fix this.
Idea 1: There are two methods: renderDynamicPolygon and renderStaticPolygon. The renderDynamicPolygon method would perform the above functions using cesiumCallbackProperties. This will be used for forms that are updated multiple times in a short time when they are updated. The renderStaticPolygon method replaces the properties of entities that will use callbackProperties with constant values โโas soon as the update is completed.
This creates a lot of other work to make sure that the shapes are in the correct state and do not help slowly changing shapes over a long period of time.
Idea 2: Similar to how primitives work, I tried to delete the old object and add it again with updated properties every time I needed to update it, but this led to flickering and, unlike primitives, I could not find the async property for entities.
I also tried using primitives. It is perfect for polylines, I just delete the old one and add a new one with updated properties. I also used async = false so that there is no flicker. This problem that I ran into was not to create all forms using primitives. (It's true?)
Another thing I tried is to use a geometry instance using geometry and appearance. After going through the tutorial on the cesium website, I was able to display several shapes and could update the look, but found it was almost impossible to figure out how to properly update the shapes, and it was also very difficult to get them before Look correctly. Forms must have the correct shape, fill color and opacity and stroke color, opacity and weight. I tried using polygonOutlineGeometry but no luck.
What would be the best way to implement this? Is one of these options the right direction, or is there some other way to do this, I have not yet revealed?
[Edit] I added the answer where I received, but still not complete and looking for answers.