R
R
RomkaChev2015-04-06 21:15:30
JavaScript
RomkaChev, 2015-04-06 21:15:30

How to get the id of the label that was clicked?

Yandex.Maps API version - 2.1
I'm trying to get the id of the clicked tag, but it doesn't work.
There is the following code in TypeScript:

var map = new ymaps.Map( 'map', {
    center   : [55.76, 37.64],
    zoom     : 7
} );

var objectManager = new ymaps.ObjectManager( {} );
this.objectManager.events.add(['click'], function(event){

    // Здесь я хочу получить id метки

});
map.geoObjects.add( objectManager );

$.get( "/getObjects", {}, ( response:ServerResponse ) => {
    objectManager.add( data.objects );
}, "json" );

Here is the ServerResponse interface:
interface ServerResponse {
    status : string;
    count  : number;
    objects: {
        id      : number; // id, который я хочу получить
        type    : string;
        geometry: {
            type       : string;
            coordinates: string[]
        };
    }[]
}

Actually, how to get the label id inside the event handler?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Petrov, 2015-04-06
@RomkaChev

Watching the sandbox

this.objectManager.objects.events.add(['click'], function (e) {
  var objectId = e.get('objectId'); //Твоя цепочка?
  console.log(objectId); //Мой..)
});

X
xmoonlight, 2015-04-06
@xmoonlight

event.objects[0].id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question