Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Circle Layer hitbox in Globe projection mode #5599

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

lucaswoj
Copy link
Contributor

@lucaswoj lucaswoj commented Mar 7, 2025

This PR fixes #5255 where circle layers have extremely small hitboxes when using the "globe" projection at low zoom levels.

Problem

When using Circle layers in the "globe" projection, queryRenderedFeatures only works over tiny fraction of the circle rather than the entire rendered feature. This makes interactive maps with circle layers frustrating to use at low zoom levels.

Root Cause

The issue stems from the pixelPosMatrix calculation in queryRenderedFeatures. The implementation wasn't properly handling globe projection, leading to incorrect hit testing calculations in CircleStyleLayer#queryIntersectsFeature.

Solution

This PR updates the getPixelPosMatrix function in query_features.ts to account for the proper scale transformation when mapping between screen space and tile units. Deeper architectural changes are needed to say that queryRenderedFeatures fully supports the globe projection but this addresses the immediate bug with a minimally intrusive fix.

Testing

  • Added integration tests that verify circle hit testing works correctly in Globe projection
  • Added a dedicated example HTML file demonstrating the functionality
  • Verified both exact center hits and edge hits work correctly at various zoom levels

This should make Circle layers properly interactive in all projection modes.

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.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores. These should not change as a result
  • Add an entry to CHANGELOG.md under the ## main section.

@lucaswoj lucaswoj changed the title Query globe 5255 Fix Circle Layer hitbox in Globe projection mode Mar 7, 2025
@lucaswoj lucaswoj marked this pull request as draft March 7, 2025 23:06
@lucaswoj lucaswoj marked this pull request as ready for review March 7, 2025 23:19
@lucaswoj
Copy link
Contributor Author

lucaswoj commented Mar 7, 2025

@HarelM @kubapelc Would you take a look at this PR and let me know what you think? I understand a more in depth fix is needed to "fully" support queryRenderedFeatures in the globe projection but this is a non-intrusive fix the bug that's affecting users right now.

@@ -75,10 +76,11 @@ function getPixelPosMatrix(transform, tileID: OverscaledTileID) {
const t = mat4.create();
mat4.translate(t, t, [1, 1, 0]);
mat4.scale(t, t, [transform.width * 0.5, transform.height * 0.5, 1]);
if (transform.calculatePosMatrix) { // Globe: TODO: remove this hack once queryRendererFeatures supports globe properly
if ('calculatePosMatrix' in transform) { // Globe: TODO: remove this hack once queryRendererFeatures supports globe properly
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have pixel to tile units support both mercator and globe and remove this if statement and todo?

@HarelM
Copy link
Collaborator

HarelM commented Mar 8, 2025

When I looked at this feature I saw that the offset code is also broken.
Did you see what results you get for offset?
In any case, this is better than current state so I'll probably merge this anyway.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented Mar 8, 2025

Thanks for the review!

I’ll look into whether circle-offset works on the glove projection, write a quick blurb on what it’d take to fully resolve the TODO comment, and get back to you early next week.

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.

Globe Projection Bug: Circle Layers have smaller hover/click area than visually represented
2 participants