Tuesday, 1 April 2014

Leaflet.js clickable marker label

I couldn't find any documentation or examples on how to make a label clickable in leaflet.js.

I tried adding a myLabel.on('click',function(){ }); event but it simply wasn't working. After poking around in the console for a while and logging the label object I found you need to change a seemingly undocumented 'clickable' option. So I ended up with something like this:


var myLabel = myMarker.label;
myLabel.options.clickable = true;
myLabel.on('click',function(){  
//do your stuff
})

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!