Leaflet.contextmenu
Leaflet.contextmenu copied to clipboard
Coordinates in Context Menu Item
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?
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;
}
})
which results in this:
You could of course trim the decimal places to your liking.