Skip to content

Add a padding option to map.getBounds #9265

Description

@johnarnfield

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions