title: Show/Hide Markers that are pulled from function
body: <p>I am using leaflet and want to show/hide the markers that are pulled from this function:</p>
  
  <pre><code>function showResourcesByName(name) {
      for (var i = 0; i &lt; markers.resources.length; i++) {
          var resName = markers.resources[i].name;
  
          if (resName == name) {
              var resIcon = icons.resources[i].icon;
              var resSize = icons.resources[i].size;
              var resPname = icons.resources[i].pname;
  
              var customIcon = L.icon({
                  iconUrl: resIcon,
                  iconSize: resSize, // size of the icon
                  iconAnchor:   [resSize[0]/2, resSize[1]/2], // point of the icon which will correspond to marker's location
                  popupAnchor:  [2, -resSize[1]/2] // point from which the popup should open relative to the iconAnchor
              });
  
              for (var j = 0; j &lt; markers.resources[i].coords.length; j++) {
                  var x = markers.resources[i].coords[j].x;
                  var y = markers.resources[i].coords[j].y;
  
                  L.marker([y, x], {icon: customIcon}).addTo(map).bindPopup(resPname);
              }
          }
      }
  }
  </code></pre>
  
  <p>That outputs markers from a json file. To show the markers I use:
  <code>showResourcesByName("NameOfTheMarkersHere")</code></p>
  
  <p>I have some ideas how this could be done, but I don't know how to make it work.</p>
  
  <p>Idea #1: Add a css class to the function result, so all markers pulled from that function will have that css class, so I can toggle them on/off using javascript/css.</p>
  
  <p>Idea #2: Add a way to toggle function result "on/off" in a button.</p>
  
  <p>Idea #3: Put the function result inside a leaflet layer and toggle that layer on/off with a button.</p>
  
  <p>Idea #4: Add a property in markers properties that can be filtered with a button when using the function.</p>
  
  <p>Please, before answer take a look at my code:</p>
  
  <p><a href="http://plnkr.co/edit/dVgHt4VK0DnA30M3a8vq?p=preview" rel="nofollow">http://plnkr.co/edit/dVgHt4VK0DnA30M3a8vq?p=preview</a></p>