<?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 Add a Legend to LayerList sample with Group Layers and selectionEnabled in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-legend-to-layerlist-sample-with-group-layers/m-p/1028136#M71811</link>
    <description>&lt;P&gt;I'm working with the ArcGIS JavaScript API 4.18 'Add a Legend to LayerList' sample (&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/&lt;/A&gt;).&amp;nbsp; I have group layers and sub group layers in my map and the sample code has a line in it to check for group layers so it doesn't show the legend twice.&amp;nbsp; This all works fine until you make selectionEnabled = true.&amp;nbsp; This lets you select layers and drag them to reorder them in your list.&amp;nbsp; Layers with one group can be reordered without issue.&amp;nbsp; However, layers in a subgroup (group within a group) lose the legend, and any other actions, you have set on the layer when you reorder them.&amp;nbsp; If you drag them out of the subgroup the legend and actions will reappear.&amp;nbsp; This is happening because the listItemCreatedFunction gets called when you reorder the layers but the flag that checks if the layer is a group prevents the layers in the subgroup from building a legend.&amp;nbsp; You can see an example in these two pens:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In this first example there is only one group and you can reorder the layers without issue &lt;A href="https://codepen.io/nbabel/pen/abBwLNJ" target="_blank" rel="noopener"&gt;https://codepen.io/nbabel/pen/abBwLNJ&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;In this second example there is a subgroup and if you reorder the layers within the subgroup the legend disappears.&amp;nbsp; If you drag a layer out of the second group the legend reappears&amp;nbsp;&lt;A href="https://codepen.io/nbabel/pen/ExgNMwO" target="_blank" rel="noopener"&gt;https://codepen.io/nbabel/pen/ExgNMwO&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So my question is: Is this expected behaviour?&amp;nbsp; Is this a bug?&amp;nbsp; When I'm reordering the layer why does it apparently think it's a group layer and not build a legend?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2021 17:13:00 GMT</pubDate>
    <dc:creator>NilsBabel1</dc:creator>
    <dc:date>2021-02-18T17:13:00Z</dc:date>
    <item>
      <title>Add a Legend to LayerList sample with Group Layers and selectionEnabled</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-legend-to-layerlist-sample-with-group-layers/m-p/1028136#M71811</link>
      <description>&lt;P&gt;I'm working with the ArcGIS JavaScript API 4.18 'Add a Legend to LayerList' sample (&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/&lt;/A&gt;).&amp;nbsp; I have group layers and sub group layers in my map and the sample code has a line in it to check for group layers so it doesn't show the legend twice.&amp;nbsp; This all works fine until you make selectionEnabled = true.&amp;nbsp; This lets you select layers and drag them to reorder them in your list.&amp;nbsp; Layers with one group can be reordered without issue.&amp;nbsp; However, layers in a subgroup (group within a group) lose the legend, and any other actions, you have set on the layer when you reorder them.&amp;nbsp; If you drag them out of the subgroup the legend and actions will reappear.&amp;nbsp; This is happening because the listItemCreatedFunction gets called when you reorder the layers but the flag that checks if the layer is a group prevents the layers in the subgroup from building a legend.&amp;nbsp; You can see an example in these two pens:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;In this first example there is only one group and you can reorder the layers without issue &lt;A href="https://codepen.io/nbabel/pen/abBwLNJ" target="_blank" rel="noopener"&gt;https://codepen.io/nbabel/pen/abBwLNJ&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;In this second example there is a subgroup and if you reorder the layers within the subgroup the legend disappears.&amp;nbsp; If you drag a layer out of the second group the legend reappears&amp;nbsp;&lt;A href="https://codepen.io/nbabel/pen/ExgNMwO" target="_blank" rel="noopener"&gt;https://codepen.io/nbabel/pen/ExgNMwO&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So my question is: Is this expected behaviour?&amp;nbsp; Is this a bug?&amp;nbsp; When I'm reordering the layer why does it apparently think it's a group layer and not build a legend?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 17:13:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-legend-to-layerlist-sample-with-group-layers/m-p/1028136#M71811</guid>
      <dc:creator>NilsBabel1</dc:creator>
      <dc:date>2021-02-18T17:13:00Z</dc:date>
    </item>
  </channel>
</rss>

