Answer the question
In order to leave comments, you need to log in
How to calculate the center and zoom for Yandex maps?
Good afternoon, I ran into a problem, I used to somehow solve it, now I can’t find it anymore, and the old solutions that I google don’t work.
There are n points, how to calculate the bounds and zoom for them so that they all fit on the map?
<YMaps>
<Map
defaultState={{
zoom: 10,
center: houses[0].position,
}}
>
{houses.map((house) => <Placemark geometry={house.position} key={house.key} />}
</Map>
</YMaps>
Answer the question
In order to leave comments, you need to log in
For me and people like me in the future:
1. Add all labels to the map
2. Get the bounds of the map instance: myMap.geoObjects.getBounds()
3. Assign it to the map instance, with options for zoom, padding, etc:
myMap.setBounds(
myMap.geoObjects.getBounds(),
{
checkZoomRange: true,
zoomMargin: 9
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question