GeoJSON – Converting Entities to GeoJSON with Cesium

cesiumgeojsonturf

I know there is a way to load entities from a GeoJSON using GeoJsonDataSource but is there any way to do the opposite: get any entity as a GeoJSON representation?

My goal is to use Turf.JS with Cesium.JS geometries.

Best Answer

Here you have a solution to export to json and for export it to kml.

Everything is obtained from this official thread of Cesium.

They are links that talk about the question and there isn't method to do that native in Cesium, such as exportKml.

To implement exportJson (for example), it should be done using pure js or Turf as you did.

You can use the exportKml code to help create the result you are looking for.

Another way you can try is to export to KML and convert the result xml to json. For example using togeojson

Cesium.exportKml({
     entities: entityCollection
 })
  .then(function(result) {
    // The XML string is in result.kml
    // Convert Kml to GeoJSON (It's just an idea)
       json = toGeoJSON.kml(result)
  });