<?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: Unselect/clear a feature from a feature layer using a query in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083283#M74039</link>
    <description>&lt;P&gt;^&lt;/P&gt;&lt;P&gt;I've already tried that. My feature is already selected before I even enter my function. If I try to just do ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(highlightSelect)
      highlightSelect.remove();&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;... it has no idea what highlightSelect is. So I have to define it beforehand ... somehow. I could try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function unselectParcel()
{
 myView.whenLayerView(myLayer).then(function(layerView)
 {	
  myLayer.queryFeatures(query).then(function(result)
   {
    let query = myLayer.createQuery();
    query.where = "MyFieldName = '" + myVariable + "'";
		
    let highlightSelect;
    highlightSelect = myView.highlight(result.attributes["OBJECTID"]);
    if(highlightSelect) highlightSelect.remove();
   });
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but of course that doesn't work because&amp;nbsp; I'm passing in a query to myLayer.queryFeatures that isn't even declared or defined yet. So I next try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function unselectParcel()
{
 myView.whenLayerView(myLayer).then(function(layerView)
 {
  let query = myLayer.createQuery();
  query.where = "MyFieldName = '" + myVariable + "'";

  myLayer.queryFeatures(query).then(function(result)
   {		
    let highlightSelect = result.features[0];
    highlightSelect.remove();
   });
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which gives me the error message:&amp;nbsp;"&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;&lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;TypeError: &lt;SPAN class="objectBox objectBox-string"&gt;highlightSelect.remove is not a function." Which is what I mentioned in my first post here.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jul 2021 21:11:47 GMT</pubDate>
    <dc:creator>Jackson_CountyMissouri</dc:creator>
    <dc:date>2021-07-27T21:11:47Z</dc:date>
    <item>
      <title>Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083161#M74033</link>
      <description>&lt;P&gt;This is sort-of a follow-up to my thread here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/querying-one-feature-layer-to-use-to-query-another/m-p/1076044#M73742" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/querying-one-feature-layer-to-use-to-query-another/m-p/1076044#M73742&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'm now trying to do the opposite: I need to unselect/clear an already selected feature in a feature layer, using a query or anything else besides getting the Popup involved. I have looked through the 4.X API as well as some examples on this board, but can't find anything that works. In the API for FeatureLayerView.highlight there is a snippet that uses&amp;nbsp;&lt;SPAN&gt;highlight.remove(), but every time I try to use it, my developer console tells me that the .remove() is not a function, which doesn't surprise me because there is no .remove function anywhere I can find in the API.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to do something like this. FYI the myVariable variable is something I've already retrieved earlier that will represent the feature that's been highlighted.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function unselectParcel()
{
 var myQuery = myLayer.createQuery();
 myQuery.where = "MyFieldName = '" + myVariable + "'";

 myLayer.queryFeatures(myQuery).then(function(response)
 {
  myView.whenLayerView(myLayer).then(function(layerView)
  {
   var feature = response.features[0];
   layerView.highlight.remove(feature.attributes["OBJECTID"]);
   });
  });
}&lt;/LI-CODE&gt;&lt;P&gt;As I said, the .remove() does not work, and I've tried all kinds of different iterations of it, to no avail. I've also tried putting the queryFeatures inside of the whenLayerView and all kinds of other arrangements, but since my selecting-the-feature function works fine and all I want to do is the reverse of that, it seems like I should just be able to make a minor change to that selecting-the-feature code - right? I can't believe they have a "highlight" function but no "clear" or "un-highlight" function.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:03:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083161#M74033</guid>
      <dc:creator>Jackson_CountyMissouri</dc:creator>
      <dc:date>2021-07-27T18:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083261#M74037</link>
      <description>&lt;P&gt;According to the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html#highlight" target="_blank" rel="noopener"&gt;highlight function&lt;/A&gt; it returns a handler that you can use to remove the highlight. There is also a good sample showing how it works:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/highlight-point-features/" target="_blank" rel="noopener"&gt;Highlight point features&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First you setup a variable to hold the highlight selection handler:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;let highlightSelect;&lt;/LI-CODE&gt;&lt;P&gt;Then when you do a query you can remove the current highlight before doing the new one (you can see where it is assigning the handler to highlightSelect in line 11):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;myLayer.queryFeatures(myQuery).then((result) =&amp;gt; {
// if a feature is already highlighted, then remove the highlight
if (highlightSelect) {
  highlightSelect.remove();
}

// the feature to be highlighted
const feature = result.features[0];

// use the objectID to highlight the feature
highlightSelect = layerView.highlight(
  feature.attributes["OBJECTID"]
);&lt;/LI-CODE&gt;&lt;P&gt;You could also just remove the highlight any time you wish:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;highlightSelect.remove();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 20:21:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083261#M74037</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-07-27T20:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083283#M74039</link>
      <description>&lt;P&gt;^&lt;/P&gt;&lt;P&gt;I've already tried that. My feature is already selected before I even enter my function. If I try to just do ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(highlightSelect)
      highlightSelect.remove();&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;... it has no idea what highlightSelect is. So I have to define it beforehand ... somehow. I could try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function unselectParcel()
{
 myView.whenLayerView(myLayer).then(function(layerView)
 {	
  myLayer.queryFeatures(query).then(function(result)
   {
    let query = myLayer.createQuery();
    query.where = "MyFieldName = '" + myVariable + "'";
		
    let highlightSelect;
    highlightSelect = myView.highlight(result.attributes["OBJECTID"]);
    if(highlightSelect) highlightSelect.remove();
   });
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but of course that doesn't work because&amp;nbsp; I'm passing in a query to myLayer.queryFeatures that isn't even declared or defined yet. So I next try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function unselectParcel()
{
 myView.whenLayerView(myLayer).then(function(layerView)
 {
  let query = myLayer.createQuery();
  query.where = "MyFieldName = '" + myVariable + "'";

  myLayer.queryFeatures(query).then(function(result)
   {		
    let highlightSelect = result.features[0];
    highlightSelect.remove();
   });
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which gives me the error message:&amp;nbsp;"&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;&lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;TypeError: &lt;SPAN class="objectBox objectBox-string"&gt;highlightSelect.remove is not a function." Which is what I mentioned in my first post here.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 21:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083283#M74039</guid>
      <dc:creator>Jackson_CountyMissouri</dc:creator>
      <dc:date>2021-07-27T21:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083314#M74040</link>
      <description>&lt;P&gt;You need to define the variable outside the functions in the main code (sort of like a global variable). The highlightSelect variable will know what feature was highlighted, so you don't need to query it again in the unselect function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let highlightSelect;

function selectParcel()
{
    //Query feature first
    highlightSelect = layerView.highlight(feature.attributes["OBJECTID"]);
}

function unselectParcel()
{
    if(highlightSelect) highlightSelect.remove();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 22:02:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083314#M74040</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-07-27T22:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083318#M74041</link>
      <description>&lt;P&gt;Still getting the "&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;&lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;TypeError:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="objectBox objectBox-string"&gt;highlightSelect.remove is not a function" error message. However, at least it's clearing the newest selected feature instead of the one I want to be selected (which is the previous selected feature), so maybe at least it's doing *something*&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 22:03:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083318#M74041</guid>
      <dc:creator>Jackson_CountyMissouri</dc:creator>
      <dc:date>2021-07-27T22:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unselect/clear a feature from a feature layer using a query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083321#M74042</link>
      <description>&lt;P&gt;If all you want to do is remove the previous highlight when doing a new query then try this (note: nu unselect function):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let highlightSelect;

function selectParcel()
{
    //Remove highlights
    if (highlightSelect) {
        highlightSelect.remove();
    }
    //Query feature first
    highlightSelect = layerView.highlight(feature.attributes["OBJECTID"]);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If it's a more complicated scenario than that, then you may have to post some more complete code.&lt;/P&gt;&lt;P&gt;I recommend having a play around with that highlight point features sample I posted earlier.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 22:14:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/unselect-clear-a-feature-from-a-feature-layer/m-p/1083321#M74042</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-07-27T22:14:53Z</dc:date>
    </item>
  </channel>
</rss>

