|
|
|
L.Control.ActiveLayers=L.Control.Layers.extend({getActiveBaseLayer:function(){return this._activeBaseLayer},getActiveOverlayLayers:function(){return this._activeOverlayLayers},onAdd:function(e){var t=L.Control.Layers.prototype.onAdd.call(this,e);return Array.isArray(this._layers)?(this._activeBaseLayer=this._findActiveBaseLayer(),this._activeOverlayLayers=this._findActiveOverlayLayers()):(this._activeBaseLayer=this._findActiveBaseLayerLegacy(),this._activeOverlayLayers=this._findActiveOverlayLayersLegacy()),t},_findActiveBaseLayer:function(){var e=this._layers;for(var t=0;t<e.length;t++){var n=e[t];if(!n.overlay&&this._map.hasLayer(n.layer))return n}throw new Error("Control doesn't have any active base layer!")},_findActiveOverlayLayers:function(){var e={},t=this._layers;for(var n=0;n<t.length;n++){var r=t[n];r.overlay&&this._map.hasLayer(r.layer)&&(e[r.layer._leaflet_id]=r)}return e},_findActiveBaseLayerLegacy:function(){var e=this._layers;for(var t in e)if(this._layers.hasOwnProperty(t)){var n=e[t];if(!n.overlay&&this._map.hasLayer(n.layer))return n}throw new Error("Control doesn't have any active base layer!")},_findActiveOverlayLayersLegacy:function(){var e={},t=this._layers;for(var n in t)if(this._layers.hasOwnProperty(n)){var r=t[n];r.overlay&&this._map.hasLayer(r.layer)&&(e[n]=r)}return e},_onLayerChange:function(){L.Control.Layers.prototype._onLayerChange.apply(this,arguments),this._recountLayers()},_onInputClick:function(){this._handlingClick=!0,this._recountLayers(),L.Control.Layers.prototype._onInputClick.call(this),this._handlingClick=!1},_recountLayers:function(){var e,t,n,r=this._form.getElementsByTagName("input"),i=r.length;for(e=0;e<i;e++)t=r[e],Array.isArray(this._layers)?n=this._layers[e]:n=this._layers[t.layerId],t.checked&&!this._map.hasLayer(n.layer)?n.overlay?this._activeOverlayLayers[t.layerId]=n:this._activeBaseLayer=n:!t.checked&&this._map.hasLayer(n.layer)&&n.overlay&&delete this._activeOverlayLayers[t.layerId]}}),L.control.activeLayers=function(e,t,n){return new L.Control.ActiveLayers(e,t,n)};
|