Fix cameraForBounds not accounting for asymmetrical padding in center result#13647
Open
ragini-pandey wants to merge 1 commit intomapbox:mainfrom
Open
Fix cameraForBounds not accounting for asymmetrical padding in center result#13647ragini-pandey wants to merge 1 commit intomapbox:mainfrom
ragini-pandey wants to merge 1 commit intomapbox:mainfrom
Conversation
cameraForBounds was not accounting for asymmetrical padding when computing the camera center. The _extendAABB method was averaging left/right and top/bottom padding values, making the AABB extension symmetric. This meant the AABB center never shifted to account for padding asymmetry, so the resulting camera center was the same regardless of padding distribution. The fix uses the actual padding values (left, right, top, bottom) directly instead of averaging them. The available viewport width/height calculation remains the same (left + right = padL + padR), so zoom is unaffected for equal total padding. The AABB center now shifts to account for the difference between left and right (or top and bottom) padding. Fixes mapbox#13645
|
Hey, @ragini-pandey 👋 Thanks for your contribution to Mapbox GL JS! Important: This repository does not accept direct merges. All changes go through our internal review process. What happens next:
Please respond to any review comments on this PR. For more details, see CONTRIBUTING.md. |
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.
Launch Checklist
@mapbox/map-design-team@mapbox/static-apisif this PR includes style spec API or visual changes.@mapbox/gl-nativeif this PR includes shader changes or needs a native port.@mapbox/gl-nativeif this PR disables any test because it also needs to be disabled on their side.gl-nativeto groom in the MAPSNAT JIRA queue if this PR includes shader changes or features not present in the native side or if it disables a test that's not disabled there.Description
Fixes #13645
cameraForBoundswas not accounting for asymmetrical padding when computing the camera center. This was a regression introduced in v3.4.0.Root Cause
In the
_extendAABBmethod insrc/ui/camera.ts, the padding values were being averaged (symmetrized) before being applied to the AABB extension:This meant both sides of the bounding box received equal padding extension, so the AABB center (which determines the resulting camera center) never shifted regardless of padding asymmetry. The zoom was correctly affected because the total padding was preserved, but the center was not.
Fix
Use the actual asymmetric padding values directly:
The available viewport
width = tr.width - (left + right)andheight = tr.height - (top + bottom)calculations remain identical sinceleft + right = padL + padRin both cases. So the zoom calculation is unaffected. The difference is that the AABB now extends asymmetrically, shifting its center to properly account for the padding difference.Testing
asymmetrical left padding shifts center: verifies that left-only padding shifts the camera center and reduces zoomsymmetric padding does not shift center: verifies that equal padding on all sides does not shift the center (regression guard)