Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinates in Context Menu Item #128

Open
joeclarkia opened this issue Apr 2, 2020 · 1 comment
Open

Coordinates in Context Menu Item #128

joeclarkia opened this issue Apr 2, 2020 · 1 comment

Comments

@joeclarkia
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants