Get property from geoJSON feature

I am testing the sandbox for the geoJSON import on my local machine (Cesium 1.96), but I am not able to get the value of a feature property as described there.

If I log the value as described (full_id is one of my properties) with

console.log(entity.properties.full_id)

I get

image

I can get the actual value with

console.log(entity.properties.full_id._value)

but I am not sure it is the correct way.

Hi @mioruggieroguida,

pls share some of your code with us, it’s hard to answer such a question without it.
E.g. when / where in your code you try to log the value?

Best, Lennart

Hi @lennart.imberg,

It is the same code from the sandbox, but with a different file (attached)
BeaconsfieldRoad.geojson (20.2 KB)

and console.log(entity.properties.full_id); instead of entity.polygon.extrudedHeight.entity.properties.Population / 50.0;

Here it is

Cesium.Ion.defaultAccessToken =
  "ion_token";

const viewer = new Cesium.Viewer("cesiumContainer");

let starting_coordinates = [51.6106269733474, -0.1459970790756092];
viewer.camera.flyTo({
  destination: Cesium.Cartesian3.fromDegrees(starting_coordinates[1], starting_coordinates[0], 1000),
  orientation: {
    heading: Cesium.Math.toRadians(0.0),
    pitch: Cesium.Math.toRadians(-55.0),
  },
});
//Example 3: Apply custom graphics after load.
//Seed the random number generator for repeatable results.
Cesium.Math.setRandomNumberSeed(0);

const promise = Cesium.GeoJsonDataSource.load("BeaconsfieldRoad.geojson");
promise
.then(function (dataSource) {
  viewer.dataSources.add(dataSource);

  //Get the array of entities
  const entities = dataSource.entities.values;

  const colorHash = {};
  for (let i = 0; i < entities.length; i++) {
    //For each entity, create a random color based on the state name.
    //Some states have multiple entities, so we store the color in a
    //hash so that we use the same color for the entire state.
    const entity = entities[i];
    const name = entity.name;
    let color = colorHash[name];
    if (!color) {
      color = Cesium.Color.fromRandom({
        alpha: 1.0,
      });
      colorHash[name] = color;
    }

    //Set the polygon material to our random color.
    entity.polygon.material = color;
    //Remove the outlines.
    entity.polygon.outline = false;

    //Extrude the polygon based on the state's population.  Each entity
    //stores the properties for the GeoJSON feature it was created from
    //Since the population is a huge number, we divide by 50.
    entity.polygon.extrudedHeight =
      entity.properties.Population / 50.0;
  }
})
  .catch(function (error) {
    //Display any errrors encountered while loading.
    window.alert(error);
  });

I am using Cesium 1.96


<script src="https://cesium.com/downloads/cesiumjs/releases/1.96/Build/Cesium/Cesium.js"></script>
<link href="https://cesium.com/downloads/cesiumjs/releases/1.96/Build/Cesium/Widgets/widgets.css" rel="stylesheet" />

I’ve just checked with my own GeoJSON data and I have the same “problem”.
Are you creating your geoJSON with QGIS, too?

It looks like
A) … the GeoJsonDataSource.load promise does not handle the JSON object literal (thats where the properties inside the GeoJSON are) corectly, or

B) QGis does not create “Cesium-friendly” geojson.

So you have to use _value. (at least for now and in my opinion).

Best Lennart

1 Like

Thanks.

That file was generated with QGIS. I have also tested another file generated directly from spatialite with ExportGeoJSON2 and it is the same issue.

Just to add: the console.log() gets executet “inside” a promise, so maybe that is the problem. Sadly, im not overly familiar with JS promises. So maybe some others can help here?

Works as expected for me using Cesium 1.97 in Chrome 105.0.5195.102.

Scott