<?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: Layer filter is removed when popup opens in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522114#M14305</link>
    <description>&lt;P&gt;I am not sure why you getting this behavior but I would suggest you two things which might help I think.&amp;nbsp;&lt;BR /&gt;1- you are using onSubmit on the form it might be reloading the page try to use onClick of button and check again.&lt;BR /&gt;2- You can alternatively use the definition expression of layer and update it what ever you want which might not refresh onSubmit.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2024 10:11:10 GMT</pubDate>
    <dc:creator>UbaidGul_opaz</dc:creator>
    <dc:date>2024-08-15T10:11:10Z</dc:date>
    <item>
      <title>Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1518405#M14225</link>
      <description>&lt;P&gt;&lt;SPAN&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;/SPAN&gt;&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;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/4655"&gt;@TonghuiMing&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 15:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1518405#M14225</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-15T15:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522114#M14305</link>
      <description>&lt;P&gt;I am not sure why you getting this behavior but I would suggest you two things which might help I think.&amp;nbsp;&lt;BR /&gt;1- you are using onSubmit on the form it might be reloading the page try to use onClick of button and check again.&lt;BR /&gt;2- You can alternatively use the definition expression of layer and update it what ever you want which might not refresh onSubmit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 10:11:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522114#M14305</guid>
      <dc:creator>UbaidGul_opaz</dc:creator>
      <dc:date>2024-08-15T10:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522282#M14313</link>
      <description>&lt;P&gt;Thanks for the suggestions. I removed the Form code and added my&amp;nbsp;addLayerHandler method on the OnClick of a button but I see the same behaviour. The filters are cleared when the pop up opens.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; &amp;lt;button className='btn btn-primary' onClick={addLayerHandler}&amp;gt;
          Add Layer to map
        &amp;lt;/button&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;I also looked at the documentation at&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html&lt;/A&gt;&amp;nbsp;and there is no definitionExpression property on the FeatureLayerView.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 15:35:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522282#M14313</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-15T15:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522385#M14314</link>
      <description>&lt;P&gt;&amp;lt;deleted&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 17:31:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522385#M14314</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-15T17:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522386#M14315</link>
      <description>&lt;P&gt;I suspect that this piece of code below is what's causing the refresh because of the useState which is supposed to re-render the component when the state changes but I am new to React and Javascript and don't really know if that's what's happening here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const [jmv, setJmv] = useState&amp;lt;JimuMapView&amp;gt;()
  const activeViewChangeHandler = (jimumapview: JimuMapView) =&amp;gt; {
    if (jimumapview) {
      setJmv(jimumapview)
    }
  }&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;</description>
      <pubDate>Thu, 15 Aug 2024 17:29:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522386#M14315</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-15T17:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Layer filter is removed when popup opens</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522773#M14334</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/668647"&gt;@MK13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;When you click map, data source selection will change. JimuLayerView will automatically update layer.filter by data source. So JimuLayerView overrides your layer.filter.&lt;/P&gt;&lt;P&gt;You can update 'where' by dataSource.updateQueryParams() method, Here is&amp;nbsp; the solution, please have a try.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;async addLayerHandler (evt) {
    evt.preventDefault()

    await jmv.whenAllJimuLayerViewLoaded()
    const jimuLayerViews = jmv.getAllJimuLayerViews()
    jimuLayerViews.forEach(async (jimuLayerView) =&amp;gt; {
      const layer = jimuLayerView.layer

      if (layer.type === 'feature' &amp;amp;&amp;amp; (layer.title === 'OpenMarketSm' || layer.title === 'ExclusionZoneSm' || layer.title === 'ExclusionZoneSm')) {
        let dataSource = null

        if (jimuLayerView.layerDataSourceId) {
          dataSource = await jimuLayerView.createLayerDataSource()
        }

        if (dataSource) {
          dataSource.updateQueryParams({
            where: "ServiceAreaType ='Comm. Recycling'"
          }, props.widgetId)
        }
      }
    })
  }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Aug 2024 09:16:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup-opens/m-p/1522773#M14334</guid>
      <dc:creator>QunSun</dc:creator>
      <dc:date>2024-08-16T09:16:55Z</dc:date>
    </item>
  </channel>
</rss>

