0

I'm a working on a project with leaflet where a it shows three layer

enter image description here

you can enable o disable whenever you want to display all the markers from that layer. Every marker has a popup that it opens when you click on the marker

The problema i have is that when you hit over on any layer and active it, the marker displays its popup.

enter image description here

Is there any way to not open it when you activate a layer? o at least to keep it close and just open when you click on it?

Thanks colleagues!

1 Answer 1

0

I revised the solution to instead target layer activation.

This will programmatically unbind popup from each marker in the layer, hence preventing popups from opening when layer is activated.

var layerGroup = L.layerGroup().addTo(map);

layerGroup.on("layeradd", function (event) {
  event.layer.eachLayer(function (marker) {
    marker.unbindPopup();
  });
});
2
  • thanks for answering, your solution is so interesting but it didn't work for me. The popup works for mouseover and mouseout however when i hit on any layer to active it, the popup opens automatically :( Commented Feb 17, 2023 at 17:18
  • Try the updated solution and let me know.
    – Kreetchy
    Commented Feb 17, 2023 at 17:27

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