Determine BoundingRectangle from an EntityCollection for use in Camera.flyTo

Hello,

I'm looking for a way to determine the BoundingRectangle (or BoundingSphere) of an EntityCollection. When I was using straight Cesium, I could call Viewer.flyTo, but due to WebGL issues, I've moved to OL-Cesium (Openlayers for 2D, Cesium for 3D).

However, the OL-Cesium interface is lacking in some things, which requires me to access the Cesium 'innards' of OL-Cesium, and unfortunately, they do not use the Viewer class, but rather create a Scene, Camera, DataSourceDisplay, etc., separately.

So, I only have access to Camera.flyTo, which wants either a point or a BoundingRectangle.

My version of Cesium is 1.45.

Thanks.

Hi Dan,

I’m not sure what all you have access to in ol-cesium, but for reference, this is how we grab the bounding spheres in the Viewer class.

I think your best bet is to create a bounding sphere object for an individual entity from it’s vertices. You can create one bounding sphere from many with the BoundingSphere.fromBoundingSpheres function.

Thanks,

Gabby

Thanks Gabby! That worked perfectly...except for one minor detail:

I am performing this in the 'success' promise callback from the 'DataSourceCollection.add()' method of the DataSourceDisplay.dataSources property (e.g., dataSources.add(dataSource).then(function() { ...perform fly to...}); ). However, I have to throw in a few 'setTimeout()' calls, checking the DataSourceDisplay.ready property before performing the calculation. Otherwise, I get DeveloperErrors thrown (presumably because the dataSourceDisplay is not ready).

I looked for, but did not see, a callback on the DataSourceDisplay for 'ready' state. Is there a way for me to be notified of the 'ready' state?

Thanks,
Dan

Normally throughout the API, we have ready promises exposed. However in this case it doesn’t look there is one.

However, you can use when to wait on a ready property:

Cesium.when(dataSourceDisplay.ready, function () {

// callback code here

});

``