<?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: LayerList wdiget listen to layer changes in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297791#M81330</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;&amp;nbsp;love your work. I ended up on something similar using a combination of reactiveUtils on list widget and all the layers. Am modifying content to adopt some of your information.&lt;/P&gt;&lt;P&gt;As a recommendation would be great if in future this reactivity was applied at Layer interface as a observable, thus making it event driven. It will make it easier to separate out concerns, and manage change.&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 05:48:35 GMT</pubDate>
    <dc:creator>Aeseir</dc:creator>
    <dc:date>2023-06-10T05:48:35Z</dc:date>
    <item>
      <title>LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297056#M81315</link>
      <description>&lt;P&gt;i created a layerlist widget as so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.layerList = new LayerList({
      view: this.view,
      selectionEnabled: true,
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then added it to ui.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have bunch of featurelayers, mapimagelayers,grouplayers etc now loaded on the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user rearranges the layer in the widget list as they choose fit, is it possible to find out which layer was changed?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 11:34:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297056#M81315</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-06-08T11:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297085#M81316</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;, you can use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html" target="_self"&gt;reactiveUtils&lt;/A&gt;&amp;nbsp;to watch the map's `layers` or `alllayers` collections. We don't have an example available that shows this exact use case but the documentation shows how to watch collections and how to compare to previous values.&amp;nbsp; There is also a lot of really good info in this sample.&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/&lt;/A&gt;&amp;nbsp; If I get time I'll try and write a codepen.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 13:27:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297085#M81316</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-06-08T13:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297427#M81320</link>
      <description>&lt;P&gt;hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;&amp;nbsp;thanks for reaching out, that was the first place I went to see if i can figure it out, but haven't yet figured it out.&lt;/P&gt;&lt;P&gt;If you can find time to put together a simple codepen to show at your convenience, would be amazing.&lt;/P&gt;&lt;P&gt;I'll keep experimenting in meantime.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 01:06:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297427#M81320</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-06-09T01:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297550#M81325</link>
      <description>&lt;P&gt;Happy to help when I can, its been really busy around here this week preparing for the 4.27 release.&amp;nbsp; Hopefully I'll get a moment today to write an example&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 12:48:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297550#M81325</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-06-09T12:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297709#M81329</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;take a look at this &lt;A href="https://codepen.io/sagewall/pen/qBQEGNp" target="_self"&gt;codepen&lt;/A&gt;, hopefully it will get you started in the right direction.&amp;nbsp; I wasn't sure exactly what properties on the layer you were interested in so I just used the layer title and index in the example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
  "esri/WebMap",
  "esri/views/MapView",
  "esri/core/Collection",
  "esri/core/reactiveUtils",
  "esri/widgets/LayerList"
], (WebMap, MapView, Collection, reactiveUtils, LayerList) =&amp;gt; {
  const changesList = document.querySelector("#changesList");

  const map = new WebMap({
    portalItem: {
      id: "512944c00f8a4219a4bb70691089c9e9"
    }
  });

  const view = new MapView({
    container: "viewDiv",
    map
  });

  const layerList = new LayerList({
    selectionEnabled: true,
    view
  });

  view.ui.add(layerList, "top-right");

  let previousTitles = new Collection();

  reactiveUtils.watch(
    () =&amp;gt; view.map.allLayers.map((layer) =&amp;gt; layer.title),
    (titles) =&amp;gt; {
      const areTitlesEqual = detectChanges(previousTitles, titles);
      if (!areTitlesEqual) {
        whatChanged(previousTitles, titles);
      }
      previousTitles = titles;
    }
  );

  function detectChanges(
    firstCollection: Collection,
    secondCollection: Collection
  ) {
    if (firstCollection.length === secondCollection.length) {
      firstCollection.forEach((item, index) =&amp;gt; {
        if (item === secondCollection.getItemAt(index)) {
          return true;
        }
        return false;
      });
    }
    return false;
  }

  function whatChanged(
    firstCollection: Collection,
    secondCollection: Collection
  ) {
    changesList!.innerHTML = "";
    firstCollection.forEach((item, index) =&amp;gt; {
      if (item !== secondCollection.getItemAt(index)) {
        const listItem = document.createElement("calcite-list-item");
        listItem.label = item;
        listItem.description = `previously at index ${index} moved to index ${secondCollection.findIndex(
          (secondItem) =&amp;gt; secondItem === item
        )}`;
        changesList!.appendChild(listItem);
      }
    });
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 20:05:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297709#M81329</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-06-09T20:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: LayerList wdiget listen to layer changes</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297791#M81330</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;&amp;nbsp;love your work. I ended up on something similar using a combination of reactiveUtils on list widget and all the layers. Am modifying content to adopt some of your information.&lt;/P&gt;&lt;P&gt;As a recommendation would be great if in future this reactivity was applied at Layer interface as a observable, thus making it event driven. It will make it easier to separate out concerns, and manage change.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 05:48:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/layerlist-wdiget-listen-to-layer-changes/m-p/1297791#M81330</guid>
      <dc:creator>Aeseir</dc:creator>
      <dc:date>2023-06-10T05:48:35Z</dc:date>
    </item>
  </channel>
</rss>

