Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Leaflet tooltip clickable

I want to add tooltips on a Leaflet map (without markers) and make them clickable. The following code adds a tooltip but it's not clickable:

var tooltip = L.tooltip({
        direction: 'center',
        permanent: true,
        interactive: true,
        noWrap: true,
        opacity: 0.9
    });
tooltip.setContent( "Example" );
tooltip.setLatLng(new L.LatLng(someLat, someLon));
tooltip.addTo(myLayer);
tooltip.on('click', function(event) {
    console.log("Click!");
});

How can I make it work?

like image 863
Strabonio Avatar asked Jan 25 '18 12:01

Strabonio


1 Answers

Easy solution: set the interactive property to true:

tooltip interactive

in react-leaflet

<Tooltip interactive={true}><Tooltip />
like image 178
Nja Avatar answered Sep 19 '22 01:09

Nja