fitBounds(
bounds:LngLatBoundsLike,options?:FitBoundsOptions,eventData?:any):this
Defined in: ui/map.ts:1394
Pans and zooms the map to contain its visible area within the specified geographical bounds. This function will also reset the map's bearing to 0 if bearing is nonzero.
Triggers the following events: movestart and moveend.
Parameters
| Parameter | Type | Description |
|---|---|---|
bounds |
LngLatBoundsLike |
Center these bounds in the viewport and use the highest zoom level up to and including Map.getMaxZoom that fits them in the viewport. Bounds will be taken in [sw, ne] order. Southwest point will always be to the left of the northeast point. |
options? |
FitBoundsOptions |
Options supports all properties from AnimationOptions and CameraOptions in addition to the fields below. |
eventData? |
any |
Additional properties to be added to event objects of events triggered by this method. |
Returns
this
Example
let bbox = [[-79, 43], [-73, 45]];
map.fitBounds(bbox, {
padding: {top: 10, bottom:25, left: 15, right: 5}
});
See
Fit a map to a bounding box