util.requireCenterAndZoom
Static function.
Calculates the optimal center and zoom level of the map to display the passed area on the specified type of map. The zoom level will be within the available zoom range.
Returns the promise object, which will be confirmed by an object with the center and zoom fields, or will be rejected with an error.
{ vow.Promise } util.requireCenterAndZoom(mapType, bounds, containerSize[, params])
Parameters:
Parameter |
Default value |
Description |
— |
Type: String|MapType|map.ZoomRange Map type. Key string from mapType.storage, or an instance of the MapType class. Or the manager of map zoom coefficients for a specific map. |
|
— |
Type: Number[][] An area set in geographical coordinates. The first point contains the minimum values for latitude and longitude, and the second point contains the maximum values. |
|
— |
Type: Number[] Size of the map container. |
|
— |
Type: Object Parameters. |
|
true |
Type: Boolean If true, fit the area into the map; if false, fit the map into the area. |
|
0 |
Type: Number|Number[] Offset from the borders of the visible area of the map. If a single number is set, it is applied to each side. If two numbers are set, they are the horizontal and vertical margins, respectively. If an array of four numbers is set, they are the top, right, bottom, and left margins. |
|
false |
Type: Boolean When the value is "false", the zoom level is rounded down. |
* Mandatory parameter/option.
Example:
// Finding the optimal center and zoom level of the map..
ymaps.util.requireCenterAndZoom(
myMap.getType(),
[[50.531219,31.278264], [50.966841,31.964909]],
myMap.container.getSize()
).then(function (result) {
// Setting the optimal center and zoom level of the map.
myMap.setCenter(result.center, result.zoom);
});
Mandatory parameter/option.