Leaflet.label
Leaflet.label copied to clipboard
click event on label?
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
Please provide an example of the bug.
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.
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.
A Star from me!!
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/
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
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)
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