Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leaflet layer control events?

Tags:

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?

like image 938
user1032402 Avatar asked Dec 31 '12 15:12

user1032402


People also ask

Is Leaflet API free?

Leaflet is open source and free.

What are layers in Leaflet?

In Leaflet, a “layer” is anything that moves around when the map is moved around.

What is Leaflet control?

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.

How do you add an overlay to a Leaflet?

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.


1 Answers

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
}
like image 198
Adrian Garcia Avatar answered Oct 01 '22 20:10

Adrian Garcia