Polygon Clamp To Ground when terrain provider is used

Hi
Link to Sandcastle: Sandcastle link

`const viewer = new Cesium.Viewer(“cesiumContainer”, {
terrainProvider : Cesium.createWorldTerrain(),
sceneMode: Cesium.SceneMode.SCENE3D,
timeline: false,
homeButton: false,
fullscreenButton: false,
animation: false,
geocoder: false,
creditDisplay: false,
msaaSamples: 2
});

const geoJSON = {“type”:“FeatureCollection”,“crs”:{“type”:“name”,“properties”:{“name”:“urn:ogc:def:crs:EPSG::4326”}},“features”:[{“type”:“Feature”,“geometry”:{“type”:“MultiPolygon”,“coordinates”:[[[[146.390265449,-41.28804605],[146.384301071,-41.287233314],[146.38362103,-41.290082095],[146.384482621,-41.290199449],[146.383826976,-41.293221767],[146.389166403,-41.293882235],[146.388974991,-41.293433771],[146.388974991,-41.293433771],[146.390265449,-41.28804605]]]]},“properties”:{“Description”:null,“Label”:null,“Name”:“BOUNDARY”}},{“type”:“Feature”,“geometry”:{“type”:“MultiPolygon”,“coordinates”:[[[[146.389467845,-41.29137588],[146.398598169,-41.291093358],[146.398394091,-41.289088423],[146.398277399,-41.287823133],[146.398286404,-41.287359851],[146.398493275,-41.286626757],[146.398762258,-41.286304368],[146.399068821,-41.286067956],[146.399223129,-41.285933356],[146.400089334,-41.285534888],[146.400739229,-41.285297806],[146.401155672,-41.285082055],[146.401549414,-41.284677671],[146.401893332,-41.2839876],[146.39447634,-41.284341211],[146.391253322,-41.283910841],[146.390265449,-41.28804605],[146.389467845,-41.29137588]]]]},“properties”:{“Description”:null,“Label”:null,“Name”:“BOUNDARY”}}]};

const promise = Cesium.GeoJsonDataSource.load(geoJSON);

promise.then(function (dataSource) {
viewer.dataSources.add(dataSource);
viewer.flyTo(dataSource);
const entities = dataSource.entities.values;
for (let i = 0; i < entities.length; i++) {
const entity = entities[i];
entity.polygon.material = Cesium.Color.CYAN.withAlpha(0.5);
entity.polygon.outline = true;
entity.polygon.outlineColor = Cesium.Color.BLACK;
entity.polygon.heightReference =
Cesium.HeightReference.CLAMP_TO_GROUND;
}
});`

When the terrain provider is not used the polygon is formatted as follows:
image

However when the terrain provider is given the polygon is formatted as follows:
image

How can we achieve the same formatting with the TerrainProvider
Any help is highly appreciated
Thanks
Sakna

Hi, Are you looking for GeoJsonDataSource.clampToGround?
I’ve modified your example. But it will not work with the outline and explicit height.

  • Best Regards
1 Like

Is there any work around to get an outline and have it clamp to terrain?

Hi Jacky,

Thanks for this. I tried clamping to ground as well. However, when I try to set the outline it does not work.

Thanks

I don’t think so because there is a an issue registered.

Only thing that worked so far is not using a terrainProvider

You can do that if you separately create polygon and polyline entities instead of create them all at once though datasource. I’ve re-modified above sandcastle example to make it working.

1 Like

Thanks Jacky for this