Skip to main content

Fit bounds

You can fit the map to the given bounds by calling the fitBounds() method and passing the coordinates of the north-east and south-west points. You can view these points as the top-right and bottom-left corners of a rectangle around which the map will be centered.

map.fitBounds({
northEast: [82.927622, 55.033432],
southWest: [82.921622, 55.027432],
});

Padding

If the map has padding, it will be taken into account when centering the map. You can ignore the map padding by setting the skipMapPadding parameter to true.

map.fitBounds(
{
northEast: [82.927622, 55.033432],
southWest: [82.921622, 55.027432],
},
{
skipMapPadding: true,
},
);

You can also set padding by passing it as an argument when calling fitBounds(). In that case, the final padding when fitting the map will be the sum of two values: the map padding and the value you passed to fitBounds().

map.fitBounds(
{
northEast: [82.927622, 55.033432],
southWest: [82.921622, 55.027432],
},
{
padding: { top: 20, left: 60, bottom: 20, right: 60 },
},
);

Keep rotation angle

If you want to keep the current map rotation angle when fitting the map to bounds, you can set the considerRotation parameter to true.

map.fitBounds(
{
northEast: [82.927622, 55.033432],
southWest: [82.921622, 55.027432],
},
{
considerRotation: true,
},
);