All, I want to detect user layer selection in order to synchronize my sidebar with the displayed layers.
But I don't see any layer control events in the API reference; How might I tell when such user layer selection has occurred?
As an alternative, I've looked at the layer load and unload events, but I don't see any identification in what's returned. Did I miss that somehow?
Leaflet is open source and free.
In Leaflet, a “layer” is anything that moves around when the map is moved around.
Leaflet provides various controls such as zoom, attribution, scale, etc., where − Zoom − By default, this control exists at the top left corner of the map. It has two buttons "+" and "–", using which you can zoom-in or zoom-out the map.
Image OverlayStep 1 − Create a Map object by passing a <div> element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer() method of the Map class. Step 4 − Create the image overlay using L.
There are some events that let you know when the user activates / desactivates a layer.
This may help you:
https://leafletjs.com/reference-1.4.0.html#map-baselayerchange
For example:
map.on('overlayadd', onOverlayAdd);
function onOverlayAdd(e){
//do whatever
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With