LatLngBounds
Quick answer
L.latLngBounds defines an axis-aligned geographic rectangle from a south-west and north-east corner, powering fitBounds, containment tests and WMS bounding box strings. It can also absorb many points into a single extent through repeated extend calls. Corners may be passed in either order because the constructor normalizes them.
L.latLngBounds( corner1 , corner2 ) → LatLngBounds
Key points
- pad returns a new expanded bounds object rather than modifying the original.
- overlaps ignores shared edges and corners, while intersects counts any contact.
- toBBoxString emits west, south, east and north values for WMS requests.
Example
var pts = [
[39.907359, 116.391263],
[39.934, 116.432],
[39.881, 116.355]
];
var bounds = L.latLngBounds(pts);
map.fitBounds(bounds, {
padding: [24, 24],
maxZoom: 15
});var extent = L.latLngBounds();
geojson.features.forEach(function (feature) {
L.geoJSON(feature).getLayers().forEach(function (layer) {
if (layer.getBounds) {
extent.extend(layer.getBounds());
}
});
});
console.log(extent.toBBoxString());
Notes
- An empty L.latLngBounds has isValid false and makes map.fitBounds fail.
- Ranges spanning the antimeridian expand into a rectangle covering the whole world.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). LatLngBounds. https://www.jingweizhi.com/en/leaflet/api/latlng-bounds.html (accessed 2026-11-03).