I have a Leaflet map that includes polygons and data from a GeoJSON file. I have permanent tooltips for each polygon that include data for the user to see. But there are so many tooltips that sometimes they overlap, and then the reader can't read the overlapped tooltips.
A solution to this problem, I thought, would be that if the user clicked a tooltip, it would be brought to the front. Unfortunately, I haven't been able to make this idea work. Does anyone know how to make this happen please?
Here is my code:
//define the map
var map = L.map('map').setView([40.350641, -79.86773], 15);
var OpenStreetMap_France = L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
maxZoom: 22,
ext: 'png',
attribution: '© Openstreetmap France | © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
//grab data about real estate parcels from json file and put in tooltips
var parcels = new L.GeoJSON.AJAX("data/parcels.geojson",{ //add parcel shapes and data
onEachFeature: function (feature, layer) {
layer.bindTooltip(/*feature.properties.PIN + " " + */"<h4>" + feature.properties.PROPERTYHOUSENUM__asmt + " " + feature.properties.PROPERTYADDRESS__asmt + "</h4>" + "<h5>Use in 1922</h5>" + feature.properties.USE_1922 + "<br/>" + "<h5>Current Use</h5>" + feature.properties.CURRENT_USE, { 'permanent': true, 'interaction': true });
//when you click a tooltip, bring it to the front
layer.on('click',function() {
this.bringToFront(); //doesn't work
this.setZIndexOffset(999); //doesn't work
});
}
}).addTo(map);