feat(core): controller maxBounds#10105
Merged
Pessimistress merged 2 commits intomasterfrom Mar 17, 2026
Merged
Conversation
felixpalmer
approved these changes
Mar 17, 2026
| /** Enable inertia after panning/pinching. If a number is provided, indicates the duration of time over which the velocity reduces to zero, in milliseconds. Default `false`. */ | ||
| inertia?: boolean | number; | ||
| /** Bounding box of content that the controller is constrained in */ | ||
| maxBounds?: [min: [number, number], max: [number, number]] | [min: [number, number, number], max: [number, number, number]] | null; |
Collaborator
There was a problem hiding this comment.
Thinking outside the box…. could this be a callback to enable constraining to a more flexible region? e.g. a circle, or a non-axis aligned rect?
Collaborator
Author
There was a problem hiding this comment.
The proposed behavior calculates min/max lng/lat in a flat viewport, discarding rotation information. Otherwise the map might zoom itself as you rotate, which is wierd.
Collaborator
There was a problem hiding this comment.
I meant that rather than constraining to a box, the constraint would be to a circular region
e8181b7 to
485b7b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is a common requirement in apps to constrain the viewport to a bounding box, and prevent user from zooming/panning outside of the area where data is available. Currently this must be done by supplying a custom
onViewStateChangecallback example. The calculation of camera center (longitude /latitude /target) to satisfy such constraint is non-trivial.This PR proposes a new controller option
maxBoundsthat will automatically constrain camera center beforeonViewStateChangeis called.Change List
maxBoundsfield toControllerOptionsMapView