Problem with polyline clamping and terrain exaggeration and tips to display polygon outline

Hello,

I’m reaching the community again to share a bug with primitive ground polylines.
First here is a little example with a polyline roughly drawn around France :

const scene = viewer.scene;

// 5 points around France, convert cartographic coordinates into cartesian
const ellipsoid = Cesium.Ellipsoid.WGS84;
const cartographicCoordinates = [
    {longitude: Cesium.Math.toRadians(2.8465697911694736), latitude: Cesium.Math.toRadians(51.249246077764674)},
    {longitude: Cesium.Math.toRadians(8.694815915102126), latitude: Cesium.Math.toRadians(48.73467348496521)},
    {longitude: Cesium.Math.toRadians(6.509891288704511), latitude: Cesium.Math.toRadians(43.065568872878444)},
    {longitude: Cesium.Math.toRadians(-1.517843342178658), latitude: Cesium.Math.toRadians(43.28560238993496)},
    {longitude: Cesium.Math.toRadians(-4.536912164037633), latitude: Cesium.Math.toRadians(48.44672602414642)},
]

const cartesianPoints = []
for (let point of cartographicCoordinates) {
    cartesianPoints.push(ellipsoid.cartographicToCartesian(new Cesium.Cartographic(point.longitude, point.latitude, 0)))
}

const polylineGeometry = new Cesium.GroundPolylineGeometry({
    positions: cartesianPoints,
    width: 5.0,
    loop: true,
});

const instance = new Cesium.GeometryInstance({
    geometry: polylineGeometry,
    id: "polygonInstance",
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN)
    }
});

// Using groundPrimitive to clamp the entity automatically to the terrain
const primitive = new Cesium.GroundPolylinePrimitive({
    geometryInstances: instance,
    appearance: new Cesium.PolylineColorAppearance({
        translucent: false,
    })
});

scene.groundPrimitives.add(primitive);

And here is the result :
with exaggeration factor = 1

with exaggeration factor = 4.1

As we can see, the polyline goes under the terrain in this case.

The question has already been raised in this post but nobody answered : Polyline disappeared when terrainExaggeration is not 1.

My goal is to mimic a polygon outline that clamp nicely to the terrain, is there any other way I could achieve that ?
I already tried using entities, but the outline does not clamp, this is a well known issue : Polygons Don't Have Outline Even When Terrain Server Isn't Present · Issue #4659 · CesiumGS/cesium · GitHub
Primitives like polygon can clamp nicely but only the surface, I can’t have only the outline.

And it seems like other primitive types (like PolygonOutlineGeometry) can’t clamp to the ground.

Hi @AlainCoserariu,

Thanks for reporting this issue. It’s definitely an annoying bug - one that has been noted here, as well. And it looks like it’s just one of several issues with vertical exaggeration.

I’m not sure of any workarounds, so I would suggest +1’ing the above issues to help get them some more attention. And if you’d like, you can contribute to CesiumJS by investigating, proposing, or even implementing a fix!

Best,

Matt