Coordinates in Context Menu Item
joeclarkia opened this issue · comments
Joe Clark commented
The context menu example has a "Show Coordinates" menu option. What I would like to see is a way to put the coordinates in the menu item itself (no callbacks / alert boxes needed). Is there a way to do this?
mike16889 commented
you could do something like this:
var map = L.map('map', {
contextmenu: true,
contextmenuItems: [{
text: 'test',
iconCls: 'showLatLng'
}]
});
then:
map.on('contextmenu.show', function(e){
let el = e.contextmenu._container.getElementsByClassName("showLatLng");
if(el.length){
el[0].parentElement.innerHTML = '<b>Lat: </b>'+e.latlng.lat+'<br><b> Lng: </b>'+e.latlng.lat;
}
})
You could of course trim the decimal places to your liking.