<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hiding multiple feature layers in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356157#M32986</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yeah I was thinking the same thing. I was trying it the same way as map.addLayers. I'll use a loop there as well because I've got a few more layers to add. Thanks mate, have a good Xmas break!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Dec 2011 04:54:04 GMT</pubDate>
    <dc:creator>EdSaunders</dc:creator>
    <dc:date>2011-12-22T04:54:04Z</dc:date>
    <item>
      <title>Hiding multiple feature layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356153#M32982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've add some feature layers and pushed them into an array like below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;var dwf = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://" rel="nofollow" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;&amp;lt;server&amp;gt;/ArcGIS/rest/services/SLR/Water/MapServer/1";&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dwfLayer = new esri.layers.FeatureLayer(dwf, {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; id : "dwf",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; title : "Drinking water facilities",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; infoTemplate : infoTemplate&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;legendLayers.push({&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; layer : dwfLayer,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; title : 'Drinking water facilities'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, in another function, I'd like to switch off all the feature layers so I've tried using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;var len = legendLayers.length;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (var i = 0; i &amp;lt; len; i++) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; legendLayers&lt;I&gt;.hide();&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dojo.forEach(legendLayers.layer, function(layer) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; layer.hide();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But neither of the above functions work to hide all the layers in the legendLayers array.&amp;nbsp; I'm obviously missing something. Can anyone help?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks heaps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ed&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Dec 2011 23:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356153#M32982</guid>
      <dc:creator>EdSaunders</dc:creator>
      <dc:date>2011-12-21T23:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding multiple feature layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356154#M32983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var len = legendLayers.length;
for (var i = 0; i &amp;lt; len; i++) {
 legendLayers&lt;I&gt;.hide();
}
&lt;/I&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Ed,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like you may need another array to hold the feature layers, rather than trying to re-use the one holding the legend layers. You could try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var fLayers = []; //define a new array for the feature layers
legendLayers.push({
&amp;nbsp; layer : dwfLayer,
&amp;nbsp; title : 'Drinking water facilities'
}
fLayers.push(dwfLayer); //push this layer to the new array (as well as the Legend array)

//Iterate through the feature layers and switch them off
for (var i = 0; i &amp;lt; fLayers.length; i++) {
&amp;nbsp; var layer = fLayers&lt;I&gt;;
&amp;nbsp; layer.hide();
}
&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:40:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356154#M32983</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2021-12-11T16:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding multiple feature layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356155#M32984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Steve, thanks for the input mate.&amp;nbsp; I didn't think it mattered when and how you add layers into an array but it seems it's quite important!&amp;nbsp; For example, this works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(saLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(wpLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(dwpLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(roadsLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(wfLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; activeLayers.push(dwfLayer);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;using the loop: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; var len = activeLayers.length;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for (var i = 0; i &amp;lt; len; i++) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; activeLayers&lt;I&gt;.hide();&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but I get the error message "activeLayers&lt;I&gt;.hide is not a function" using:&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;activeLayers.push([saLayer, wpLayer, dwpLayer, roadsLayer, wfLayer, dwfLayer]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;activeLayers.push({layer:saLayer},{layer:wpLayer},{layer:dwpLayer},{layer:roadsLayer},{layer:wfLayer},{layer:dwfLayer});&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can I not put layers into an array using the two types of syntax above?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ed&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Dec 2011 04:26:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356155#M32984</guid>
      <dc:creator>EdSaunders</dc:creator>
      <dc:date>2011-12-22T04:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding multiple feature layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356156#M32985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;but I get the error message "activeLayers&lt;I&gt;.hide is not a function" using:&lt;BR /&gt;&lt;BR /&gt;activeLayers.push([saLayer, wpLayer, dwpLayer, roadsLayer, wfLayer, dwfLayer]);&lt;BR /&gt;activeLayers.push({layer:saLayer},{layer:wpLayer},{layer:dwpLayer},{layer:roadsLayer},{layer:wfLayer},{layer:dwfLayer});&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try using push within a for loop, in the same way as you're using hide?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Dec 2011 04:38:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356156#M32985</guid>
      <dc:creator>StephenLead</dc:creator>
      <dc:date>2011-12-22T04:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding multiple feature layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356157#M32986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yeah I was thinking the same thing. I was trying it the same way as map.addLayers. I'll use a loop there as well because I've got a few more layers to add. Thanks mate, have a good Xmas break!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Dec 2011 04:54:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/hiding-multiple-feature-layers/m-p/356157#M32986</guid>
      <dc:creator>EdSaunders</dc:creator>
      <dc:date>2011-12-22T04:54:04Z</dc:date>
    </item>
  </channel>
</rss>

