title: Automatically open popup on layer add
body: <p><strong>I have a polyline that needs to have a popup automatically open when the user selects the polyline layer in the layers control menu.</strong></p>
  
  <blockquote>
    <p>This method did not work for me:</p>
  </blockquote>
  
  <pre><code>var polyline = L.geoJson(myData).bindPopup("&lt;h1&gt;Some Text goes here&lt;/h1&gt;").openPopup();
  </code></pre>
  
  <p><strong>How can I do the auto popup?</strong></p>
  
  <p>Here's my current setup:</p>
  
  <pre><code>var polyline = L.geoJson(myData).bindPopup("&lt;h1&gt;Some Text goes here&lt;/h1&gt;");
  
  var overlaysMenuCtrl = L.Control.extend({ ... blah blah... });
  
  map.addControl(new overlaysMenuCtrl)());
  </code></pre>
  
  <p>I extend the control and add a custom function to check for layers that are toggled on/off by the user:</p>
  
  <pre><code>function toggleLayer(checked, layer){
      if(checked){
          map.addLayer(layer);
      } else {
          map.removeLayer(layer);
      }
  }
  
  $(".check").change(function(){
      var layerClicked = $(this).attr("id");
  //Turn layers on and off based on the ID of the radio checked
     switch(layerClicked){
      case "polyline": toggleLayer(this.checked, polyline);
      break;
      ...and other layers ...
      }
  });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;label&gt;&lt;input id="polyline" type="checkbox" class="check"&gt;Polyline layer&lt;/label&gt;
  </code></pre>