question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] cluster tooltip

See original GitHub issue

hello. I would like to know if there is a way to bind a on:hover tooltip to the cluster marker. I tried using Bootstrap tooltip in the html parameter of the iconCreateFunction, but it doesn’t work.

var tooltip = '<a href="#" data-toggle="tooltip"  data-original-title="I am a tooltip">cluster name</a>';
var cluster = new L.MarkerClusterGroup({showCoverageOnHover: true,
                                       spiderfyOnMaxZoom: true,
                                       iconCreateFunction: function (cluster) 
                                                            { return L.divIcon({ html: tooltip, className: 'tooltip', iconSize: L.point(40, 40) });}
                                        });
/*add markers to the cluster*/
$('.tooltip').tooltip();
map.addLayer(cluster);  

Thank you

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
Lekensteyncommented, Feb 12, 2019

This code seems still functional with Leaflet 1.4.0 and Leaflet.markercluster 1.4.1:

   L.markerClusterGroup.on('clustermouseover', function(ev) {
        ev.propagatedFrom.bindTooltip('tooltip text', {sticky: true}).openTooltip();
    }).on('clustermouseout', function(ev) {
        ev.propagatedFrom.unbindTooltip();
    });

Note: Either .layer and .propagatedFrom would work for FeatureGroups like L.markerClusterGroup, but the former is deprecated since it was ambiguous for other types: https://github.com/Leaflet/Leaflet/pull/5880

Another caveat is that with IE9, the tooltip is rapidly closed, potentially due to hovering over the tooltip element (which triggers clustermouseout). (This issue is also visible with tooltips on other layer elements, the tooltip.) If IE9 support is important (meh…), you could workaround that by setting tooltip options like:

{
    offset: [10, 0],
    direction: 'right', // important, otherwise the offset could be applied in the wrong direction
    sticky: true
}
1reaction
Azmisovcommented, Oct 31, 2017

Now that tooltips have been merged leaflet core, I am wondering what the recommended approach to adding tooltips is. Currently, I’m doing something like:

L.markerClusterGroup({
    iconCreateFunction: function(c){
        c.bindTooltip("tooltip text", {direction: "right"});
        return generate_icon(c);
    }
})

Is there a better way to do it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible to show aggregate votes in a tooltip on a ...
I'm building an interface that would take poll data in and show some results over a marker cluster using Mapbox but I don't...
Read more >
How to add tooltips to each item of a cluster in Folium?
As stated in the question: "My goal is to add a tooltip to each item of the dataframe displaying its name." In your...
Read more >
Tooltip on a Flared Cluster - Esri Community
I have a Feature Layer using a Weighted Cluster. I have been able to set the the Tooltip for the flared graphic, however...
Read more >
How To Format Cluster Points - Map Region Point Layer
Hi, I would like to know how I can customize the tooltip for point clusters in a point layer on a map region....
Read more >
Format Titles, Captions, Tooltips, and Legends - Tableau Help
You can show titles and captions on any sheet. Another option is to Add tooltips to marks. A legend card appears in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found