<?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 Features not changing on executing query in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339057#M82496</link>
    <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a query app that executes a query based on a condition. I am using the following sample code example for reference purpose :&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query app that I am working on seems to work fine as am getting correct number of records for a particular query that gets executed however, the issue is the features are not being returned correctly.&lt;/P&gt;&lt;P&gt;Initially, when I set the same query in map viewer (red dots) and in the application (green dots) features are returned correctly as shown in the first two figures 1 &amp;amp;&amp;nbsp; 2 however, if I change the query in the application and and in map viewer discrepancy is observed as shown in the last two figures 3 &amp;amp; 4.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure1.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83355i855AB6F67B1E1462/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure1.png" alt="Figure1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure2.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83357i1E3D17DA5FB912FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure2.png" alt="Figure2.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure3.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83356i346DB4640D83B70D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure3.png" alt="Figure3.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure4.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83358iE463F426461F5512/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure4.png" alt="Figure4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not sure what am I missing here and why features are not being correctly. Any inputs on this would be helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2023 12:03:11 GMT</pubDate>
    <dc:creator>wizgis</dc:creator>
    <dc:date>2023-10-18T12:03:11Z</dc:date>
    <item>
      <title>Features not changing on executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339057#M82496</link>
      <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a query app that executes a query based on a condition. I am using the following sample code example for reference purpose :&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The query app that I am working on seems to work fine as am getting correct number of records for a particular query that gets executed however, the issue is the features are not being returned correctly.&lt;/P&gt;&lt;P&gt;Initially, when I set the same query in map viewer (red dots) and in the application (green dots) features are returned correctly as shown in the first two figures 1 &amp;amp;&amp;nbsp; 2 however, if I change the query in the application and and in map viewer discrepancy is observed as shown in the last two figures 3 &amp;amp; 4.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure1.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83355i855AB6F67B1E1462/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure1.png" alt="Figure1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure2.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83357i1E3D17DA5FB912FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure2.png" alt="Figure2.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure3.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83356i346DB4640D83B70D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure3.png" alt="Figure3.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Figure4.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83358iE463F426461F5512/image-size/large?v=v2&amp;amp;px=999" role="button" title="Figure4.png" alt="Figure4.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not sure what am I missing here and why features are not being correctly. Any inputs on this would be helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 12:03:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339057#M82496</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2023-10-18T12:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Features not changing on executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339121#M82498</link>
      <description>&lt;P&gt;Can you post your before and after queries?&amp;nbsp; Some code snippets of how it was before vs. now would be helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2023 13:48:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339121#M82498</guid>
      <dc:creator>TimDietz</dc:creator>
      <dc:date>2023-10-18T13:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Features not changing on executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339444#M82507</link>
      <description>&lt;LI-CODE lang="javascript"&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.0"&amp;gt;
    &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        html, body, 
        #viewDiv{
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%
        }

        #optionsDiv {
        background-color: dimgray;
        color: white;
        padding: 10px;
        width: 350px;
        }

      .esri-popup .esri-popup-header .esri-title {
        font-size: 18px;
        font-weight: bolder;
      }

      .esri-popup .esri-popup-body .esri-popup-content {
        font-size: 14px;
      }
    &amp;lt;/style&amp;gt;
      &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.27/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.27/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
    require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/layers/GraphicsLayer", "esri/rest/query", "esri/rest/support/Query"], function(esriConfig, Map, MapView, FeatureLayer, GraphicsLayer, query, Query){
    
    esriConfig.apiKey = ""

    const floraURL = ""

    const popupTemplate = {
        title: "{Classification}, {Name}", 
        fieldInfos: [
            {
                fieldName: "Classification",
                label: "Classification"
            },
            {
                fieldName: "ParasiteInfection",
                label: "Parasite Infection Identified"
            },

            {
                fieldName: "Threats",
                label: "Threats Identified"
            }
    ],
    content: "Classification of Flora : {Classification} &amp;lt;br&amp;gt; " +
    "Any Parasite Infection : {ParasiteInfection} &amp;lt;br&amp;gt;" +
    "Are there any threats that have been identified : {Threats} &amp;lt;br&amp;gt;"
    };


    const resultsLayer = new GraphicsLayer();

    const params = new Query({
          returnGeometry: true,
          outFields: ["*"]
        });

    var map = new Map({
        basemap: "arcgis-topographic",
        layers: [resultsLayer]
    });

    var view = new MapView({
        map: map,
        center: [0,0],
        zoom: 15,
        container: "viewDiv",
        popup: {
            dockEnabled : true,
            dockOptions: {
                position: "top-right",
                breakpoint: false
            }
        }
    }); 

    view.when(function(){
        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(){
        params.where = attributeName.value + expressionsign.value + "'" + value.value + "'";

        query
            .executeQueryJSON(floraURL, params)
            .then(getResults)
            .catch(promiseRejected);
        }

    function getResults(response){
        const results = response.features.map(function (feature){
            feature.symbol = {
                type: "simple-marker", // Use simple-marker for 2D symbology
                color: "green", // Set the color of the marker
                size: 10, // Set the size of the marker
                outline: {
                    color: [0, 0, 0, 0.5], // Set the outline color and transparency
                    width: 1 // Set the outline width
                }
            };

            feature.popupTemplate = popupTemplate;
            return feature;
        });

        resultsLayer.addMany(results)

        view.goTo(results).then(function(){
            view.openPopup({
                features: results,
                featureMenuOpen: true,
                updateLocationEnabled: true
            });
        })
        .catch(function (error){
            if (error.name !== "AbourtError"){
                console.error(error);
            }
        });

        document.getElementById("printResults").innerHTML = results.length + "Results Found";

    }

    function promiseRejected(error){
        console.error("Promise Rejected: ", error.message);
    }
    });
    &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 class="esri-widget" id = "optionsDiv"&amp;gt;
        &amp;lt;h2&amp;gt;Flora Diversity of Sanjay Van.&amp;lt;/h2&amp;gt;
        &amp;lt;select class="esri-widget" id="attSelect"&amp;gt;
            &amp;lt;option value="Classification"&amp;gt;Classification&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="Herb"&amp;gt;Herb&amp;lt;/option&amp;gt;
            &amp;lt;option value="Climber"&amp;gt;Climber&amp;lt;/option&amp;gt;
            &amp;lt;option value="Shrub"&amp;gt;Shrub&amp;lt;/option&amp;gt;
            &amp;lt;option value="Tree"&amp;gt;Tree&amp;lt;/option&amp;gt;
            &amp;lt;option value="Grass"&amp;gt;Grass&amp;lt;/option&amp;gt;
            &amp;lt;option value="Others"&amp;gt;Others&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;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&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/590435"&gt;@TimDietz&lt;/a&gt;&amp;nbsp;I am attaching the code snippet that is being used. Based on my understanding and research that I have done so far it feels like I need to have a function/code that removes the features of current query first and then draw new features based on the new query that the user has put.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just not sure where and how to add this piece of code.&amp;nbsp; Any insights would be helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 05:15:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339444#M82507</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2023-10-19T05:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Features not changing on executing query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339462#M82509</link>
      <description>&lt;P class="lia-align-left"&gt;&lt;STRONG&gt;Update :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I was able to get it to work by adding the following line of code :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;resultsLayer.removeAll(results)&lt;/LI-CODE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 19 Oct 2023 07:46:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/features-not-changing-on-executing-query/m-p/1339462#M82509</guid>
      <dc:creator>wizgis</dc:creator>
      <dc:date>2023-10-19T07:46:21Z</dc:date>
    </item>
  </channel>
</rss>

