<?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: Update LayerList widget on changes in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278214#M80862</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/546199"&gt;@Aeseir&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Can you please provide a codepen or example of the issue you are seeing?&amp;nbsp; The LayerList is designed to automatically update when an operational layer is added or removed from the map.&amp;nbsp; You shouldn't need to do anything.&amp;nbsp; I modified our Intro to FeatureLayer by adding a timeout that removes the layer after 5 seconds and things are working as intended.&amp;nbsp; Are you using a different layer class?&amp;nbsp; How are you removing the layer that isn't being removed from the LayerList?&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/sagewall/pen/RwerVeG" target="_blank"&gt;https://codepen.io/sagewall/pen/RwerVeG&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 13:17:26 GMT</pubDate>
    <dc:creator>Sage_Wall</dc:creator>
    <dc:date>2023-04-13T13:17:26Z</dc:date>
    <item>
      <title>Update LayerList widget on changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278195#M80860</link>
      <description>&lt;P&gt;I am trying to figure out how to update the LayerList widget in v4 when a layer is removed from the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot find any material on refreshing it or updating it on documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently a layer can be removed, but still sit in the LayerList view, confusing the user.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 12:17:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278195#M80860</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-04-13T12:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Update LayerList widget on changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278214#M80862</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/546199"&gt;@Aeseir&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Can you please provide a codepen or example of the issue you are seeing?&amp;nbsp; The LayerList is designed to automatically update when an operational layer is added or removed from the map.&amp;nbsp; You shouldn't need to do anything.&amp;nbsp; I modified our Intro to FeatureLayer by adding a timeout that removes the layer after 5 seconds and things are working as intended.&amp;nbsp; Are you using a different layer class?&amp;nbsp; How are you removing the layer that isn't being removed from the LayerList?&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/sagewall/pen/RwerVeG" target="_blank"&gt;https://codepen.io/sagewall/pen/RwerVeG&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 13:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278214#M80862</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-04-13T13:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update LayerList widget on changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278995#M80891</link>
      <description>&lt;P&gt;That is weird. Pretty much same setup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works for top level items.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const layerList = new LayerList({
view: this.view,
listItemCreatedFunction: onListItemCreation()
});

layerList.on("trigger-action", (event: any) =&amp;gt; {
if(event.action.id === "delete-layer") {
const layer = this.view?.map.findLayerById(event.item.layer.id);

if(layer) this.view.map.remove(layer);
}
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this doesn't work when the layer is a child layer of a Grouplayer, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const groupLayer = new GroupLayer(options);

const featureLayer = new FeatureLayer(options);

groupLayer.layers.add(featureLayer);

// assume featureLayer ID = 1 for this purpose
const featureLayerToDelete = this.view.map.findLayerById(1);
this.view.map.layers.remove(featureLayerToDelete);
//this deletes it but doesn't update the listlayer widget&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 15 Apr 2023 00:34:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1278995#M80891</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-04-15T00:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update LayerList widget on changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1279197#M80898</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/546199"&gt;@Aeseir&lt;/a&gt;&amp;nbsp;, Sorry for the delay in responding.&lt;/P&gt;&lt;P&gt;I'm having a little trouble replicating this behavior you describe.&amp;nbsp; When I try the same thing, adding a feature layer into a group layer then try and remove the feature layer, nothing happens. It's not removed from the map and still is present in the LayerList.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/sagewall/pen/dygXvyv" target="_blank"&gt;https://codepen.io/sagewall/pen/dygXvyv&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This is because after adding the feature layer to the group layer, the original feature layer is no longer an operational layer in the map, its a sublayer in the group layer. To remove the feature layer from the group layer you can use the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GroupLayer.html#remove" target="_self"&gt;GroupLayer.remove()&lt;/A&gt; method as shown here and things should work as expected.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/sagewall/pen/abRZJZZ" target="_blank"&gt;https://codepen.io/sagewall/pen/abRZJZZ&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require(["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/widgets/LayerList", "esri/layers/GroupLayer"], (Map, MapView, FeatureLayer, LayerList, GroupLayer) =&amp;gt; {

      const map = new Map({
        basemap: "hybrid"
      });

      const view = new MapView({
        container: "viewDiv",
        map: map,
        extent: {
          xmin: -9177811,
          ymin: 4247000,
          xmax: -9176791,
          ymax: 4247784,
          spatialReference: 102100
        }
      });

      const layerList = new LayerList({
        view
      })
      view.ui.add(layerList, "bottom-right")

      const featureLayer = new FeatureLayer({
        url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
      });

      const groupLayer = new GroupLayer();
      groupLayer.add(featureLayer);
      map.add(groupLayer);

      // // this doesn't work as featureLayer is now a sublayer of groupLayer
      // setTimeout(() =&amp;gt; {
      //   console.log("Delayed for 5 seconds.");
      //   map.remove(featureLayer)
      // }, "5000");

      // remove the feature layer from the group layer after 5 seconds
      setTimeout(() =&amp;gt; {
        console.log("Delayed for 5 seconds.");
        groupLayer.remove(featureLayer)
      }, "5000");

      // then remove the group layer entirely after 10 seconds
      setTimeout(() =&amp;gt; {
        console.log("Delayed for 5 seconds.");
        map.remove(groupLayer)
      }, "10000");
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 12:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1279197#M80898</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-04-17T12:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Update LayerList widget on changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1279573#M80905</link>
      <description>&lt;P&gt;Gotcha, essentially the owner of the layer is not the GroupLayer. This makes sense and it works fine.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 09:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/update-layerlist-widget-on-changes/m-p/1279573#M80905</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-04-18T09:18:03Z</dc:date>
    </item>
  </channel>
</rss>

