My objective is to plot polygons and assign a tooltip label to each one. For some reason, my code doesn't seems to work.
poly_geojson = L.geoJson(poly_gon,{
onEachFeature(feature, layer) {
if (feature.properties.sourceLang == "en") {
layer.bindTooltip("<h4>"+feature.properties.name+"</h4>")
}
else {
layer.bindTooltip("<h4>"+feature.properties.name+"</h4>")
}
}
}).addTo(map);
Best Answer
According to leaflet's documentation - afterCode - I added the 'options fix' from the comments:bindTooltip()
- addopenTooltip()
poly_geojson = L.geoJson(poly_gon,{ onEachFeature : function(feature, layer) { if (feature.properties.sourceLang == "en") { layer.bindTooltip("<h4>"+feature.properties.name+"</h4>"); } else { layer.bindTooltip("<h4>"+feature.properties.name+"</h4>"); } } }).addTo(map);
EDIT: no need to use openTooltip() please check this codepen