LatLngBounds
Represents a rectangular geographical area on a map.
Usage example
var southWest = L.latLng(40.712, -74.227),
northEast = L.latLng(40.774, -74.125),
bounds = L.latLngBounds(southWest, northEast);
All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
map.fitBounds([
[40.712, -74.227],
[40.774, -74.125]
]);
Creation
Factory | Description |
---|---|
L.latLngBounds( |
Creates a LatLngBounds object by defining south-west and north-east corners of the rectangle. |
L.latLngBounds( |
Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds . |
Methods
Method | Returns | Description |
---|---|---|
extend( |
this |
Extend the bounds to contain the given point |
extend( |
this |
Extend the bounds to contain the given bounds |
pad( |
LatLngBounds |
Returns bigger bounds created by extending the current bounds by a given percentage in each direction. |
getCenter() |
LatLng |
Returns the center point of the bounds. |
getSouthWest() |
LatLng |
Returns the south-west point of the bounds. |
getNorthEast() |
LatLng |
Returns the north-east point of the bounds. |
getNorthWest() |
LatLng |
Returns the north-west point of the bounds. |
getSouthEast() |
LatLng |
Returns the south-east point of the bounds. |
getWest() |
Number |
Returns the west longitude of the bounds |
getSouth() |
Number |
Returns the south latitude of the bounds |
getEast() |
Number |
Returns the east longitude of the bounds |
getNorth() |
Number |
Returns the north latitude of the bounds |
contains( |
Boolean |
Returns |
contains( |
Boolean |
Returns |
intersects( |
Boolean |
Returns |
overlaps( |
Boolean |
Returns |
toBBoxString() |
String |
Returns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data. |
equals( |
Boolean |
Returns |
isValid() |
Boolean |
Returns |