Skip to main content

Fitting bounds

To fit all the required objects in the map, call the fitBounds() method, which will automatically change the center and zoom level of the map according to the specified bounds. The method accepts two parameters: the coordinates of the north-east point (the upper-right corner of the map) and the coordinates of the south-west point (the lower-left corner of the map).

map.fitBounds({
northEast: [37.618655, 55.771005],
southWest: [37.612655, 55.765005],
});

Padding

If the paddings are set for the map, they will be taken into account when fitting the map to bounds. To ignore paddings, specify the skipMapPadding parameter:

map.fitBounds(
{
northEast: [37.618655, 55.771005],
southWest: [37.612655, 55.765005],
},
{
skipMapPadding: true,
},
);

You can specify additional paddings using the padding parameter. These paddings will be added to the paddings specified for the map:

map.fitBounds(
{
northEast: [37.618655, 55.771005],
southWest: [37.612655, 55.765005],
},
{
padding: { top: 20, left: 60, bottom: 20, right: 60 },
},
);

Keeping rotation angle

To keep the map rotation angle when fitting the map to bounds, specify the considerRotation parameter:

map.fitBounds(
{
northEast: [37.618655, 55.771005],
southWest: [37.612655, 55.765005],
},
{
considerRotation: true,
},
);