title: get status of Leaflet layer control checkbox
body: <p>I have several functions drawing different things on a map using Leaflet and one of them has a layer control which shows/hides some sectors on the map. The other function draw lifts (straight lines).</p>
  
  <p>Upon user action, the content displayed on the map is changed and I redraw the lifts.
  I would like the sectors to only be drawn if the user has checked the checkbox but I don't know how to get the value of the checkbox and pass it to the lift function (which should trigger the sector function if the user has checked the checkbox).</p>
  
  <p>How can I save the value of the layer control checkbox and test it in another Ajax function (lift) ?</p>
  
  <pre><code>$('#build').on("click", function(e){
      $.ajax({
          type: "POST",
          url: map_controller/show_lift_types",
          success: function(result){
              if (result.returned == true){
                  // ... Displays some information in the page 
                  drawLift(); // Draws the lifts
                  // If the user has chosen to show the sector layer, need to call drawSectors 
                  drawSectors();
              }
          }
      });
  });
  
  
  function drawLift() {
      if (typeof lift_path !== 'undefined') {             // If lift_path (the lifts) exists
          map.eachLayer(function (layer) {                // For each layer
              console.log(layer._leaflet_id);
              if (typeof layer._path !== 'undefined') {       // Only if the _path variable exist. Excludes the background image of the map and already built lift
              map.removeLayer(layer);                     // Remove the layer
          }
          });
      }
  
      $.ajax({
          type: "POST",
          dataType: "json",
          url: map_controller/get_lifts_map",
          success: function(result){
              for ( i=0; i &lt; result.id_group.length; i++ ) {
                  // ... retrieves parameters ...         
                  var path_info = {
                      "type": "Feature",
                      "features": [{
                          "type": "Feature",
                          "geometry": {
                              "type": "LineString",
                              "coordinates": [start_location, end_location]
                          }
                      }]
                  };
                  lift_path = new L.geoJson(path_info,style: style}).on('click', function (e) {
                      // ... Some function...
                  }).addTo(map);
              }
          }
      });
  };
  
  function drawSector() {
      var sector_path = new Array()   
      var baseLayers;
      $.ajax({
          type: "POST",
          dataType: "json",
          url: map_controller/get_sectors_map",
          success: function(result){  
              for ( i=0; i &lt; result.path.length; i++ ) {
                  // ... retrieves parameters ...   
                  var sectors = {
                      "type": "Feature",
                      "geometry": {
                          "type": "Polygon",
                          "coordinates": path
                      }
                  };
                  sector_path[i] = L.geoJson(sectors, style);
              }
              var sectors = L.layerGroup([sector_path[0], sector_path[1], sector_path[2]]).addTo(map);
              var overlays = {};
              overlays[Settings.show_sectors] = sectors;  // Show sector checkbox
              L.control.layers(baseLayers, overlays).addTo(map);
          }
      });
  }
  
  // do the actual ajax calls
  drawSector(); 
  drawLift();   
  </code></pre>
  
  <p><strong>Update:</strong> Based on @davojta suggestion, here is my complete solution:</p>
  
  <pre><code>$(document).on('change', '.leaflet-control-layers-selector', function() {
      $checkbox = $(this);
      if ($checkbox.is(':checked')) {
          sectorLayerCheckbox = true;
      }
      else {
          sectorLayerCheckbox = false;
      }
  }
  </code></pre>
  
  <p>In <code>drawLift</code> I added :</p>
  
  <pre><code>if (typeof sectorLayerCheckbox == 'undefined' || sectorLayerCheckbox != false) {  
     drawSector();
  }
  </code></pre>