Search code examples
javascripttypescriptyandex-apiyandex-maps

How to get id of clicked placemark on yandex maps?


I've trying to get id of clicked placemark, but I can't find the way to do that.

I have the following code on 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){

    // here i want to get placemark 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; // this is id, which I want to get
        type    : string;
        geometry: {
            type       : string;
            coordinates: string[]
        };
    }[]
}

So here is the question: how can i get id of placemark, which was clicked?


Solution

  • Did you try this var objectId = e.get('objectId');?

    You can see how to use ObjectManager in YandexMap Sandbox and in ObjectManager Documentation.