<?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: FeatureLayer.definitionExpression on 4.22 not refreshing in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134696#M75964</link>
    <description>&lt;P&gt;This works for me in both 4.21 and 4.22.&amp;nbsp; Not sure of your particular feature service URL, but this one using stream data on top of an Esri simple example will correctly apply the definition expression, and then remove it based on the button chosen.&amp;nbsp; If you are still experiencing issues, maybe adding some actual code would help decipher it.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width,initial-scale=1" /&amp;gt;
    &amp;lt;meta name="theme-color" content="#000000" /&amp;gt;
    &amp;lt;meta name="viewport"
          content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;
        Example resetting a FeatureLayer's Definition Expression
    &amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet"
          href="https://js.arcgis.com/4.22/esri/themes/dark/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.22/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }

        #infoDiv {
            padding: 6px;
            width: 370px;
            height: 97%;
            position: absolute;
            top: 10px;
            right: 10px;
            --calcite-ui-brand: #71C96E;
            --calcite-ui-brand-hover: #67B564;
        }

        #resultsDiv {
            overflow: auto;
            display: none;
        }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
        require([
            "esri/Map",
            "esri/views/MapView",
            "esri/layers/FeatureLayer",
            "esri/Basemap"
        ], (
            Map,
            MapView,
            FeatureLayer,
            Basemap
        ) =&amp;gt;
            (async () =&amp;gt; {
                // dark human geography basemap
                const basemap = new Basemap({
                    portalItem: {
                        id: "4f2e99ba65e34bb8af49733d9778fb8e"
                    }
                });

                // national parks layer
                const layer = new FeatureLayer({
                    url: "https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Live_Stream_Gauges_v1/FeatureServer/0",
                    outFields: ["*"]
                });

                const map = new Map({
                    basemap,
                    layers: [layer]
                });

                const view = new MapView({
                    container: "viewDiv",
                    map: map,
                    center: [-112.4, 33.5],
                    zoom: 9,
                    padding: {
                        right: 380
                    }
                });

                const layerView = await view.whenLayerView(layer);

                view.when(function () {
                    view.ui.add("buttons", "bottom-right");
                    document.getElementById("btnTest1").addEventListener('click', function () { testDef("All"); });
                    document.getElementById("btnTest2").addEventListener('click', function () { testDef("Flowing") });
                });
                
                function testDef(inTest) {
                    var defExp = "";
                    if (inTest == "Flowing") {
                        defExp = "stage_ft &amp;gt; 0.3 and org = 'Maricopa County'";
                    }
                    layer.definitionExpression = defExp;
                    layer.refresh();
                }
            })());
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="buttons"&amp;gt;
        &amp;lt;button id="btnTest1"&amp;gt;All&amp;lt;/button&amp;gt;
        &amp;lt;button id="btnTest2"&amp;gt;Flowing&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 18 Jan 2022 18:03:17 GMT</pubDate>
    <dc:creator>JeffreyWilkerson</dc:creator>
    <dc:date>2022-01-18T18:03:17Z</dc:date>
    <item>
      <title>FeatureLayer.definitionExpression on 4.22 not refreshing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134130#M75930</link>
      <description>&lt;DIV class=""&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;We're having an issue which I think is similar to&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/feature-effect-and-labeling-issue/m-p/1129839/thread-id/75742" target="_self"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/feature-effect-and-labeling-issue/m-p/1129839/thread-id/75742&amp;nbsp;&lt;/A&gt;but it's a little different so I wanted to point it out so that it can get fixed in the next release.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;We have a FeatureLayer that displays a number of points across the US. We have a default definitionExpression of&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier" size="4"&gt;"acres &amp;gt; 0 and price/acres &amp;gt; 500" &lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;which can be seen in the first attachment. &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;We allow a user to select a state and filter down their search. Doing so results in a definitionExpression like&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier" size="4"&gt;"&lt;SPAN&gt;state = 'AL' AND acres &amp;gt; 0 and price/acres &amp;gt; 500"&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;This can be seen in the second attachment. When we change the definitionExpression to be more restrictive, the points that do not match are not removed from the map. We've confirmed this behavior was introduced after 4.20.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;I'm wondering if it's the same bug identified in &lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/feature-effect-and-labeling-issue/m-p/1129839#M75742" target="_self"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/feature-effect-and-labeling-issue/m-p/1129839#M75742&lt;/A&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 15 Jan 2022 00:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134130#M75930</guid>
      <dc:creator>RyderRoss</dc:creator>
      <dc:date>2022-01-15T00:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer.definitionExpression on 4.22 not refreshing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134696#M75964</link>
      <description>&lt;P&gt;This works for me in both 4.21 and 4.22.&amp;nbsp; Not sure of your particular feature service URL, but this one using stream data on top of an Esri simple example will correctly apply the definition expression, and then remove it based on the button chosen.&amp;nbsp; If you are still experiencing issues, maybe adding some actual code would help decipher it.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width,initial-scale=1" /&amp;gt;
    &amp;lt;meta name="theme-color" content="#000000" /&amp;gt;
    &amp;lt;meta name="viewport"
          content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;
        Example resetting a FeatureLayer's Definition Expression
    &amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet"
          href="https://js.arcgis.com/4.22/esri/themes/dark/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.22/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }

        #infoDiv {
            padding: 6px;
            width: 370px;
            height: 97%;
            position: absolute;
            top: 10px;
            right: 10px;
            --calcite-ui-brand: #71C96E;
            --calcite-ui-brand-hover: #67B564;
        }

        #resultsDiv {
            overflow: auto;
            display: none;
        }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
        require([
            "esri/Map",
            "esri/views/MapView",
            "esri/layers/FeatureLayer",
            "esri/Basemap"
        ], (
            Map,
            MapView,
            FeatureLayer,
            Basemap
        ) =&amp;gt;
            (async () =&amp;gt; {
                // dark human geography basemap
                const basemap = new Basemap({
                    portalItem: {
                        id: "4f2e99ba65e34bb8af49733d9778fb8e"
                    }
                });

                // national parks layer
                const layer = new FeatureLayer({
                    url: "https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Live_Stream_Gauges_v1/FeatureServer/0",
                    outFields: ["*"]
                });

                const map = new Map({
                    basemap,
                    layers: [layer]
                });

                const view = new MapView({
                    container: "viewDiv",
                    map: map,
                    center: [-112.4, 33.5],
                    zoom: 9,
                    padding: {
                        right: 380
                    }
                });

                const layerView = await view.whenLayerView(layer);

                view.when(function () {
                    view.ui.add("buttons", "bottom-right");
                    document.getElementById("btnTest1").addEventListener('click', function () { testDef("All"); });
                    document.getElementById("btnTest2").addEventListener('click', function () { testDef("Flowing") });
                });
                
                function testDef(inTest) {
                    var defExp = "";
                    if (inTest == "Flowing") {
                        defExp = "stage_ft &amp;gt; 0.3 and org = 'Maricopa County'";
                    }
                    layer.definitionExpression = defExp;
                    layer.refresh();
                }
            })());
    &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div id="buttons"&amp;gt;
        &amp;lt;button id="btnTest1"&amp;gt;All&amp;lt;/button&amp;gt;
        &amp;lt;button id="btnTest2"&amp;gt;Flowing&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:03:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134696#M75964</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2022-01-18T18:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer.definitionExpression on 4.22 not refreshing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134713#M75965</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works for me as well. Would you be able to share a reproducible case? If not can you please share the relevant code (layer constructor - renderers, labels etc). Also the code where and how you are setting the definitionExpression?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7278"&gt;@JeffreyWilkerson&lt;/a&gt;&amp;nbsp;you do not need to call refresh when definitionExpression is set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:47:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1134713#M75965</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-01-18T18:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer.definitionExpression on 4.22 not refreshing</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1135946#M76034</link>
      <description>&lt;P&gt;After disabling snapshot mode (&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/enterprise-point-featurelayers-in-4-20/m-p/1134770#M75967" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/enterprise-point-featurelayers-in-4-20/m-p/1134770#M75967&lt;/A&gt;), this problem went away. I'm wondering if it was due to the layer still trying to load all of the &amp;gt;350k features into memory.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 18:40:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-on-4-22-not/m-p/1135946#M76034</guid>
      <dc:creator>RyderRoss</dc:creator>
      <dc:date>2022-01-21T18:40:21Z</dc:date>
    </item>
  </channel>
</rss>

