[英]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. 我试图获取点击的地标的ID,但是我找不到解决方法。
I have the following code on TypeScript: 我在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: 这是ServerResponse接口:
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? 所以这是一个问题:我如何获取被点击的地标ID?
Did you try this var objectId = e.get('objectId');
您是否尝试过var objectId = e.get('objectId');
? ?
You can see how to use ObjectManager in YandexMap Sandbox and in ObjectManager Documentation . 您可以在YandexMap沙箱和ObjectManager文档中看到如何使用ObjectManager。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.