Reputation: 301
How to get the baselayer selected in leaflet?
Upvotes: 5
Views: 6054
Reputation: 51
map._zoomBoundLayers seems to have what you need. or the first element of map._layers also seems to be right
I added a tag I wanted to use in the layer obje
google = L.tileLayer('http://{s}.google.com/vt/lyrs=p&hl=en&x={x}&y={y}&z={z}',
{ maxZoom : 20
, descr : "GoogleMap"
, attribution: '© <a href="https://maps.google.com/">Google</a>'});
mapLayerID = Object.keys(map._layers)[0];
currentLayer = map._layers[mapLayerID].options.descr;
Upvotes: 0
Reputation: 28638
Listen for the baselayerchange
event on your mapinstance:
Fired when the base layer is changed through the layer control.
http://leafletjs.com/reference.html#map-baselayerchange
map.on('baselayerchange', function (e) {
console.log(e.layer);
});
Upvotes: 13