I'm writing a web-viewer with Leaflet using multiple layers (some with Tiles and some with geosjson contours) that I had processed using GDAL. I'd like to display a label with the value of the contour when I activate the respective layer, and disable it when it is not visible. The same with all contour layers. I have tried this code but the labels are displayed at load, without hiding if I deactivate the layer.
L.geoJson(mydataset,
{onEachFeature: function(feature, layer) {
var label = L.marker(layer.getBounds().getCenter(), {
icon: L.divIcon({
className: 'label',
html: feature.properties.MY_VARIABLE,
iconSize: [100, 40]
})
}).addTo(map);
}
});
I know that }).addTo(map) could be the cause of that. Thanks for the suggestions