cesium icon indicating copy to clipboard operation
cesium copied to clipboard

flyTo with Rectangle doesn't play well with terrain

Open atlight opened this issue 5 years ago • 3 comments

The Camera.flyTo({ destination: Rectangle }) function flies the camera so that the specified Rectangle is in view.

Rectangles are lat/long based objects without height information, and the flyTo function always seems to use a height of 0. If, when using terrain, you call flyTo with a small rectangle in a high-altitude area, the camera will be placed beneath the terrain, and the user sees astronomy instead of the intended area.

The other fly functions aren't able to handle this scenario well either:

  • Camera.flyTo({ destination: Cartesian3 }) flies the camera itself to a specific location. Using this to fly to a rectangle would require a lot of precomputation, duplicating logic already in Cesium.
  • Camera.flyToBoundingSphere with BoundingSphere.fromCornerPoints. This isn't convenient if you want to view a rectangular area on a rectangular viewport. The area will indeed appear in view, but it won't fill the screen.
  • Viewer.flyTo. This assumes you have an Entity, DataSource etc that you want to zoom to (maybe I want to zoom to an arbitrary area), and also that you are using Viewer (maybe I am using CesiumWidget).

I can think of three potential solutions to this problem, from most to least general:

  • Extend Camera.flyTo to fly to OrientedBoundingBox objects.
  • Add a height parameter to Camera.flyTo, allowing the Rectangle to be given a single flat height. This would require minimal code change, mainly to the 0.0 values here.
  • Add a toTerrain boolean option to Camera.flyTo, where Cesium samples appropriate terrain heights and zooms to the given Rectangle on the terrain. This is admittedly a bit less general, but would still likely be useful to many consumers.

atlight avatar Aug 20 '20 10:08 atlight

I think my preferred approach here would be to add a height parameter to Camera.flyTo since it's the simplest but also gives the developer the most flexibility. For example, this would allow you to easily do the sample terrain heights before flying (do you sample the center, the 4 corners of the rectangle? Up to you) and you'd probably want the height to be not directly at that terrain height, but some offset above that.

Curious to hear what others think.

OmarShehata avatar Aug 20 '20 13:08 OmarShehata

We already have a private function computeFlyToLocationForRectangle which takes a rectangle and scene and samples the terrain and produces a final Cartographic position that can then be passed to the camera. It's used by both the Viewer for zooming to imagery layers and the Geocoder for zooming to rectangular results.

The easy way out would just be to expose this function, since it does exactly what you want for rectangles.

Longer term, I think we definitely need to revisit the Camera API, but I think there are lots of things we need to think about in this regard.

mramato avatar Aug 20 '20 23:08 mramato

I would really appreciate if computeFlyToLocationForRectangle could be exposed!

anne-gropler avatar Jun 11 '25 12:06 anne-gropler