title: Open Layers 3 layer visibility - problems passing variables
body: <p>I have got together a pretty basic function which turns on a layer I have on my map.</p>
  
  <p>This is the code for initialising the layer:</p>
  
  <pre><code>var featurelayer;
  
  featurelayer = new ol.layer.Tile({
        name: 'featurelayer',
        source: new ol.source.TileWMS({url: 'http://myserver/geoserver/wms',
        serverType: 'geoserver',
        params:{
          'LAYERS':"layergroup:mylayer", 'TILED':true
        }
        }),
        visible: false
        });
  map.addLayer(featurelayer);
  </code></pre>
  
  <p>I have a list item on my site which when clicked activates a function that I am using to try to turn the layer on. My html and jQuery function is below:</p>
  
  <pre><code>&lt;li class='last'&gt;&lt;a href='#'&gt;&lt;i class="fa fa-circle text-info"&gt;&lt;/i&gt;&lt;span&gt; Flood Zone 3b (Functional Floodplain)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
  $("a.layer").click(function() {
    map.getLayers().forEach(function(layer) {
      if (layer.get('name') === this.id) {
        featurelayer.setVisible(true);
      }
    });
  });
  </code></pre>
  
  <p>This code actually works, it displays the layer on the map. My problem is I will have more than one layer, and ideally I want to be able to pass the ID from my list item which is the same name as the layer to my setVisible event.</p>
  
  <p>I cannot seem to work out how to do this as my console log is always returning undefined; I have tried creating a variable which I am equaling to 'this.id' but that doesn't work - do I need to pass my ID through my click function? Why am I receiving an undefined error if it is registering that my layer name matches my list item ID?</p>
  
  <p>Thanks for any help you can give! </p>