How do I know the name
or id
of the marker that is clicked?
And is it possible?
Is there a way to find the label/name
of the marker like this for example:
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)
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:
name
and the coords
of the point If you need more info, try to explore the properties of the map object in the browser, like this: console.log(mapObj.markers);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.