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

click event on label?

Open mandsch opened this issue 9 years ago • 8 comments

Hi, in my leaflet map, I add labels to geojson features. The labels get the clickable option set to true, the label is seemingly clickable (the mouse changes to the pointer type). But nothing happens onclick. there is an onclick handler defined for the actual marker, but how to set an onclick handler for the label?

Thanks, Michael

mandsch avatar Oct 09 '15 14:10 mandsch

Please provide an example of the bug.

IvanSanchez avatar Oct 09 '15 14:10 IvanSanchez

It's not a bug, it's maybe just lacking documentation on how to bind an action to the click event. I also came here looking for that.

pax avatar Oct 28 '15 13:10 pax

You need to specifically bind an event to marker.label, e.g.:

L.DomEvent.addListener(marker.label, 'click', function(e) { this.togglePopup() }, marker);

I had to dig in to the code a bit to figure this out, worth a mention in the README on how to access the label and bind events to it.

gbuesing avatar Nov 02 '15 16:11 gbuesing

A Star from me!!

PerchHero20 avatar Jan 18 '16 09:01 PerchHero20

Are there no plans for adding on/off methods to the label? So that we can use:

marker.getLabel().on('click', function(e) { this.togglePopup() });

Update: it seems to work also this way: http://jsfiddle.net/A1an/mqL7h6p5/

a1an77 avatar Jan 21 '16 15:01 a1an77

Hi a1an77 I found that your label doesn't see appear you map Is there any way to show in your label? Many many Thanks!

Regards, Kenneth

hkcity1111 avatar Feb 18 '16 05:02 hkcity1111

Hi Kenneth what do you mean? If the jsfiddle does not work for you be sure to check if your browser is blocking some content (open the console to check for errors and warnings)

a1an77 avatar Feb 18 '16 13:02 a1an77

Hi a1an77, Yes, you are right. I found that our company block something and cannot load leaflet label src.js so that I cannot see drag me but I can run this sample in my home computer. Thanks a lot

hkcity1111 avatar Feb 18 '16 16:02 hkcity1111