D
D
dmignir2014-06-10 00:50:09
JavaScript
dmignir, 2014-06-10 00:50:09

Yandex Maps API getting placemark from balloon

Firework! There was a problem while studying Yandex.Maps api, please help.
There is a cycle that creates points on the map (an iterator - index), the question arose, when opening a balloon - how to get a placemark - the parent of this balloon? Those. the balloon must be somehow attached to the point after all.
I am looking for a normal method, because the only one that came to mind was the search for a point by the coordinates of the balloon.

var placemark = new ymaps.Placemark([mass[index].latitude, mass[index].longtitude], {
            iconContent: mass[index].name,
            hintContent: "test",
            Index: index
        }, {
            balloonPanelMaxMapArea: 0,
            draggable: "true",
            preset: "islands#blueStretchyIcon",
            openEmptyBalloon: true
        });


        placemark.events.add('balloonopen', function (e) {
         //необходимо получить объект placemark, по нажатию на который собственно и был вызван balloon.open
            console.log(this);
            //placemark.properties.set('balloonContent', "Идет загрузка данных...");
        });
    
    
    placemarks.push(placemark);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Boldyrev, 2014-07-04
@o_0

Simple js closure.

placemark.events.add('balloonopen', function (e) {
console.log(placemark); // здесь, собственно, и будет тот самый нажатый placemark
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question