if 2D json CLAMP_TO_GROUND

Hello,

I have json data in 2D and 3D. How lead with 2D ou 3D coordinates to CLAMP_TO_GROUND id 2D?

See my example:

viewer.dataSources.dataSourceAdded.addEventListener(function(collection,dataSource){
  
  if (Cesium.defined(dataSource)) {
    
    var entities = dataSource.entities.values;
    for (var i = 0; i < entities.length; i++) {

      var entity = entities[i];
      //console.log(dataSource.entities.values[i]);

      if (Cesium.defined(entity.polygon)) {
        console.log("...polygon");
        
        entity.polygon.material = createCallback(entity);
        entity.polygon.width = 1;
        //entity.polygon.perPositionHeight = true;
        entity.polygon.outlineColor = Cesium.Color.RED;
        entity.polygon.outlineWidth = 1;
        entity.polygon.granularity = Cesium.Math.RADIANS_PER_DEGREE;
        
        if (data2d == true){entity.polygon.extrudedHeight = 2500;}
        else {entity.polygon.extrudedHeight = 0;};
      }
    }
  }

});

Thanks

So one has heights and the other doesn’t?

Remove

if (data2d == true){entity.polygon.extrudedHeight = 2500;}
else {entity.polygon.extrudedHeight = 0;};

``

and instead set perPositionHeight to true if your position data has height values.

Hello Gabby,

But how check is coordinates are 2D or 3D? coordinates entity...

Thanks

An entity can use 2D or 3D coordinates. It would depend on your data, not the entities. See the Polygon Sandcastle example.

Hello Gabby,

This is my viewer:

  var viewer = new Cesium.Viewer('cesiumContainer', {
    terrainProvider: Cesium.createWorldTerrain({
      requestWaterMask : true,
      requestVertexNormals : true
    }),
    sceneMode: Cesium.SceneMode.SCENE3D,
    animation: false,
    timeline: false
  });

If you replace it on: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Polygon.html

My problem is 'Blue polygon with holes'... with zoom start disapears :frowning:

Thanks

Found the problem...

After load my 2D data, I print coordinates on console and I get cartographic position coordinates with height=0 (OK) and some data with height=9.313225746154785e-10 (NOT OK)

Why this value of 9.313225746154785e-10 on 2D data?

Thanks