14 марта 2019
Нет комментариев
ymaps.ready(init); function init(){ var placemarks=[]; var myMap=new ymaps.Map("places_map",{ center:[59.952236, 30.299258], zoom:16, controls:['zoomControl'] }); Placemark=new ymaps.Placemark([59.952236, 30.299258],{ balloonContent:'address 1', hintContent:'name 1', },{ preset:'islands#redDotIcon' }); placemarks[1]=Placemark; myMap.geoObjects.add(Placemark); Placemark=new ymaps.Placemark([59.924406, 30.385793],{ balloonContent:'address 2', hintContent:'name 2', },{ preset:'islands#redDotIcon' }); placemarks[2]=Placemark; myMap.geoObjects.add(Placemark); Placemark=new ymaps.Placemark([59.952236, 30.299258],{ balloonContent:'address 3', hintContent:'name 3', },{ preset:'islands#redDotIcon' }); placemarks[3]=Placemark; myMap.geoObjects.add(Placemark); myMap.behaviors.disable('scrollZoom'); $('.places_map .places .item').on('click',function(){ $('.places_map .places .item').removeClass('active'); $(this).addClass('active'); $('.places_map .places').addClass('closed'); var cid=$(this).data('id'); myMap.setCenter(placemarks[cid].geometry.getCoordinates()); //placemarks[cid].balloon.open(); }); }
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU"></script> <div class="places_map"> <div id="places_map"></div> <div class="places"> <div class="items"> <div class="item" data-id="1">title 1</div> <div class="item" data-id="2">title 2</div> <div class="item" data-id="3">title 3</div> </div> </div> </div>
#places_map{ height:500px; }