Errors with GroundPrimitives and PolygonGeometry

I am using a PolygonGeometry and trying to create GroundPrimitives with it. Currently I get the follwoing error if I try and add it to scene.primitives “DeveloperError: Not all of the geometry instances have GroundPrimitive support” The docs here https://cesium.com/docs/cesiumjs-ref-doc/GroundPrimitive.html state that GroundPrimitives should work with PolygonGeometries.
The code looks like this:

let polygon = new Cesium.PolygonGeometry({
    polygonHierarchy: new Cesium.PolygonHierarchy(
        Cesium.Cartesian3.fromDegreesArray(bounds)),
});
let instance = new Cesium.GeometryInstance({
    geometry: Cesium.PolygonGeometry.createGeometry(polygon),
    id: cell,
    attributes: {
        color: new Cesium.Color(rgb[0], rgb[1], rgb[2], 0.5),
    },
})

scene.primitives.add(new Cesium.GroundPrimitive({
    geometryInstances: instance,
}));

Is this a bug or is this not supported?

Hi,

for lines you can use GroundPolylinePrimitive and GroundPolylineGeometry,

see https://cesium.com/docs/cesiumjs-ref-doc/GroundPolylinePrimitive.html

Unfortunately I was trying to color regions with this so lines aren’t really what I’m going for.

It looks like you just need to pass the polygon directly without calling createGeometry. Full example:

var viewer = new Cesium.Viewer("cesiumContainer");
var scene = viewer.scene;

var polygon = new Cesium.PolygonGeometry({
  polygonHierarchy : new Cesium.PolygonHierarchy(
    Cesium.Cartesian3.fromDegreesArray([
      -115.0,
      37.0,
      -115.0,
      32.0,
      -107.0,
      33.0,
      -102.0,
      31.0,
      -102.0,
      35.0,
    ])
  )
});

var instance = new Cesium.GeometryInstance({
  geometry : polygon,
  attributes : {
    color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
  }
});
scene.primitives.add(new Cesium.GroundPrimitive({
  geometryInstances : instance,
  appearance : new Cesium.PerInstanceColorAppearance()
}));