<?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: Listed to Map Layers visibility in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334532#M8533</link>
    <description>&lt;P&gt;You could do something with the reactiveUtils.watch() method.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Assume I have previously stored mapView to a variable.
mapView.view.map.allLayers.map(layer =&amp;gt; {
  reactiveUtils.watch(layer.visible, (layer) =&amp;gt; {
    console.log(layer)
  }
}&lt;/LI-CODE&gt;&lt;P&gt;Something like this should set up an event listener to run anytime a layer changes it's visibility and log what layer changed.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2023 14:22:36 GMT</pubDate>
    <dc:creator>JeffreyThompson2</dc:creator>
    <dc:date>2023-10-03T14:22:36Z</dc:date>
    <item>
      <title>Listed to Map Layers visibility</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334519#M8530</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm currently facing some challenges related to monitoring changes in layer visibility within map layers and custom widgets I've developed.&lt;/P&gt;&lt;P&gt;I've discovered that I can access the '__esri.LayerList' to interact with the visibility function for the layers within my map layers widget. However, I'm encountering issues with implementing the visibility toggle, as it seems to override the normal function. Additionally, I'm struggling with identifying which specific layer was selected for showing or hiding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    this.layerList._toggleVisibility = function (pointerEvent: PointerEvent) {
      console.log(pointerEvent) 
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;I'd greatly appreciate any recommendations or insights on how to effectively track changes in layer visibility.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 13:50:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334519#M8530</guid>
      <dc:creator>JonathanAttard</dc:creator>
      <dc:date>2023-10-03T13:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Listed to Map Layers visibility</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334532#M8533</link>
      <description>&lt;P&gt;You could do something with the reactiveUtils.watch() method.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Assume I have previously stored mapView to a variable.
mapView.view.map.allLayers.map(layer =&amp;gt; {
  reactiveUtils.watch(layer.visible, (layer) =&amp;gt; {
    console.log(layer)
  }
}&lt;/LI-CODE&gt;&lt;P&gt;Something like this should set up an event listener to run anytime a layer changes it's visibility and log what layer changed.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 14:22:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334532#M8533</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-03T14:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Listed to Map Layers visibility</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334845#M8558</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for your suggestion, but I'm still facing issues with monitoring changes in layer visibility. Unfortunately, when I implemented the solution you provided, nothing happened. Here's the code I tried: &lt;/SPAN&gt;&lt;/P&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;LI-CODE lang="javascript"&gt;// Import
import * as reactiveUtils from "@arcgis/core/core/reactiveUtils.js";

// Attempted function
onActiveViewChange = (activeView: JimuMapView, previousActiveViewId: string) =&amp;gt; {
    // Watching for changes within a collection
    reactiveUtils.watch(
      () =&amp;gt; activeView.view.map.allLayers.map(layer =&amp;gt; layer.visible),
      (visible) =&amp;gt; {
        console.log(`FeatureLayer visible ${visible}`);
      });
  }

// Within the render
&amp;lt;JimuMapViewComponent onActiveViewChange={this.onActiveViewChange} /&amp;gt;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have tried implementing this code with different instances of&amp;nbsp;'JimuMapView', as well as within both Map and Map Layers Widgets&lt;/SPAN&gt;. &lt;SPAN&gt;It's worth mentioning that I am working with an ArcGIS Web Map and not creating my own layers from scratch.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Managed to make it work using the solution from this post:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handle-listen-layer-visibility-events/m-p/1275671" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handle-listen-layer-visibility-events/m-p/1275671&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layer.watch('visible', (visibility, a, eventName,layer) =&amp;gt; {
                console.log("visible: ", visibility);
                console.log(layer, eventName, a);
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 11:05:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334845#M8558</guid>
      <dc:creator>JonathanAttard</dc:creator>
      <dc:date>2023-10-04T11:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Listed to Map Layers visibility</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334899#M8563</link>
      <description>&lt;P&gt;I'm glad you found a solution, but for your future knowledge onActiveViewChange() probably doesn't work the way you think it works. The onActiveViewChange function only fires when the mapView changes, as in the entire jimuMapView object is replaced with a different jimuMapView object. In your code, the event listener would likely never be set up.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 12:57:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/listed-to-map-layers-visibility/m-p/1334899#M8563</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-04T12:57:57Z</dc:date>
    </item>
  </channel>
</rss>

