Getting error while reading entities from datasource

Hello Support,

Am getting an error while getting total entities in Geojson file.

My code is

var dataSource = Cesium.GeoJsonDataSource.load(‘data/electrical_ug_oh_ht_cable_geo.geojson’, {
‘stroke’: new Cesium.Color(1, 0, 0, 1.0),

});

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

alert(dataSource.entities.values);

When am printing the total enties in a datasource am getting below error. But I can see the geojson data on the globe.

“Unable to get property ‘values’ of undefined or null”.

Where is the mistake am doing in the above code?

Regards,

Tharak.

Because GeoJsonDataSource is asynchronous, it returns a Promise that will resolve when the data is loaded. So you need to use .then before accessing any of the data.

https://cesiumjs.org/Cesium/Build/Documentation/GeoJsonDataSource.html?classFilter=GeoJsonDataSource#.load

Maybe

  1. Your json is invalid
  2. Your data path is invalid.

Thanks

Thank you scott. It is working now.

And I have one more question. Am loading geojson files dynamically. After loading all geojosn file am applying style for earch entity in the geojson datasource. Now my question is how to identify entity type like it is polyline entity or polygon entity?

Id there any way to indentity datasource is polygon or polyline type?

Regards,

Tharak.