Answer the question
In order to leave comments, you need to log in
How to dynamically add balloons to a Yandex map?
Tell me who solved this problem and who knows the way out of it.
There is a Yandex map (2.1) and a filter. When the filter is running, the coordinates of the object come from the server. How to dynamically add these elements as balloons to the created map?
At the initial load, everything is clear, an Ajax request passes in the init function, and in the loop we display balloons on the map.
myMap = new ymaps.Map('map', {center: [59.918154,30.305578], zoom: 11});
myMap.controls.remove('trafficControl').remove('searchControl').remove('typeSelector');
// создадим массив геообъектов
$.ajax({
url:'/ajax/maps',
success:function(data){
for(var i = 0;i<=data.length;i++){
var mapX = data[i][0];
var mapY = data[i][1];
var dop = data[i][2];
var address = data[i][3];
var pm = new ymaps.Placemark([mapY, mapX], {
iconContent: "",
hintContent:address,
balloonContent: dop
});
myMap.geoObjects.add(pm);
}
}
});
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