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

Globe panning is reverted when North pole facing the user #5296

Open
jcolot opened this issue Jan 6, 2025 · 7 comments · May be fixed by #5330
Open

Globe panning is reverted when North pole facing the user #5296

jcolot opened this issue Jan 6, 2025 · 7 comments · May be fixed by #5330
Labels
bug Something isn't working globe Globe related issues PR is more than welcomed Extra attention is needed

Comments

@jcolot
Copy link

jcolot commented Jan 6, 2025

See video: moving the mouse on the left of the globe and to the bottom rotates the globe clockwise, unexpectedly:

Screen.Recording.2025-01-06.at.20.38.18.mov

A way to solve it would rely on something like versor (https://github.com/d3/versor), tracking the rotation with quaternions.

maplibre-gl-js version 5.0.0:

Expected Behavior

Homogenous panning all over the globe, non-blocking at the poles (for instance: https://observablehq.com/@jcolot/versor-panning)

Actual Behavior

Unexpected behaviours related to the poles

@HarelM
Copy link
Collaborator

HarelM commented Jan 6, 2025

I think this method was used in panTo and other programmatic movements but not with user interactions, feel free to open a PR to solve this.

@HarelM HarelM added bug Something isn't working PR is more than welcomed Extra attention is needed globe Globe related issues labels Jan 6, 2025
@jcolot
Copy link
Author

jcolot commented Jan 7, 2025

Reading the code, it might have been considered as a feature rather than a bug:

// We avoid using the "grab a place and move it around" approach from mercator here,

Still I think quaternion based dragging could be an option. I'll try to propose something.

@HarelM
Copy link
Collaborator

HarelM commented Jan 7, 2025

I wouldn't read too much into this comment. I do think the behavior is intentional in general and this this comment is there, but not the bug that is reported here, I don't think it is intentional.
I also think there's a similar bug in the southern pole, right?

@kubapelc
Copy link
Collaborator

kubapelc commented Jan 7, 2025

Hi, I'd like to add context to that comment, since I wrote the current globe controls.

In mercator, when you click and hold the map to pan it and the move the mouse, the place you originally grabbed will always stay under the cursor, which very intuitively emulates something like grabbing a piece of paper and moving it. Same thing happens with zoom: the place under the cursor stays under the cursor while zooming in or out. Let's call this the "mercator behaviour".

And globe does actually do both these things as well! But it is only limited to relatively high zoom levels, since if you were to try these approaches at the scale of the entire planet, it would not behave very well at all. If you used mercator-like panning on a planet, you would be unable to move the map more than 90° and you would get weird speed changes based on how close to the planet's horizon you grabbed the map. You would get similarly unpleasant results with zooming. (And you would also somehow need to handle the fact that the map is a sphere in the middle of the screen and there is a lot of pixels that do not have the map under them, so it is unclear what panning or zooming on these pixels would do.)

In the end I used a very simple control scheme for the low zoom level panning: left/right moves the map east/west, up/down moves it north/south. Also the speed of these movements is roughly matched to what you would get with mercator panning, but is only determined by the zoom level, not by where you grabbed the map. This is then smoothly blended into mercator behaviour as the zoom increases.

This issue, the effect of the map moving in seemingly the opposite direction than what is should when you grab the opposing hemisphere, is a direct result of the panning only being zoom dependant at low zooms. This is not ideal, but the current solution is also very simple and works well in I think all other cases. But there might very well be a better way of doing things.

jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 11, 2025
jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 11, 2025
jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 12, 2025
@kubapelc
Copy link
Collaborator

I looked at how other maps solve this and google maps in particular has a very simple and elegant solution: it just limits the view so that the user can never really see over the poles. I think that would be by far the simplest solution here as well.

@jcolot
Copy link
Author

jcolot commented Jan 14, 2025

Yes, Google Maps limits the pitch, but Google Earth offers a more flexible way of panning, allowing to pan over the poles. Possibly there could be two modes. Looking at the code, one issue I see is that the function setLocationAtPoint is solving an equation without allowing bearing to change. This equation will often have no solution near the poles. Allowing the bearing to change allows more solutions (any point on the surface can rotated to any other point on the surface of the globe). I have a draft PR using quaternions to find those solutions. An issue is that it's a bit less precise and it fails some tests which require a precision with epsilon 10ˆ-11 while I have 10ˆ-8 precision when allowing the bearing to change with quaternions, so I'm keeping the old way of doing thing in case the bearing is kept fixed (which I keep as the default).

#5330

Behaviour on my branch:

Screen.Recording.2025-01-14.at.14.43.39.mov

jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 14, 2025
@HarelM HarelM linked a pull request Jan 14, 2025 that will close this issue
8 tasks
jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 15, 2025
@kubapelc
Copy link
Collaborator

I intentionally avoided changing map bearing while the user is panning the map, because I find it very confusing when maps do that. But I'm definitely not opposed to having the quaternion-based control scheme as an option, though I'm glad you want to keep the current one as default. I tried your PR and it works nicely

jcolot added a commit to jcolot/maplibre-gl-js that referenced this issue Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working globe Globe related issues PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants