Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

click event on label? #132

Open
mandsch opened this issue Oct 9, 2015 · 8 comments
Open

click event on label? #132

mandsch opened this issue Oct 9, 2015 · 8 comments

Comments

@mandsch
Copy link

mandsch commented Oct 9, 2015

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

@IvanSanchez
Copy link
Member

Please provide an example of the bug.

@pax
Copy link

pax commented Oct 28, 2015

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.

@gbuesing
Copy link

gbuesing commented Nov 2, 2015

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.

@PerchHero20
Copy link

A Star from me!!

@a1an77
Copy link

a1an77 commented Jan 21, 2016

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/

@hkcity1111
Copy link

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

@a1an77
Copy link

a1an77 commented Feb 18, 2016

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)

@hkcity1111
Copy link

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

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

No branches or pull requests

7 participants