<?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: Features not getting highlighted based on a query in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383799#M83674</link>
    <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;. This is exactly that I was hoping to achieve.&lt;/P&gt;</description>
    <pubDate>Sat, 17 Feb 2024 15:03:47 GMT</pubDate>
    <dc:creator>wizgis</dc:creator>
    <dc:date>2024-02-17T15:03:47Z</dc:date>
    <item>
      <title>Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383459#M83662</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;I am just learning ArcGIS Maps SDK for Javascript, and in the process, I am trying to create a simple application that should highlight the features after executing a query. The code is as follows :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/widgets/Popup", "esri/widgets/Legend", "esri/widgets/LayerList", "esri/rest/query", "esri/rest/support/Query"], function (esriConfig, Map, MapView, FeatureLayer, Popup, Legend, LayerList, query, Query) {

            esriConfig.apiKey = "XXXXXXXXX";

            const colors = ["#d92b30", "#3cccb4", "#ffdf3c", "#c27c30", "#f260a1"];

            const commonProperties = {
                type: "simple-marker",
                width: "2px",
                style: "circle"
            };

            const gujarat = {
                ...commonProperties,
                color: colors[0]
            }
            
            const odisha = {
                ...commonProperties,
                color: colors[1]
            }

            const punjab = {
                ...commonProperties,
                color: colors[2]
            }

            const tamilnadu = {
                ...commonProperties,
                color: colors[3]
            }

            const other = {
                ...commonProperties,
                color: colors[4]
            }

            const ptrenderer = {
                type: "unique-value",
                legendOptions:{
                    title: "State Name"
            },
            defaultSymbol: other,
            defaultLabel: "Others",
            field: "state",

            uniqueValueInfos: [
            {
              value: "Gujarat", // code for Gujarat
              symbol: gujarat,
              label: "Gujarat"
            },
            {
              value: "Odisha", // code for Odisha
              symbol: odisha,
              label: "Odisha"
            },
            {
              value: "Punjab", // code for Punjab
              symbol: punjab,
              label: "Punjab"
            },
            {
              value: "Tamil Nadu", // code for Tamil Nadu
              symbol: tamilnadu,
              label: "Tamil Nadu"
            }
          ]

        }

            const params = new Query({
              returnGeometry: true,
              outFields: ["*"]
            });
            
            const map = new Map({
                basemap: "arcgis-topographic"
            });

            const view = new MapView({
                map: map,
                center: [78.9629, 20.5937],
                zoom: 5,
                container: "viewDiv",
                popup: new Popup({
                    defaultPopupTemplateEnabled : true
                }),
            });

            const featureLayer = new FeatureLayer({
                url : "https://services6.arcgis.com/Cj6ppUYzylKGUnEi/arcgis/rest/services/India_Wetlands/FeatureServer",
                renderer: ptrenderer
            });

            view.when(() =&amp;gt; {
            view.ui.add("optionsDiv", "bottom-right");
            document.getElementById("doBtn").addEventListener("click", doQuery);
             });

            const attributeName = document.getElementById("attSelect");
            const expressionSign = document.getElementById("signSelect");
            const value = document.getElementById("valSelect");

            function doQuery() {
            // Clear the results from a previous query and close the popup if its open.
            //featureLayer.removeAll();
            if (view.popup.visible) {
            view.closePopup();
            }
            
            params.where = attributeName.value + expressionSign.value + "'" + value.value + "'";

             // executes the query and calls getResults() once the promise is resolved
             // promiseRejected() is called if the promise is rejected
             featureLayer.queryFeatures(params).then(getResults).catch(promiseRejected);
            }

            function getResults(results){
                const symbol = {
                    type: "simple-marker",
                    color : [20, 30, 100, 0.5],
                    outline: {
                        color: "white",
                        width: .5
                    }
                }

                results.features.map((feature) =&amp;gt; {
                    feature.symbol = symbol
                    return feature
                })
            }

             // Called each time the promise is rejected
            function promiseRejected(error) {
            console.error("Promise rejected: ", error.message);
             }



            view.when(()=&amp;gt;{
                const layerlist = new LayerList({
                    view : view
                })
            view.ui.add(layerlist, "top-right")
            })

            view.ui.add(new Legend({ view }), "bottom-left");

            //const featureLayer = new FeatureLayer({
                //url : "https://services6.arcgis.com/Cj6ppUYzylKGUnEi/arcgis/rest/services/India_Wetlands/FeatureServer",
                //renderer: ptrenderer
            //});

            const statesLayer = new FeatureLayer({
                url: "https://livingatlas.esri.in/server1/rest/services/IAB/State/MapServer/0"
            })
            //});   
            map.add(statesLayer,0)
            map.add(featureLayer)
        });&lt;/LI-CODE&gt;&lt;P&gt;The application loads just fine and am able to see the features however, after executing the query nothing happens and there is no error in the console as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the following links as reference :&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/tutorials/query-a-feature-layer-sql/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/tutorials/query-a-feature-layer-sql/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe as both the links are referring to graphic layer and am using a feature layer, that could be causing some issue. Not sure what am I missing here.&lt;/P&gt;&lt;P&gt;Any suggestions would be helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 16:21:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383459#M83662</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2024-02-16T16:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383478#M83664</link>
      <description>&lt;P&gt;Can you share your query parameters? I am guessing that is where the issue is. The code above does not help to narrow down the issue. You can open the network request tab and see if the service is returning any results for your query since you are issuing the query on the layer.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 16:42:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383478#M83664</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-02-16T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383488#M83666</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp; Here is the rest of HTML code that constructs the query:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="esri-widget" id="optionsDiv"&amp;gt;
        &amp;lt;h2&amp;gt;Test.&amp;lt;/h2&amp;gt;
        &amp;lt;select class="esri-widget" id="attSelect"&amp;gt;
          &amp;lt;option value="State"&amp;gt;State&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
        &amp;lt;select class="esri-widget" id="signSelect"&amp;gt;
          &amp;lt;option value="="&amp;gt;is equal to&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
        &amp;lt;select class="esri-widget" id="valSelect"&amp;gt;
          &amp;lt;option value="Gujarat"&amp;gt;Gujarat&amp;lt;/option&amp;gt;
          &amp;lt;option value="Tamil Nadu"&amp;gt; Tamil Nadu&amp;lt;/option&amp;gt;
          &amp;lt;option value="Punjab"&amp;gt;Punjab&amp;lt;/option&amp;gt;
          &amp;lt;option value="Odisha"&amp;gt;Odisha&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;button class="esri-widget" id="doBtn"&amp;gt;Do Query&amp;lt;/button&amp;gt; &amp;lt;br /&amp;gt;
        &amp;lt;p&amp;gt;&amp;lt;span id="printResults"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also checked the network tab and I can see that query does get executed, the issue is that features which satisfy a particular query are not getting highlighted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wizgis_0-1708103028420.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/95050i944734375FE23206/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wizgis_0-1708103028420.png" alt="wizgis_0-1708103028420.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 17:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383488#M83666</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2024-02-16T17:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383508#M83669</link>
      <description>&lt;P&gt;The problem here is that you're trying to highlight graphics in a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html" target="_self"&gt;FeatureLayer&lt;/A&gt; by assigning a new symbol to them.&amp;nbsp; That would've worked in 3.x, but not in 4.x.&amp;nbsp; To highlight FeatureLayer graphics in 4.x, you need to get a reference to the layer's associated &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html" target="_self"&gt;FeatureLayerView&lt;/A&gt;, and then use its &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html#highlight" target="_self"&gt;highlight&lt;/A&gt; method.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 17:19:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383508#M83669</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2024-02-16T17:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383525#M83670</link>
      <description>&lt;P&gt;So you need to highlight features using &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html#highlight" target="_self"&gt;FeatureLayerView.highlight&lt;/A&gt; method.&lt;/P&gt;&lt;P&gt;Please take a look this codepen:&amp;nbsp;&lt;A href="https://codepen.io/U_B_U/pen/PoLVeVq?editors=1000" target="_blank"&gt;https://codepen.io/U_B_U/pen/PoLVeVq?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This sample could be useful:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/highlight-features-by-geometry/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/highlight-features-by-geometry/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 17:55:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383525#M83670</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-02-16T17:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Features not getting highlighted based on a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383799#M83674</link>
      <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp;. This is exactly that I was hoping to achieve.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2024 15:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-getting-highlighted-based-on-a-query/m-p/1383799#M83674</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2024-02-17T15:03:47Z</dc:date>
    </item>
  </channel>
</rss>

