Skip to content

Fix initial position of pointer-tracked popup #5811

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

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

Conversation

matthiasschwarz
Copy link

@matthiasschwarz matthiasschwarz commented Apr 25, 2025

Fixes the initial position of a pointer-tracked popup.
Currently the pointer has no position when added to the map, which results in it being displayed in the top left corner until the mouse is moved.
As initial position is now used the latest mouse position.

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.
  • Write tests for all new functionality.
  • Add an entry to CHANGELOG.md under the ## main section.

@matthiasschwarz matthiasschwarz force-pushed the fix-pointer-tracked-popup-initial-position branch from c44deab to 38ae220 Compare April 25, 2025 18:44
@HarelM
Copy link
Collaborator

HarelM commented Apr 25, 2025

I would like to avoid updating handler manger for this, if possible.
Can you think if a solution that can be encapsulated within the popup class?

Also, can you share a video of the issue?

@matthiasschwarz
Copy link
Author

Since there is no intended way to determine the current mouse position without using the mouse events. There is no solution that only encapsulates the popup class. The current mouse position must be cached in the map so that it is available when the popup is added to the map. An instance of a popup could be created during a mouse event. At this point, it would be too late to wait for the next mouse event.

Would you prefer tracking the mouse position in the map instance via an event listener?

Bug.mp4

Codesandbox

@HarelM
Copy link
Collaborator

HarelM commented Apr 26, 2025

but you are controlling when to add it to the map, why not set the initial location before adding it to the map?
I'm not following on the problem statement... What am I missing?

@matthiasschwarz

This comment was marked as resolved.

@matthiasschwarz
Copy link
Author

I found a workaround to provide an initial location. Calling trackPointer after adding the popup to the map allows to use an initial location.

popup
  .setLngLat(e.lngLat)
  .addTo(map)
  .trackPointer();

Codesandbox

There should probably an example about the usage especially since the documentation shows calling trackPointer before adding the popup to the map.

@HarelM
Copy link
Collaborator

HarelM commented Apr 26, 2025

To my understanding, track pointer should be used on the entire map and less as a hover effect on a marker.
Moreover, the concept of the popup changing position when the mouse moves over the maker is a very odd one from my point of view and a weird user experience.
I would consider simply adding a popup when mouse over and set the location of the marker to be a "staric" one.
But I might not be familiar with the relevant use case.
In any case, you are welcome to contribute a PR that updates the docs.

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

Successfully merging this pull request may close these issues.

2 participants