Skip to content

Clamp mercator horizon for high pitch angles#7352

Open
Timorleiderman wants to merge 1 commit intomaplibre:mainfrom
Timorleiderman:codex/fix-pitch-limit-bug-for-camera
Open

Clamp mercator horizon for high pitch angles#7352
Timorleiderman wants to merge 1 commit intomaplibre:mainfrom
Timorleiderman:codex/fix-pitch-limit-bug-for-camera

Conversation

@Timorleiderman
Copy link
Copy Markdown

Motivation

  • Prevent negative horizon values and ground disappearance when the camera pitch exceeds about 89 degrees in Mercator mode.
  • This surfaced in downstream testing in a web game that uses MapLibre for a near-ground missile-tracking camera, where high pitch angles caused the ground to disappear.

Description

  • Clamp the pitch to maxMercatorHorizonAngle inside getMercatorHorizon() in src/geo/projection/mercator_utils.ts before computing tangents.
  • Update src/geo/projection/mercator_utils.test.ts so 90 degree and 95 degree pitch cases expect a horizon of 0.
  • No public API or style-spec changes are included.

Testing

  • npm run test-unit -- src/geo/projection/mercator_utils.test.ts
  • Downstream manual validation in the web game: high-pitch ground view no longer loses the ground plane once the fix is applied.

Notes

  • This is a small Mercator projection bug fix, so I am opening it directly as a PR rather than starting with a separate issue.

@HarelM
Copy link
Copy Markdown
Collaborator

HarelM commented Mar 30, 2026

Thanks for taking the time to open this PR!
Can you share a before and after videos maybe? I'm keen to see how the game looks 😀

Can you also check if this breaks the functionality of allowing the camera to look above the horizon which was added a while back (with clamp to ground false)?

Cc: @NathanMOlson

@HarelM HarelM added the need more info Further information is requested label Mar 30, 2026
@NathanMOlson
Copy link
Copy Markdown
Collaborator

I do not think this change should be made in Maplibre GL JS. For me, allowing pitch angles above 90 is desired behavior. If the camera pitch is far enough above the horizon, the ground should be offscreen. The unit and render tests show the desired behavior.

My suggestion is to clamp the pitch angle outside the library if you don't want to allow pitch angles above 90. If you want the library to do it for you, take a look at maxPitch and see if that will serve your needs.

@HarelM
Copy link
Copy Markdown
Collaborator

HarelM commented Mar 30, 2026

Yeah, I kind of suspected this is what you would say. Makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need more info Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants