Sorting polygons


I’m having a problem when I’m drawing polygons and polylines. I can’t draw polylines over polygons:

My code:

*function PolygonCesium(positions, color){
var polygon = new Cesium.Polygon();
polygon.material.uniforms.color = color;
polygon.positions = positions;
function PolylineCesium(positions, color){
var polylines = new Cesium.PolylineCollection();
var polyline = polylines.add({
positions : positions,
material : Cesium.Material.fromType(‘Color’)
polyline.material.uniforms.color = color;
} *

function geoToCart(x, y) {
return ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(x, y, 0));
PolygonCesium([geoToCart(-94, 1.5), geoToCart(-93, 1.5), geoToCart(-94, 2.5)], new Cesium.Color(1,0,0,1)); // RED POLYGON
PolylineCesium([geoToCart(-95, 1), geoToCart(-92.5, 3)], new Cesium.Color(1,1,0,1)); // YELLOW POLYLINE
PolygonCesium([geoToCart(-94.5, 1.5), geoToCart(-93, 3.5), geoToCart(-93, 2.5)], new Cesium.Color(0,0,1,1)); // BLUE POLYGON
PolylineCesium([geoToCart(-93.5, 1), geoToCart(-93.5, 3)], new Cesium.Color(0,1,0,1)); // GREEN POLYLINE

In the primitives array the order is ok:

Using raise and lower functions of ComposePrimitive doesn’t work.

Can someone help me?




As far as I know, the raise/lower functions don't do anything. They have no effect for me either. I did figure out that primitives that have transparency get rendered last. I used this as a trick to get billboards to render on top of polylines. I gave my billboards an opacity of 0.99 and the polylines have opacity of 1.0.

Hi Tamy,

The reason your seeing the polylines under the polygons is because the polylines are being drawn under the surface and the polygons are tessellated to be on the surface with a one degree granularity by default. Try using EllipsoidGeodesic to find the points on the surface.



Hi Dan,

I didn’t understand. Can you give me an example of how to use EllipsoidGeodesic to define the points of my polyline?

Thank you!