E
E
Egor Rublev2016-08-26 10:20:59
JavaScript
Egor Rublev, 2016-08-26 10:20:59

How on the Yandex map, when you click on the button, open the balloon at the point?

How on the Yandex map, when you click on the button, open the balloon at the point?

obj.balloon.open() // Правильно?

myMap.setCenter(schools[glCity].filials[glFilial].coord, 16).balloon.open();


The first part of setCenter works, but the balloon does not open, how to open it correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor L, 2016-08-26
@FaloSun

<button id="show">Показать на карте</button>
<div id="map" style="width: 300px; height: 300px"></div>

ymaps.ready(init);
    var myMap;
    function init(){     
        myMap = new ymaps.Map ("map", {
            center: [55.76, 37.64],
            zoom: 7            
        })}
var el = document.getElementById("show");
el.addEventListener("click", showBal, false);
function showBal(){
myMap.balloon.open(myMap.getCenter(), { content: 'Hello Yandex!' }, { closeButton: true });
}

https://jsfiddle.net/Fullzero5/sejfkLf1/

F
forgotten, 2016-08-26
@forgotten

map.setCenter returns a Promise, not a map.
https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/ref...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question