<?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 Is it possible to Toggle map service layers by name (not id) ? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-toggle-map-service-layers-by/m-p/108629#M10058</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to toggle Dynamic Map service layers by Layer Name instead of Layer id.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible for me to do this using layerinfo.name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have modifed the Explicity Create Map Service Layer List sample &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html&lt;/A&gt;&lt;SPAN&gt; for what I need &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and I have been having issues trying to get layerinfo.name defined.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have followed a few example in other posts and can't quite get the samples to work in my favor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I saw the recent post regarding the '&lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/62112-Legend-with-Visible-Layers-how-to-modify-for-sublayers"&gt;Legend with Visible Layers&lt;/A&gt;&lt;SPAN&gt;' and couldn't figure out how to breakdown that sample to manually build the layer list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attacthed my working sample using Layer id.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thought I had was to write a function that would take the layer name from the check box function, Get/return the layer id, and use that result to toggel the layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still developing my javascript skills but would be open to any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My ArcGIS server is 9.31 so I can't take advantage of the Legend widget or other samples.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jul 2012 16:01:53 GMT</pubDate>
    <dc:creator>ChristopherPollard</dc:creator>
    <dc:date>2012-07-16T16:01:53Z</dc:date>
    <item>
      <title>Is it possible to Toggle map service layers by name (not id) ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-toggle-map-service-layers-by/m-p/108629#M10058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to toggle Dynamic Map service layers by Layer Name instead of Layer id.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible for me to do this using layerinfo.name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have modifed the Explicity Create Map Service Layer List sample &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html&lt;/A&gt;&lt;SPAN&gt; for what I need &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and I have been having issues trying to get layerinfo.name defined.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have followed a few example in other posts and can't quite get the samples to work in my favor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I saw the recent post regarding the '&lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/62112-Legend-with-Visible-Layers-how-to-modify-for-sublayers"&gt;Legend with Visible Layers&lt;/A&gt;&lt;SPAN&gt;' and couldn't figure out how to breakdown that sample to manually build the layer list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attacthed my working sample using Layer id.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thought I had was to write a function that would take the layer name from the check box function, Get/return the layer id, and use that result to toggel the layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still developing my javascript skills but would be open to any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My ArcGIS server is 9.31 so I can't take advantage of the Legend widget or other samples.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 16:01:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-toggle-map-service-layers-by/m-p/108629#M10058</guid>
      <dc:creator>ChristopherPollard</dc:creator>
      <dc:date>2012-07-16T16:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to Toggle map service layers by name (not id) ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-toggle-map-service-layers-by/m-p/108630#M10059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/arcgisdynamicmapservicelayer.htm#setVisibleLayers" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGISDynamicMapServiceLayer.setVisibleLayers(ids, doNotRefresh?)&lt;/A&gt;&lt;SPAN&gt; method only takes an array of layer IDs. But, you can use a 2D array to hold the layer name and id information, which can be used later to get the layer's id from this 2D array based on the layer's name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var items = [["One", 0],["Two", 1],["Three", 2]];&amp;nbsp; //format: [name,id] Note: check service REST endpoint to get the information about layer name and id 
var visible =[];
var lyrName = "Three"; //layer wants to be turned on
for (var i = 0; i &amp;lt; items.length; i++){
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (items&lt;I&gt;[0] == lyrName) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible.push(items&lt;I&gt;[1]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
} 
agsDynamicMapServiceLayer.setVisibleLayers(visible);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:33:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-it-possible-to-toggle-map-service-layers-by/m-p/108630#M10059</guid>
      <dc:creator>SiqiLi</dc:creator>
      <dc:date>2021-12-11T06:33:06Z</dc:date>
    </item>
  </channel>
</rss>

