Leaflet.contextmenu icon indicating copy to clipboard operation
Leaflet.contextmenu copied to clipboard

Coordinates in Context Menu Item

Open joeclarkia opened this issue 4 years ago • 1 comments

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?

joeclarkia avatar Apr 02 '20 16:04 joeclarkia

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: image

You could of course trim the decimal places to your liking.

mike16889 avatar Aug 29 '20 04:08 mike16889