Answer the question
In order to leave comments, you need to log in
How to set map scale automatically?
It is necessary that the zoom of the map be set as close as possible based on the marks, so that they all fit on the map and are visible.
I do it like this:
var barMap = new ymaps.Map('y-map', {
center: [55.72504493, 37.64696100],
zoom: 10,
behaviors: ['default', 'scrollZoom']
}), coords = [], barList = [someJsonData];
var collection = new ymaps.GeoObjectCollection();
for (var i in barList) {
coords = barList[i].coords.split(',');
collection.add(new ymaps.Placemark([coords[0], coords[1]], {
balloonContentHeader: '<a href="/bars/' + barList[i].link + '" target="_blank" title="Откроется в новом окне">' + barList[i].name + '</a>',
balloonContent: barList[i].address
}));
}
barMap.geoObjects.add(collection);
barMap.setBounds(collection.getBounds());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question