Skip to content

fix(android): fit zero-height camera bounds - #4353

Closed
RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-4050-zero-height-bounds
Closed

RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-4050-zero-height-bounds

Conversation

@RobJacobson

@RobJacobson RobJacobson commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #4050

Problem and root cause

Camera.setCamera({ bounds }) receives the two points from the issue at latitude 37. Android converts them into a CoordinateBounds with a nonzero longitude span and zero latitude span. That degenerate rectangle is passed to Mapbox's camera fitter, which returns a center but a zoom of 0. The map therefore falls back to a world view and the points do not fit the viewport. The issue's recording shows the failure; the reporter also observed that bounds with a nonzero latitude span fit correctly.

What changes

For camera fitting only, expand a zero-height rectangle symmetrically by 0.000001 degrees of latitude, clamped to valid latitude values. This gives the fitter a nonzero height without shifting the center or changing the longitude span. Non-degenerate bounds are passed through unchanged, and the original bounds remain unchanged for camera constraints.

The Android bounds path fits the resulting southwest/northeast points with cameraForCoordinates. It passes the resolved camera padding, bearing, and pitch through CameraOptions, with zero additional coordinatesPadding so padding is applied once.

Regression tests cover equal-latitude bounds, preservation of the center and original bounds, unchanged nonzero spans, latitude limits, and camera padding/bearing/pitch. The Android unit suite passes 15 tests across 5 suites. The Android example app was built and run with Mapbox Maps SDK v11 and the New Architecture; the issue coordinates fit around the Bay Area at a regional zoom instead of showing the world.

Checklist

  • I've read CONTRIBUTING.md
  • I updated documentation or generated code with yarn generate
  • I have tested the new feature on /example app.
    • In V11 mode/iOS
    • In New Architecture mode/iOS
    • In V11 mode/Android
    • In New Architecture mode/Android
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

The issue report includes the original failing screen recording. In the post-fix Android emulator run, Camera > Fit displayed the equal-latitude coordinates fitted around the Bay Area at a regional zoom.

Component to reproduce the issue you're fixing

const point1 = [-122.1, 37];
const point2 = [-121.2, 37];

camera.current?.setCamera({
  bounds: {
    ne: point1,
    sw: point2,
  },
});

- Expand zero-height bounds only for camera fitting to avoid zoom zero.
- Preserve viewport padding, bearing, and pitch during bounds fitting.
- Add regression tests for degenerate bounds and resolved padding.
@RobJacobson

Copy link
Copy Markdown
Contributor Author

Superseded by consolidated #4351. That PR now includes the Android degenerate-bounds handling and camera-padding behavior together, with regression tests for both #4050 and #4217. Keeping #4050 linked to #4351 so it closes when the combined fix merges.

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.

[Bug]: "setCamera" with bounds option doesn't fit these bounds (Android)

1 participant