<?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 React custom widget layer filter is removed when pop-up opens in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/react-custom-widget-layer-filter-is-removed-when/m-p/1516393#M85246</link>
    <description>&lt;P&gt;I am running the code below in a custom experience builder widget. It is supposed to filter multiple layers in the map. The filter works as expected but as soon as I click on a feature in the map and the pop up opens, the filter is cleared from all the layers. I expect the filter to be maintained on the layers until I remove it on the click of another button. What could be causing this behaviour?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, type SqlQueryParams, type AllWidgetProps, DataSourceManager, type FeatureLayerDataSource } from 'jimu-core'
import { JimuMapViewComponent, type JimuMapView } from 'jimu-arcgis'
import FeatureLayer from 'esri/layers/FeatureLayer'
import { Select, Option } from 'jimu-ui'
import { FeatureLayerDataSourceImpl } from 'jimu-core/data-source'
import { FeatureLayerDataSourceManager } from 'dist/widgets/common/chart/src/runtime/chart/data-source'

const { useState } = React //{} allow destructuring of this constant

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const [jmv, setJmv] = useState&amp;lt;JimuMapView&amp;gt;()
  const activeViewChangeHandler = (jimumapview: JimuMapView) =&amp;gt; {
    if (jimumapview) {
      setJmv(jimumapview)
    }
  }
  const addLayerHandler = (evt) =&amp;gt; {
    evt.preventDefault()
    //filter all layer views
    jmv.view.map.layers.forEach((lyr) =&amp;gt; {
      if (lyr.type === 'feature' &amp;amp;&amp;amp; (lyr.title === 'OpenMarketSm' || lyr.title === 'ExclusionZoneSm' || lyr.title === 'ExclusionZoneSm')) {
        let featLyrView = null
        jmv.view.whenLayerView(lyr).then((lyrview) =&amp;gt; {
          featLyrView = lyrview
          featLyrView.filter = {
            where: "ServiceAreaType ='Comm. Recycling'"
          }
        })
      }
    })
  }
  return (
      &amp;lt;div&amp;gt;
      &amp;lt;Select
        aria-label="Name"
          placeholder='Select a service type'&amp;gt;
        &amp;lt;Option value = "1"&amp;gt;Residential Trash &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "2"&amp;gt;Residential Recycle &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "3"&amp;gt;Residential Yard Waste &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "4"&amp;gt;Commercial Trash &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "5"&amp;gt;Commercial Recycle &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "6"&amp;gt;Industrial Temp &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "7"&amp;gt;Sanitation Services &amp;lt;/Option&amp;gt;
      &amp;lt;/Select&amp;gt;
      &amp;lt;div&amp;gt;Add Layers to a Map&amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
  {props.useMapWidgetIds &amp;amp;&amp;amp; props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp;
        (&amp;lt;JimuMapViewComponent useMapWidgetId={props.useMapWidgetIds?.[0]} onActiveViewChange={activeViewChangeHandler}/&amp;gt;)}
      &amp;lt;/div&amp;gt;
      &amp;lt;form onSubmit={addLayerHandler}&amp;gt;
        &amp;lt;button className='btn btn-primary'&amp;gt;
          Add Layer to map
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;/div&amp;gt;
  )
}

export default Widget
//activeViewChangeHandler is called once when the map is ready
// {/* ?. checks if object is null  */}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Aug 2024 01:26:01 GMT</pubDate>
    <dc:creator>MK13</dc:creator>
    <dc:date>2024-08-08T01:26:01Z</dc:date>
    <item>
      <title>React custom widget layer filter is removed when pop-up opens</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/react-custom-widget-layer-filter-is-removed-when/m-p/1516393#M85246</link>
      <description>&lt;P&gt;I am running the code below in a custom experience builder widget. It is supposed to filter multiple layers in the map. The filter works as expected but as soon as I click on a feature in the map and the pop up opens, the filter is cleared from all the layers. I expect the filter to be maintained on the layers until I remove it on the click of another button. What could be causing this behaviour?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { React, type SqlQueryParams, type AllWidgetProps, DataSourceManager, type FeatureLayerDataSource } from 'jimu-core'
import { JimuMapViewComponent, type JimuMapView } from 'jimu-arcgis'
import FeatureLayer from 'esri/layers/FeatureLayer'
import { Select, Option } from 'jimu-ui'
import { FeatureLayerDataSourceImpl } from 'jimu-core/data-source'
import { FeatureLayerDataSourceManager } from 'dist/widgets/common/chart/src/runtime/chart/data-source'

const { useState } = React //{} allow destructuring of this constant

const Widget = (props: AllWidgetProps&amp;lt;any&amp;gt;) =&amp;gt; {
  const [jmv, setJmv] = useState&amp;lt;JimuMapView&amp;gt;()
  const activeViewChangeHandler = (jimumapview: JimuMapView) =&amp;gt; {
    if (jimumapview) {
      setJmv(jimumapview)
    }
  }
  const addLayerHandler = (evt) =&amp;gt; {
    evt.preventDefault()
    //filter all layer views
    jmv.view.map.layers.forEach((lyr) =&amp;gt; {
      if (lyr.type === 'feature' &amp;amp;&amp;amp; (lyr.title === 'OpenMarketSm' || lyr.title === 'ExclusionZoneSm' || lyr.title === 'ExclusionZoneSm')) {
        let featLyrView = null
        jmv.view.whenLayerView(lyr).then((lyrview) =&amp;gt; {
          featLyrView = lyrview
          featLyrView.filter = {
            where: "ServiceAreaType ='Comm. Recycling'"
          }
        })
      }
    })
  }
  return (
      &amp;lt;div&amp;gt;
      &amp;lt;Select
        aria-label="Name"
          placeholder='Select a service type'&amp;gt;
        &amp;lt;Option value = "1"&amp;gt;Residential Trash &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "2"&amp;gt;Residential Recycle &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "3"&amp;gt;Residential Yard Waste &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "4"&amp;gt;Commercial Trash &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "5"&amp;gt;Commercial Recycle &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "6"&amp;gt;Industrial Temp &amp;lt;/Option&amp;gt;
        &amp;lt;Option value = "7"&amp;gt;Sanitation Services &amp;lt;/Option&amp;gt;
      &amp;lt;/Select&amp;gt;
      &amp;lt;div&amp;gt;Add Layers to a Map&amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
  {props.useMapWidgetIds &amp;amp;&amp;amp; props.useMapWidgetIds.length === 1 &amp;amp;&amp;amp;
        (&amp;lt;JimuMapViewComponent useMapWidgetId={props.useMapWidgetIds?.[0]} onActiveViewChange={activeViewChangeHandler}/&amp;gt;)}
      &amp;lt;/div&amp;gt;
      &amp;lt;form onSubmit={addLayerHandler}&amp;gt;
        &amp;lt;button className='btn btn-primary'&amp;gt;
          Add Layer to map
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;/div&amp;gt;
  )
}

export default Widget
//activeViewChangeHandler is called once when the map is ready
// {/* ?. checks if object is null  */}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 01:26:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/react-custom-widget-layer-filter-is-removed-when/m-p/1516393#M85246</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-08T01:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when pop-up opens</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/react-custom-widget-layer-filter-is-removed-when/m-p/1516425#M85248</link>
      <description>&lt;P&gt;I have nothing to offer based on the code you provided. Seems like you maybe resetting the filters when user clicks the map? This is just a guess in a dark. All I can say with 100% certainty is that it is in your code somewhere.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 23:48:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/react-custom-widget-layer-filter-is-removed-when/m-p/1516425#M85248</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-08-07T23:48:16Z</dc:date>
    </item>
  </channel>
</rss>

