title: Leaflet : Dynamically count number of feaures loaded into a layer
body: <p>I have an application where  markers/features are loading into layers/layerGroups (what's the right term?) from multiple sources, and they're loading dynamically (based on some attribute in <code>feature.properties</code> and other conditions). I want to be able to tell on the sidepanel the number of markers currently loaded into the layer on display. Given just the layer's variable/identifier, how can one find the number of markers/features loaded into it?</p>
  
  <pre><code>var layer1= L.layerGroup();
  layerControl.addOverlay(layer1, 'Layer 1');
  
  ... // loading stuff into this layer from different sources
  
  console.log(layer1.length); // doesn't work, gives "undefined"
  console.log(JSON.stringify(layer1)); // doesn't work, "TypeError: cyclic object value"
  </code></pre>
  
  <p>..so I guess layers can't be treated like JSON objects. </p>
  
  <p>I found a <a href="https://stackoverflow.com/questions/25601451/getting-the-count-of-markers-in-a-layer-in-leaflet">related question</a>, but the answer there only addresses markers loaded from one geoJson source and advises a simple <code>counter++</code> in the <code>onEachFeature</code>. I'm working with a lot of layers in my application and would appreciate not having to put a separate counter variable for each and every one, rather want to just use the layer's variable/identifier to count. If we can add a layer to a map or clustergroup so simply then we ought to be able to count what's in it, right?</p>