zoomTo fitting entities to screen

I am using viewer.zoomTo(entity) and have noticed that there is a lot of variation in the amount of screen space that the entities take up when the zoom is complete. Ideally, I would like the entities to fill the center portion of the screen. Are there any suggestions for improving the fitting?

For example in this sandcastle the largest dimension takes up about half of the screen. I would say this is the type of fit that I am expecting.

However in this sandcastle, the polygon takes up only a small portion of the screen. This is a bad fit and I would want the polygon to take up more screen space.

Without having it verified in all depth on the level of the code, I think that the zoomTo funcitonality basically always relies on a bounding sphere, in one way or another. So the answer to

Are there any suggestions for improving the fitting?

is: Yes! Compute better bounding spheres :slightly_smiling_face:

Here are the bounding spheres visualized:


I don’t know what’s going wrong in the second case. I stumbled over Entity's bounding sphere is incorrect (occasionally) · Issue #9690 · CesiumGS/cesium · GitHub while searching, but that might be a red herring. However, here are the corresponding sandcastles, with some (hacky) showBoundingSphere(entity) function to visualize them:

Working:

Not working:

Thanks for the breakdown @Marco13 . In some offline discussions @Gabby_Getz mentioned this is probably due to tall shadow volumes and may be resolved by Remove the dependency on ApproximateTerrainHeights from GroundPrimitive and GroundPolylinePrimitive · Issue #8480 · CesiumGS/cesium · GitHub