I am using a permanent tooltip on each marker but the problem is that tooltip texts are overlapping each other and markers are updating every 10 seconds interval. I can't use LayerGroup collision because I need to show markers. I can't find any solution to solve this issue. I tried labelgun but no luck. I used BingMap before in my project and BingMap manages this overlapping issue internally.
Here is my sample code
let marker = L.marker(pos, {options});
marker.bindTooltip(vehicleName, {
direction: 'auto',
permanent: true,
className: "my-labels",
offset: L.point(5,15)
});
newLayer.addLayer(marker);
newLayer.addTo(map);
Best Answer
This will be brute force simple solution for the case when tooltip number is not too high. It's based on the fact it's possible to get all HTML elements with specific CSS class name with the call
document.getElementsByClassName
. This can be used to get all tooltip elements, if we assign them some dummy CSS class with theclassName
option.Logic of the solution goes like this (unoptimized brute force):
document.getElementsByClassName
call;.getBoundingClientRect()
method;Example below is based on creating 250 random polygons with permanent tooltips with the help of turf.js library (here is working JSFiddle: https://jsfiddle.net/TomazicM/L2kewosz/).