aratcliffe / Leaflet.contextmenu

A context menu for Leaflet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coordinates in Context Menu Item

joeclarkia opened this issue · 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?

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.