简体   繁体   English

我如何获得标记JVectorMap的名称或标识

[英]How do i get the name or identification of a marker JVectorMap

How do I know the name or id of the marker that is clicked? 我怎么知道被点击的标记的nameid

And is it possible? 有可能吗?

Is there a way to find the label/name of the marker like this for example: 有没有办法找到label/name ,例如:

onMarkerClick: function(label){
    alert(label.text());
}

All help appreciated :) 所有帮助表示赞赏:)

The second parameter in the click handler function is the key/index of the marker object. 单击处理程序函数中的第二个参数是标记对象的键/索引。

onMarkerClick (Event e, String code) onMarkerClick(事件e,字符串代码)

One possible way to do that, is: 一种可行的方法是:

onMarkerClick: function(e, code) {
    var mapObj = $("#map").vectorMap("get", "mapObject");
    var idx = parseInt(code); // optional
    var name = mapObj.markers[idx].config.name;
    var latitude = mapObj.markers[idx].config.latLng[0];
    var longitude = mapObj.markers[idx].config.latLng[1];
}

Explanation: 说明:

  • depending how you created the markers, you may need to get the index as numeric value 根据创建标记的方式,您可能需要将索引作为数字值获取
  • by default, each marker is storing the name and the coords of the point 默认情况下,每个标记都存储该点的namecoords

If you need more info, try to explore the properties of the map object in the browser, like this: console.log(mapObj.markers); 如果需要更多信息,请尝试在浏览器中浏览地图对象的属性,如下所示: console.log(mapObj.markers);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM