Fit view to a 3D axis-aligned bounding box
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Motivation
For an indoor visualization use case, I'd like to be able to fit the map view to a building's 3D bounds – see the following screenshot:
I cannot currently do that, as fitBounds() only lets me fit 2D bounding boxes.
Design
AFAICT the core functionality is already there in the form of Camera#_cameraForBox() – but it's only used for fitting an elevation box at non-zero pitch ATM.
Possible options I can think of:
-
Expose
minAltitude/maxAltitudedirectly inFitBoundsOptions. -
Extend
LngLatBounds/LngLatBoundsLiketo accept three-tuples of(lng, lat, alt)– wherealtis in meters. (I guess this is both the more involved and the more questionable API design choice as the vertical unit of measurement differs from the horizontal ones.) -
As the ray marching algorithm iteratively changes the transform's
center,zoom,pitchandbearing, it may be better to expose this functionality as a new method onCamera(and transitively onMap), similarly to howfitScreenCoordinates()(the only call-site for_cameraForBox()) is also a distinct method.
Mock-Up
(Original code taken from https://docs.mapbox.com/mapbox-gl-js/example/fitbounds/).
Option 1 (exposing minAltitude / maxAltitude in FitBoundsOptions):
map.fitBounds([
[32.958984, -5.353521], // southwestern corner of the bounds
[43.50585, 5.615985], // northeastern corner of the bounds
{
minAltitude: 0,
maxAltitude: 100
}
]);
Option 2 (LngLatBoundsLike accepts three-tuples):
map.fitBounds([
[32.958984, -5.353521, 0], // southwestern corner of the bounds (at 0 altitude)
[43.50585, 5.615985, 100], // northeastern corner of the bounds (at 100m altitude)
]);
Option 3 (expose a new method on Camera and Map):
map.fitBounds3D(
[32.958984, -5.353521], // southwestern corner of the bounds
[43.50585, 5.615985], // northeastern corner of the bounds
{
minAltitude: 0,
maxAltitude: 100
}
)
Would you accept a PR once the design is decided on?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/ui/camera.js, especially Camera#_cameraForBox(), and compare its existing fitScreenCoordinates() call path with fitBounds() and FitBoundsOptions. Decide the public API for 3D axis-aligned bounds, then verify that the selected entry point fits the requested minimum and maximum altitude around the building view.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100