我想通过点击获得地标标题或气球。这是我的功能:
function init() {
var myMap = new ymaps.Map("map", {
center: [55.76, 37.64],
zoom: 10
});
myMap.geoObjects
.add(new ymaps.Placemark([55.684758, 37.738521], {
iconCaption: '111 title',
balloonContent: '111 content'
}))
.add(new ymaps.Placemark([55.687086, 37.529789], {
iconCaption: '222 title',
balloonContent: '222 content'
}));
var objectManager = new ymaps.ObjectManager( {} );
objectManager.events.add(['click'], function(event){
var title = //get Placemark title
console.log(title);
});
myMap.geoObjects.add( objectManager );
}
UPD:我将此代码添加到地标:
balloonContentBody: '111 content<br><button class="selectPlacemark">Select</button>'
然后通过单击此按钮,我得到气球内容。但这不是我喜欢的解决方案