Load GeoJson containing different geometry types?

1. A concise explanation of the problem you're experiencing.

I have a json file which I need to load using Cesium.GeoJsonDataSource.load, add the dataSource to viewer, and visualize features with custom styling.
I have managed to do this with simpler json files containing only one type of features e.g. only MultiLineStrings, only Polygons or only Points.
Now I have json which contains both Point and MultiLineStrings.

My question is, is it possible to load this kind of json file, and if it is then how to do it? Can I somwhow adjust the json file structure to fit the function requirements? Or there is no other way but to separate the file into multiple files according to feature type (which actually is not an option for me)?

See the code comments below.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

json file (actually much larger than this):

[
   {
      "name":"Building",
      "type":"FeatureCollection",
      "features":[
         {
            "type":"Feature",
            "geometry":{
               "type":"Point",
               "coordinates":[
                  15.947065173349179,
                  45.80343302400814
               ]
            },
            "properties":{
               ...
            }
         }
      ]
   },
   {
      "name":"Floor",
      "type":"FeatureCollection",
      "features":[
         {
            "type":"Feature",
            "geometry":{
               "type":"MultiLineString",
               "coordinates":[
                  [
                     [
                        15.947320004827413,
                        45.77868733628231,
                        0
                     ],
                     [
                        15.990385463305135,
                        45.778893374452025,
                        0
                     ]
                  ],
                  [
                     [
                        15.990385463305135,
                        45.778893374452025,
                        0
                     ],
                     [
                        15.990385463305135,
                        45.778893374452025,
                        5
                     ]
                  ],
                  [
                     [
                        15.947320004827413,
                        45.77868733628231,
                        5
                     ],
                     [
                        15.990385463305135,
                        45.778893374452025,
                        5
                     ]
                  ]
               ]
            },
            "properties":{
               ...
            }
         },
         {
            "type":"Feature",
            "geometry":{
               "type":"MultiLineString",
               "coordinates":[
                  [
                     [
                        15.947320303103405,
                        45.77868492920056,
                        -5
                     ],
                     [
                        15.990385759730152,
                        45.77889096725009,
                        -5
                     ]
                  ],
                  [
                     [
                        15.990385759730152,
                        45.77889096725009,
                        -5
                     ],
                     [
                        15.990385759730152,
                        45.77889096725009,
                        0
                     ]
                  ],
                  [
                     [
                        15.947320303103405,
                        45.77868492920056,
                        0
                     ],
                     [
                        15.990385759730152,
                        45.77889096725009,
                        0
                     ]
                  ]
               ]
            },
            "properties":{
               ...
            }
         }
      ]
   }
]

Code:

var promise = Cesium.GeoJsonDataSource.load('MY.json');
console.log('is this ok? ' + promise); // [object Object] *** Yes, it is.
promise.then(function(dataSource) { // I guess the error occurs here
    console.log('does this work?'); // because this line doesn't print anything
    viewer.dataSources.add(dataSource);
    var entities = dataSource.entities.values;

It throws error:

t {name: "RuntimeError", message: "Unsupported GeoJSON object type: undefined", stack: "Error↵ at new t (http://127.0.0.1:50145/Cesium/…http://127.0.0.1:50145/Cesium/Cesium.js:484:28359"}

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I have building centroid georeferenced, floors inside the building, rooms and objects in rooms. I have to make 3D visualization by extruding the footprints.
I have experience with this kind of task, I've done it already (
http://www2.geof.unizg.hr/~pmalec/App_Zagreb3DGIS/index.html )
But now I have more complex json file which contains all kinds of feature types together.
The ultimate goal is to enable the user to import their json file, click on building centroid which triggers the 3D visualization of building and objects inside. That's why I need the features to be all in one file.
Also, I know this can be done with 3DTiles, but for now json is requested.

4. The Cesium version you're using, your operating system and browser.

Cesium 1.39
Win7 64bit
Chrome 64.0.3282.186

Hi Paula,

That should be possible. I would recommend if it’s a lot of geometry to convert to 3D Tiles, though I know you said json is preferred

Double check whether your GeoJSON is valid. From the error, it sounds like on of your “type” values was not correctly specified.

Thanks,

Gabby

Hi Gabby,

thank you very much for your help. I have solved this problem.
Now I have another question.
I've seen a few topics on forum about this, but haven't really found an example/solution.
I'm working on application which uses cesium for visualizing 3D geometry (buildings etc).
I want to allow the users to drag & drop local geojson files to viewer, and the features need to be processed and styled before they appear, e.g. polygons extruded and colored.
I'm also considering the file explorer window for browsing local folders and loading geojson files that way. But still I prefer drag&drop.

Do you have any advice or can show me to the existing examples of this kind of task?

Best regards,
Paula

Hi Paula,

That’s a good question, but it’s beyond the scope of Cesium. You should be able to ask that in any forum that deals with Web UI. When you have the json, you should be able to load it in Cesium as you are familiar with.

Thanks,

Gabby

Paula - what was the solution you discovered for this RunTimeError? I am now running into the same thing and can't find a solution. The GeoJSON file I am trying to load looks okay.

Thanks!