I have multiple overlays in my map that are all disabled by default:
var overlays = {
'Overlay #1': overlay1,
'Overlay #2': overlay2,
'Overlay #3': overlay3
};
L.control.layers(baseMaps, overlays).addTo(mymap);
I'd like to make it so that when you click on a particular marker overlay2 appears. I'd like it to appear as checked in the Layer Control dialog and I'd like it to show up on the map as well. What isn't immediately obvious to me is (1) how to make it so that javascript is ran when a particular popup is opened or a particular marker clicked on and (2) how to turn overlays on as I've described.
Here's my marker code:
L.marker({lat: 30.266293, lon: -97.656965}, {icon: myIcon})
.addTo(mymap)
.bindPopup("<b>Hello world!</b>");
I guess I could make use of the popupopen event handler, looking at _source but is that the best way? That answer is almost eight years old.
As far as turning overlays on is concerned... Leaflet enable all overlays by default does $(".leaflet-control-layers-overlays label input").trigger('click')
but that looks like that'll turn all the overlays on - not just one of them. I suppose I could do .eq(1)
or some such but that seems super inelegant.
Any ideas?