Tell me how you can transfer the zoom to the initialization of the map from the received geoobject. The problem is that the map is loaded with the initially set zoom, and then the second time it is loaded with bounds. How can I get a zoom from a geo object for mapy and initialize it there?

<script type="text/javascript"> ymaps.ready(init); function init(){ ymaps.geocode('Россия, Чебоксары', {results: 1}).then(function (res) { var firstGeoObject = res.geoObjects.get(0); var coords = firstGeoObject.geometry.getCoordinates(); var bounds = firstGeoObject.properties.get('boundedBy'); firstGeoObject.options.set('preset', 'islands#darkBlueDotIconWithCaption'); firstGeoObject.properties.set('iconCaption', firstGeoObject.getAddressLine()); var myMap; myMap = new ymaps.Map("block-map", { center: coords, zoom: 10 }); myMap.behaviors.disable('scrollZoom'); myMap.controls.add("zoomControl", {position: {top: 15, left: 15}}); myMap.geoObjects.add(firstGeoObject); myMap.setBounds(bounds, {checkZoomRange: true}); }); } </script> 
  • What for? If you have one single label (as is now the code), then just set a large scale right away and do not change the bounds of the map after adding the geoobject. - Reni

1 answer 1

 <script type="text/javascript"> ymaps.ready(init); function init(){ ymaps.geocode('<%=adres%>', {results: 1}).then(function (res) { var firstGeoObject = res.geoObjects.get(0); var coords = firstGeoObject.geometry.getCoordinates(); var bounds = firstGeoObject.properties.get('boundedBy'); firstGeoObject.options.set('preset', 'islands#darkBlueDotIconWithCaption'); firstGeoObject.properties.set('iconCaption', firstGeoObject.getAddressLine()); var myMap; myMap = new ymaps.Map("block-map", { center: coords, bounds: bounds, checkZoomRange: true }); myMap.behaviors.disable('scrollZoom'); myMap.controls.add("zoomControl", {position: {top: 15, left: 15}}); myMap.geoObjects.add(firstGeoObject); //myMap.setBounds(bounds, {checkZoomRange: true}); }); } </script>