Skip to content

Conversation

jacobtoye
Copy link
Member

Updated LatLngBounds to provide the functionality to extend the bounds by a %.

Use case
When a group of markers are displayed on the map sometimes they touch the edge of the window. This can mean that part of the marker is not visible. This could be true for other items that are displayed on the map.

The way I am using it is I have an array of markers that has a LatLngBounds to represent the bounds of those markers. When the map is loaded I want to show all markers in the map viewport (without any right on the edge).

To test you can add the following code to the map.html debug file (I didn't think a minor function would deserve a new debug file so didn't commit it).

<button id="padbounds">Pad bounds by 5%</button>

function padBounds () {
    map.fitBounds(map.getBounds().padBounds(0.05));
}
L.DomUtil.get('padbounds').onclick = padBounds;

mourner added a commit that referenced this pull request Feb 15, 2012
Ability to pad a LatLngBounds by a %
@mourner mourner merged commit 4308b89 into Leaflet:master Feb 15, 2012
@mourner
Copy link
Member

mourner commented Feb 16, 2012

Cleaned up the method a bit and renamed to just LatLngBounds pad.

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.

2 participants