<?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: JS API 2.2 /2.3 ArcGIS Server 10.1 and Legend - Checkbox for sublayers in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378057#M35091</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;thanks for the reply, will have a crack at it next week.&lt;BR /&gt;&lt;BR /&gt;I see from the code that it will retrieve the sublayers....still a bit unsure how to get the check boxes in the first TOC and not in the second one, will do some investigation.&lt;BR /&gt;&lt;BR /&gt;thanks again.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For creating the checkboxes, I'd look at the example at &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/map_dynamiclayerlist.html"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/map_dynamiclayerlist.html&lt;/A&gt;&lt;SPAN&gt;. It works well, except if you have sublayers. That's why I use my code to get the bottom-most sublayers. I'll put my explanation below, if you want it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Explanation: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Say you have an .mxd with this kind of layer arrangement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Group Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap, you need both the Group Layer 1 and Layer 1 checked to view Layer 1. However, when you publish this map to ArcGIS Server, and the buildLayerList/updateLayerVisibility example linked above, it does something different.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Published on ArcGIS Server, your map Service will look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[0] Group Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [1] Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [2] Layer 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [3] Layer 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, if you've created checkboxes for all four, and they're checked for Group Layer 1 and Layer 1, this is passed to updateLayerVisibility, which calls layer.setVisibleLayers([0, 1]). This treats Group Layer 1 and Layer 1 separately, and will show not just layer 1, but layers 2, 3, and another layer 1 as well. If you turn off Group layer one in your service, it will only show Layer 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's why I only create checkboxes for the bottom-most layers when I have an mxd with layer groups.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 May 2011 14:15:43 GMT</pubDate>
    <dc:creator>KenDoman</dc:creator>
    <dc:date>2011-05-20T14:15:43Z</dc:date>
    <item>
      <title>JS API 2.2 /2.3 ArcGIS Server 10.1 and Legend - Checkbox for sublayers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378054#M35088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just working on getting a nice legend for my service. I have followed the instructions and the legend works fine however i require checkboxes for each sublayer in the service instead of the higher layer. Does anyone know how i would be able to achieve this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to do it automatically so i dont need to manually change anything when using the code in another application for example. I just would like it to loop through, see sublayers and add the option for a checkbox to turn it on/off, unsure why this is not included as it seems so common for end users to do???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 May 2011 14:24:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378054#M35088</guid>
      <dc:creator>AndyBurns</dc:creator>
      <dc:date>2011-05-19T14:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: JS API 2.2 /2.3 ArcGIS Server 10.1 and Legend - Checkbox for sublayers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378055#M35089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi&lt;BR /&gt;&lt;BR /&gt;Just working on getting a nice legend for my service. I have followed the instructions and the legend works fine however i require checkboxes for each sublayer in the service instead of the higher layer. Does anyone know how i would be able to achieve this?&lt;BR /&gt;&lt;BR /&gt;I would like to do it automatically so i dont need to manually change anything when using the code in another application for example. I just would like it to loop through, see sublayers and add the option for a checkbox to turn it on/off, unsure why this is not included as it seems so common for end users to do???&lt;BR /&gt;&lt;BR /&gt;thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
function getSubLayers(layer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; var infos = layer.layerInfos, info, i, il, subLayerArray;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i=0, il = infos.length; i&amp;lt;il; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info = infos&lt;I&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!info.subLayerIds) { // if the layer doesn't have a subLayer, ...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subLayerArray.push(info.id); // ...function adds the layer's id to an array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return subLayerArray;
}
&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:28:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378055#M35089</guid>
      <dc:creator>KenDoman</dc:creator>
      <dc:date>2021-12-11T17:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: JS API 2.2 /2.3 ArcGIS Server 10.1 and Legend - Checkbox for sublayers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378056#M35090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks for the reply, will have a crack at it next week.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I see from the code that it will retrieve the sublayers....still a bit unsure how to get the check boxes in the first TOC and not in the second one, will do some investigation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 12:34:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378056#M35090</guid>
      <dc:creator>AndyBurns</dc:creator>
      <dc:date>2011-05-20T12:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: JS API 2.2 /2.3 ArcGIS Server 10.1 and Legend - Checkbox for sublayers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378057#M35091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;thanks for the reply, will have a crack at it next week.&lt;BR /&gt;&lt;BR /&gt;I see from the code that it will retrieve the sublayers....still a bit unsure how to get the check boxes in the first TOC and not in the second one, will do some investigation.&lt;BR /&gt;&lt;BR /&gt;thanks again.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For creating the checkboxes, I'd look at the example at &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/map_dynamiclayerlist.html"&gt;http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/map_dynamiclayerlist.html&lt;/A&gt;&lt;SPAN&gt;. It works well, except if you have sublayers. That's why I use my code to get the bottom-most sublayers. I'll put my explanation below, if you want it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Explanation: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Say you have an .mxd with this kind of layer arrangement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Group Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; --- Layer 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcMap, you need both the Group Layer 1 and Layer 1 checked to view Layer 1. However, when you publish this map to ArcGIS Server, and the buildLayerList/updateLayerVisibility example linked above, it does something different.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Published on ArcGIS Server, your map Service will look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[0] Group Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [1] Layer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [2] Layer 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; [3] Layer 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, if you've created checkboxes for all four, and they're checked for Group Layer 1 and Layer 1, this is passed to updateLayerVisibility, which calls layer.setVisibleLayers([0, 1]). This treats Group Layer 1 and Layer 1 separately, and will show not just layer 1, but layers 2, 3, and another layer 1 as well. If you turn off Group layer one in your service, it will only show Layer 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's why I only create checkboxes for the bottom-most layers when I have an mxd with layer groups.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 14:15:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/js-api-2-2-2-3-arcgis-server-10-1-and-legend/m-p/378057#M35091</guid>
      <dc:creator>KenDoman</dc:creator>
      <dc:date>2011-05-20T14:15:43Z</dc:date>
    </item>
  </channel>
</rss>

