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") {
        else {
  • Specification of onEachFeature option is wrong, it should be: onEachFeature: function(feature, layer) { … }
    – TomazicM
    Commented Dec 19, 2019 at 7:11
  • hey, i still face the same issue, the code works if i replace 'bindTooltip' with 'bindPopup'. im not sure if i am doing this right
    – arya
    Commented Dec 19, 2019 at 7:27
  • 2
    If you corrected syntax, it should work.
    – TomazicM
    Commented Dec 19, 2019 at 17:21

1 Answer 1


According to leaflet's documentation - after bindTooltip() - add openTooltip() Code - I added the 'options fix' from the comments:

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

  • 1
    Any special reason for opening all tooltips upon definition with .openTooltip()? This is not necessary unless you want to have all the tooltips open initially. Usually behavior for tooltip is to be opened upon mouse over.
    – TomazicM
    Commented Jan 29, 2020 at 13:13
  • If a codePen is avail - it'll be easier to explain. I might be wrong of course. @TomazicM
    – NettaB
    Commented Jan 29, 2020 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.