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

Add a padding option to map.getBounds #9265

Open
johnarnfield opened this issue Feb 5, 2020 · 4 comments
Open

Add a padding option to map.getBounds #9265

johnarnfield opened this issue Feb 5, 2020 · 4 comments

Comments

@johnarnfield
Copy link

johnarnfield commented Feb 5, 2020

Motivation

Scenario:

  • Various DOM elements on the web page outside of the map are associated with geographical coordinates
  • When hovering over these elements, a marker should appear on the map
  • The map bounds potentially need to expand on mouse entering an element to accommodate markers outside of the current viewport. On mouse leaving an element, the map bounds then contract back to some pre-defined reference frame.
  • If the user has scrolled or zoomed the map, this pre-defined reference frame is updated to reflect the bounds when scrolling or zooming is complete so that on mouse leave, the map returns to the last position the user set, whilst still allowing temporary expansion to show extra markers whilst hovering on the respective DOM elements

Problem:

  • The user's desired bounds are stored with a call to map.getBounds()
  • The expanded view is set with a call to map.fitBounds(..., { padding: 20 }) so that markers are clearly visible in the viewport
  • This means that any call to fitBounds() after the call to getBounds() will expand the viewport by 20px, even if the marker falls within the current map bounds.

Without knowing how the extra 20px padding is added on in fitBounds(), it would be difficult to adjust this logic to prevent any zoom and scroll between getBounds and fitBounds calls.

Design Alternatives

  • The padding argument could be a global map setting. All calls to getting and setting bounds take it in to consideration.
  • getBounds could take an optional padding argument, which is subtracted from the actual bounds before being returned.
@arindam1993
Copy link
Contributor

From what I gathered it seems like #8638 would fit your usecase.
Its a slightly different implementation wherein it shifts the map's center of perspective to account for the persistent padding , unlike fitBounds which translates the camera but doesn't shift the center of perspective.

@goors
Copy link

goors commented May 14, 2020

Any update here maybe?

@andrewharvey
Copy link
Collaborator

The padding argument could be a global map setting. All calls to getting and setting bounds take it in to consideration.

👍 to this

@andrewharvey
Copy link
Collaborator

The padding argument could be a global map setting. All calls to getting and setting bounds take it in to consideration.

#10386 aims to close the gap in this regard, so that getBounds are the inset of the global map padding

For your described scenario, could you keep track of if you've just done a fitBounds with a padding? If you have then you know when you do getBounds() it's already got that padding factored in and subsequent fitBounds you'd not pass a padding as the bounds incorporate it? I might be missing something here though.

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

No branches or pull requests

5 participants