TransWikia.com

Layer.bindTooltip doesn't work in Leaflet

Geographic Information Systems Asked on October 6, 2021

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);

One Answer

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

Answered by NettaB on October 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP