2017-06-02 11 views
5

Czy istnieje sposób na zaznaczenie wszystkich zaznaczonych warstw w sterowniku.layers z api ulotek? Mogę to zrobić za pomocą jquery, takiego jak ten $ ('. Leaflet-control-layers-selector: checked') , ale może jest api? enter image description here DziękiJak uzyskać wybrane warstwy w control.layers?

Odpowiedz

4

Nie ma na to jednak API można łatwo tworzyć samemu:

// Add method to layer control class 
L.Control.Layers.include({ 
    getActiveOverlays: function() { 

     // Create array for holding active layers 
     var active = []; 

     // Iterate all layers in control 
     this._layers.forEach(function (obj) { 

      // Check if it's an overlay and added to the map 
      if (obj.overlay && this._map.hasLayer(obj.layer)) { 

       // Push layer to active array 
       active.push(obj.layer); 
      } 
     }); 

     // Return array 
     return active; 
    } 
}); 

var control = new L.Control.Layers(...), 
    active = control.getActiveOverlays(); 
Powiązane problemy