Using zoomTo
, the camera will zoom to and fit the bounds to whatever is currently visible on the timeline but in my case I want to fit the bounds to the entire datasource even if an entity is not currently visible.
My current approach is to do this:
const czml = [ packet, packet, packet, ...];
const arrayOfPositions = Cesium.Cartesian3.fromDegreesArray(
czml
.map((packet) => packet.polygon.positions.cartographicDegrees)
.flat()
// remove every third element that is supposed to be the height
.filter((_: any, index: number) => (index + 1) % 3 !== 0)
)
this.viewer.camera.setView({
destination: Cesium.Rectangle.fromCartesianArray(arrayOfPositions),
});
This approach feels hacky because to determine the determine of positions I need to iterate all of the CZML packets, then flatten out all the lng/lat values into a single array to do the above action.
Is there a better way to get all the lng/lat values of entities instead of iterating over all the CZML packets? The entities have a position property that is an instance of SampledPositionProperty
but it’s not clear how I could use that for anything or get the lng/lat values of the entity.
It feels wrong for me to have to extract the lng/lat values from the CZML but maybe there is a better approach. Something like datasource.computeViewRectangle()
(although that doesn’t exist).
Is there an alternate better way to achieve what I want without using any of the above approaches?