Adding entities in for-loop

Hi all,

I'm relatively new to Cesium, so this might be a very basic question.

I'm trying to make a web viewer which shows 3D buildings. I have a database of more than 6 million buildings, which I serve to the browser using a WFS (geoserver).

At first, I used the Cesium-plugin of the guys from Oslandia (https://github.com/Oslandia/cesium-buildings) to get my buildings on the map. However, it was running quite slowly for my database.

I'm now looking into using entities. The code below shows what I'm trying to do. The problem that I have is that (of course) my buildings do not have the same amount of coordinates. That is why I make the for-loop to create the coor-variable (which looks like [X1, Y1, X2, Y2, .. X1, Y1].

However, when I try to put this variable in the polygon hierarchy, it only takes up the first three numbers of the coor-variable as X, Y, Z.

Any ideas what is going wrong?
If you have any other suggestions...

load(request, function(xhr) {
   var geoJson = JSON.parse(xhr.responseText);
    
   for (var f = 0; f < geoJson.features.length; f++) {
      var building = geoJson.features[f];
      var coor = ;
      for (var i = 0; i < building.geometry.coordinates[0][0].length; i++) {
    coor.push(building.geometry.coordinates[0][0][i][0]);
    coor.push(building.geometry.coordinates[0][0][i][1]);
      }
      buildingList.push(viewer.entities.add({
         id : ID,
   polygon : {
      hierarchy : Cesium.Cartesian3.fromArray(coor),
      material : Cesium.Color.DARKORCHID.withAlpha(0.3),
      outline : true,
      outlineColor : Cesium.Color.BLACK,
      extrudedHeight : building.geometry.coordinates[0][0][0][2]
   }
      }));
   }

Thanks!
Wout

Hello Wout,

Cesium.Cartesian3.fromArray takes in an array of 3 numbers [x, y, z] and turns them into a Cartesian3 object…

Instead, I think you are looking for the Cesium.Cartesian3.fromDegreesArray function. This will take in an array for longitude, latitude positions in degrees and turn them into an array of Cartesian3 positions. That’s what the hierarchy option expects to be the input.

Hope this helps!

-Hannah

Thanks Hannah!!