Skip to content

feat(core): controller maxBounds#10105

Merged
Pessimistress merged 2 commits intomasterfrom
x/max-bounds
Mar 17, 2026
Merged

feat(core): controller maxBounds#10105
Pessimistress merged 2 commits intomasterfrom
x/max-bounds

Conversation

@Pessimistress
Copy link
Copy Markdown
Collaborator

@Pessimistress Pessimistress commented Mar 16, 2026

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 onViewStateChange callback example. The calculation of camera center (longitude /latitude /target) to satisfy such constraint is non-trivial.

This PR proposes a new controller option maxBounds that will automatically constrain camera center before onViewStateChange is called.

Change List

  • add maxBounds field to ControllerOptions
  • implementation for MapView
  • unit tests

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 16, 2026

Coverage Status

coverage: 91.064% (+0.007%) from 91.057%
when pulling e32f5e2 on x/max-bounds
into 0a3d347 on master.

Comment thread docs/api-reference/core/orthographic-view.md
/** 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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that rather than constraining to a box, the constraint would be to a circular region

@Pessimistress Pessimistress marked this pull request as ready for review March 17, 2026 17:11
@Pessimistress Pessimistress merged commit 9378745 into master Mar 17, 2026
5 checks passed
@Pessimistress Pessimistress deleted the x/max-bounds branch March 17, 2026 17:50
@chrisgervang chrisgervang added this to the v9.3 milestone Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants