getActiveLayers for LeafletJS
Well, one option I've come across (to answer my own question) is a plugin created by vogdb.
This plugin contains methods getActiveBaseLayer()
and getActiveOverlayLayers()
.
The following, from vogdb's github page, demonstrates how vogdb's activeLayers
control can be used in place of the standard leaflet layers
control making the 2 methods available.
var control = L.control.activeLayers(baseLayers, overlayLayers)
control.addTo(map)
console.log(control.getActiveBaseLayer().name)
var overlayLayers = control.getActiveOverlayLayers()
for (var overlayId in overlayLayers) {
console.log(overlayLayers[overlayId].name)
}
The plugin can be found on github: https://github.com/vogdb/Leaflet.ActiveLayers
And for referencing purposes, I found the link to vogdb's plugin here: http://leaflet.uservoice.com/forums/150880-ideas-and-suggestions-for-leaflet/suggestions/3777550-get-active-baselayer