Polygon Collection

Hello All,

I can see there is a polyline / label and billboard collection - but is there not a polygon collection?

Thanks

Toby

Hi Toby,

Right - there is no polygon collection. Starting with b19, Polygon is built on the new Geometry and Appearances layer, which allows grouping together polygons - like a collection - for efficient rendering. In general, it allows for grouping heterogeneous geometries, e.g., polygons, boxes, and spheres, as long as their vertex formats and appearances match.

Checkout the Sandcastle example and the draft tutorials.

Patrick

Hi Patrick,

Thanks for that. So what I’m trying to do is render various text / lines / polygons etc based on a return from a server. The server can have edits to it, so I have to remove all annotations everytime I refresh so I pick up deletions (ugly I know).

With lines / points it’s pretty easy because I’m adding all of those to a global LabelCollection or PolyLineCollection, which is named and I can just remove in one go. However for the polygons I am adding them as a new primitive everytime (not the way to go I presume). Without a polygonCollection (and without upgrading to b20) is there a way I can do this better?

Thanks

Toby

Toby,

Without b20 or writing a lot of custom rendering code, your approach is reasonable. If performance is OK, I wouldn’t worry about it.

Patrick

Hi Patrick,
I had a similar concern as Toby had. In my case, I use geojsondatasource to load multiple polygon layers from geoserver via wfs. The viewer.datasources.add() method is called to automatically show the results in the viewer. The visualization looks great. But when checking the sence.getPrimitives(), it looks pretty messy. For one polygon layer (for example which contains 5 polygons), the sence.getPrimitives() contains following 9 items:
0: BillboardCollection (empty)
1: LabelCollection (empty)
2: BillboardCollection (empty)
3: PolylineCollection (getLength() = 5)
4: Polygon
5: Polygon
6: Polygon
7: Polygon
8: Polygon

the "3: PolylineCollection" represents the boundary of polygons which is fine, but there is no neat collection for the 5 individual polygons. It will make things difficult and dirty if, for example, I wanna change the color of the polygon layer or on turn it on/off or remove it as a whole.

Could you please cast some light on me?

Heaps of thanks in advance.

Benny

Hi Benny,

We are moving DataSources to the new geometry and appearances, so, in this case, all the polygons will be in the same primitive as long as they have the same appearance (which allows, for example, different colors per polygon, but not different materials).

Also, deep down in Cesium, we have to treat things like polygon fill and outline separately because that is how WebGL and the underlying hardware work. Although we can present higher-level abstractions where they look the same, under-the-hood we need to handle them separately.

Patrick

Thanks Patrick, today I successfully moved my code (based on b20) from scattered polygons and polylines to Geometry as you suggested. The scene.getPrimitives() now looks neat.

I also encountered an issue of attaching (or mapping) attributes (e.g. area, population, average income or json string) to a geometry instance. Noticed that there is a “GeometryInstanceAttribute.js” but later found it is specially designed for rendering and cannot accept any of aforementioned (correct me if I am wrong). So I sort of hack into the “Primitive” and “GeometryInstance” class and use a similar way of handling ‘_instanceID’ to extend the support for additional attributes for GeometryInstance. The “getGeometryInstanceAttributes” method in Primitive is also extended to enable interaction with both rendering attributes (e.g. color, show by default) and my attributes. It works pretty good. By now every primitive in the scene.getPrimitives() represents a data layer on my geoserver and it contains geometry and entire data.

Though the result is desired, I am not quite sure I am doing the right thing here because the geometry is coupled with data after my modification. Please let me know if you have any suggestion.

My second question is can we apply animations on a picked geometry instance (i.e. change its color or alpha)? I can use the default “getGeometryInstanceAttributes” method in Primitive to access the color attribute and apply an instant change in the scene, but how to create an animation? the effect will be useful to highlight the picked geometry instance.

Sorry to make it so long. I really appreciate your help :sunglasses:

Cheers,

Benny

Checkout the Sandcastle animation example.

Patrick

Hi Patrick,
So have upgraded to b21, and am looking at this again… Going well, except I need to be able to add instances to the primitive after it has been instantiated… i.e.

var polygonPrimitive = new Cesium.Primitive({

geometryInstances: ,

appearance: new Cesium.PerInstanceColorAppearance()

});

and then I would expect something like;

polygonPrimitive.addGeometryInstance(geometryInstance);

I know I can get the instance array with polygonPrimitive.geometryInstances, and then there are pop and push operators on that, but not sure if that’s the way to go.

Thanks

Toby

Hi Toby,

This new system is for “static geometry batching” so we have to know the geometry up front, which is what makes it so fast. If we need to add/remove, we need to recreate the primitive or have multiple primitives. For many uses cases, this approach is OK.

However, we can modify per-instance attributes like color, but this isn’t really appropriate for the geometry itself. Also, some limited cases of remove can simply be implemented by setting the per-instance show to false. If you haven’t seen it yet, we are working on a tutorial:

https://github.com/AnalyticalGraphicsInc/cesium/wiki/Geometry-and-Appearances

If you need very fast add/remove (like every frame or every few frames; not every few seconds or minutes), then you’ll be interested in dynamic buffers when we start working on them - #932.

Patrick