Skip to content

Conversation

@larsmaxfield
Copy link
Contributor

@larsmaxfield larsmaxfield commented Dec 27, 2025

Changes:

  • Add constrain parameter to ITransform.apply() and therefore VerticalPerspectiveTransform.apply() and GlobeTransform.apply(). Was previously an optional parameter for MercatorTransform.apply().

  • Call constrain=true in Camera.migrateProjection()

Demo:

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Write tests for all new functionality.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov
Copy link

codecov bot commented Dec 27, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.46%. Comparing base (96f279d) to head (fc75465).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/geo/projection/globe_transform.ts 87.50% 1 Missing ⚠️
...c/geo/projection/vertical_perspective_transform.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6917      +/-   ##
==========================================
- Coverage   92.47%   92.46%   -0.01%     
==========================================
  Files         288      288              
  Lines       23849    23849              
  Branches     5061     5061              
==========================================
- Hits        22054    22053       -1     
- Misses       1795     1796       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@larsmaxfield
Copy link
Contributor Author

My approach here is to constrain the incoming transform when we migrate projections, thereby fixing #6892.

The constrain parameter already exists for TransformHelper.apply(), which (when true) calls constrainInternal to snap the transform's center and zoom into their respective valid ranges. constrain is also already available with MercatorTransform.apply(). If we make it available for all transforms, we can then call it when migrating transforms. That's what this approach does.

@larsmaxfield larsmaxfield marked this pull request as ready for review December 30, 2025 16:04
@larsmaxfield
Copy link
Contributor Author

Not sure if the test is in the best spot.

And perhaps Camera.migrateProjection() should simply call constrain=true instead of an opt-in parameter?

@HarelM
Copy link
Collaborator

HarelM commented Dec 30, 2025

Yeah, I'm not sure which is better...
I think that calling constrain explicitly sounds better...

@larsmaxfield
Copy link
Contributor Author

Stripped the constrain parameter from Camera.migrateProjection(). It now always calls constrain=true when applying the transform.

@HarelM
Copy link
Collaborator

HarelM commented Jan 2, 2026

Ping me when you'd like me to review this.

@larsmaxfield
Copy link
Contributor Author

It's ready! 👍

@HarelM
Copy link
Collaborator

HarelM commented Jan 2, 2026

I've added two minor comment, overall looks good.

@larsmaxfield larsmaxfield changed the title Add optional constrain to ITransform.apply() Add constrain parameter to ITransform.apply(); constrain when migrating projections Jan 5, 2026
Copy link
Collaborator

@HarelM HarelM left a comment

Choose a reason for hiding this comment

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

LGTM, THANKS!

@HarelM HarelM merged commit f813651 into maplibre:main Jan 5, 2026
26 checks passed
melitele pushed a commit to melitele/maplibre-gl-js that referenced this pull request Jan 9, 2026
…ng projections (maplibre#6917)

* Draft fix maplibre#6892: Add constrain to ITransform.apply

* Test map.setProjection() constrains zoom, center

* Add CHANGELOG entry

* Remove constrain param camera.migrateProjection()

Always call constrain=true on newTransform.apply()

* Require `constrain` param for `ITransform.apply()`

* Add @param tags to `ITransform.apply()`
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.

Map does not resize when switching from low-zoom globe to mercator but resizes after interaction

2 participants