Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet Markerclusterer with Leaflet.Label

Question: Is it possible to use Leaflet.label on Leaflet.markercluster?

Problem: I am trying to have a HTML div appear when the cursor hovers over a cluster icon.

For a normal Marker, you can use attach a label to a marker using

L.marker([-37.7772, 175.2606]).bindLabel('Look revealing label!').addTo(map);
like image 569
Nyxynyx Avatar asked May 06 '26 19:05

Nyxynyx


1 Answers

http://jsfiddle.net/WUXXz/

var label = null;

markers.on('clustermouseover', function (a) {
    label = new L.Label().setLatLng(a.layer.getLatLng())
        .setContent('<p>Hello world!<br />This is a nice popup.</p>')
        .openOn(map);
});

markers.on('clustermouseout', function () {
   if (label) {
      label.close();
      label = null;
   }
});
like image 103
flup Avatar answered May 08 '26 09:05

flup



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!