<?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: Remove Highlighted Features in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439648#M40544</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Apr 2019 12:25:09 GMT</pubDate>
    <dc:creator>JeremySingh1</dc:creator>
    <dc:date>2019-04-01T12:25:09Z</dc:date>
    <item>
      <title>Remove Highlighted Features</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439646#M40542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So whenever I click the buttons below in the webpage, it doesn't&amp;nbsp;seem to remove the highlighted features properly from my map. Could anyone see the reason why none of the highlighted features are not removed properly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;BR /&gt;&amp;lt;html&amp;gt;&lt;BR /&gt;&amp;lt;head&amp;gt;&lt;BR /&gt;&amp;lt;meta charset="utf-8"&amp;gt;&lt;BR /&gt;&amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"&amp;gt;&lt;BR /&gt;&amp;lt;title&amp;gt;Intro to PopupTemplate - 4.10&amp;lt;/title&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;style&amp;gt;&lt;BR /&gt;html,&lt;BR /&gt;body,&lt;BR /&gt;#viewDiv {&lt;BR /&gt;padding: 0;&lt;BR /&gt;margin: 0;&lt;BR /&gt;height: 100%;&lt;BR /&gt;width: 100%;&lt;BR /&gt;}&lt;BR /&gt;#paneDiv {&lt;BR /&gt;position: absolute;&lt;BR /&gt;bottom: 0;&lt;BR /&gt;width: 100%;&lt;BR /&gt;padding: 20px 0;&lt;BR /&gt;z-index: 1;&lt;BR /&gt;text-align: center;&lt;BR /&gt;}&lt;BR /&gt;button {&lt;BR /&gt;background: white;&lt;BR /&gt;padding: 7px;&lt;BR /&gt;border: 1px solid #005e95;&lt;BR /&gt;font-size: 0.9em;&lt;BR /&gt;margin: 5px;&lt;BR /&gt;color: #005e95;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;lt;/style&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css"&amp;gt;&lt;BR /&gt;&amp;lt;script src="https://js.arcgis.com/4.10/"&amp;gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;require([&lt;BR /&gt;"esri/Map",&lt;BR /&gt;"esri/layers/FeatureLayer",&lt;BR /&gt;"esri/views/MapView"&lt;BR /&gt;], function(&lt;BR /&gt;Map,&lt;BR /&gt;FeatureLayer,&lt;BR /&gt;MapView&lt;BR /&gt;) {&lt;BR /&gt;//&lt;BR /&gt;// const fLayer = new featureLayer({&lt;BR /&gt;// portalItem: {&lt;BR /&gt;// id: "bba798b019ce4f20ac7db2b1f5df860c#data"&lt;BR /&gt;// }&lt;BR /&gt;// });&lt;BR /&gt;var template = { // autocasts as new PopupTemplate()&lt;BR /&gt;title: "This Lot is {Lot} SQFT in Size",&lt;BR /&gt;content: [{&lt;BR /&gt;// It is also possible to set the fieldInfos outside of the content&lt;BR /&gt;// directly in the popupTemplate. If no fieldInfos is specifically set&lt;BR /&gt;// in the content, it defaults to whatever may be set within the popupTemplate.&lt;BR /&gt;type: "fields",&lt;BR /&gt;fieldInfos: [{&lt;BR /&gt;fieldName: "Borough",&lt;BR /&gt;label: "Borough",&lt;BR /&gt;visible: true&lt;BR /&gt;}, {&lt;BR /&gt;fieldName: "Block",&lt;BR /&gt;label: "Block",&lt;BR /&gt;visible: true,&lt;BR /&gt;format: {&lt;BR /&gt;digitSeparator: true,&lt;BR /&gt;places: 0&lt;BR /&gt;}&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;};&lt;BR /&gt;var featureLayer = new FeatureLayer({&lt;BR /&gt;portalItem: {&lt;BR /&gt;id:"bba798b019ce4f20ac7db2b1f5df860c"&lt;BR /&gt;},&lt;BR /&gt;popupTemplate: template&lt;BR /&gt;});&lt;BR /&gt;// Create the map&lt;BR /&gt;var map = new Map({&lt;BR /&gt;basemap: "gray",&lt;BR /&gt;layers: [featureLayer]&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;// Create the MapView&lt;BR /&gt;var view = new MapView({&lt;BR /&gt;container: "viewDiv",&lt;BR /&gt;map: map,&lt;BR /&gt;center: [-73.954509, 40.620479],&lt;BR /&gt;zoom: 13&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;/*************************************************************&lt;BR /&gt;* The PopupTemplate content is the text that appears inside the&lt;BR /&gt;* popup. {fieldName} can be used to reference the value of an&lt;BR /&gt;* attribute of the selected feature. HTML elements can be used&lt;BR /&gt;* to provide structure and styles within the content. The&lt;BR /&gt;* fieldInfos property is an array of objects (each object representing&lt;BR /&gt;* a field) that is use to format number fields and customize field&lt;BR /&gt;* aliases in the popup and legend.&lt;BR /&gt;**************************************************************/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Reference the popupTemplate instance in the&lt;BR /&gt;// popupTemplate property of FeatureLayer&lt;BR /&gt;//&lt;/P&gt;&lt;P&gt;//map.add(featureLayer);&lt;BR /&gt;var highlightSelect;&lt;BR /&gt;//var hoverPromise;&lt;/P&gt;&lt;P&gt;view.when(function(){&lt;BR /&gt;var lotLayer = map.layers.getItemAt(0);&lt;BR /&gt;view.whenLayerView(lotLayer).then(function(layerView){&lt;BR /&gt;var queryLots = lotLayer.createQuery();&lt;BR /&gt;var buttons = document.querySelectorAll("button");&lt;BR /&gt;for (var i = 0, button = null; button = buttons&lt;I&gt;; i++){&lt;BR /&gt;console.log(button);&lt;BR /&gt;button.addEventListener("click", onClick);&lt;BR /&gt;}&lt;BR /&gt;function onClick(event){&lt;/I&gt;&lt;/P&gt;&lt;P&gt;queryLots.where = "Lot='" + event.target.innerText + "'";&lt;BR /&gt;lotLayer.queryFeatures(queryLots).then(&lt;BR /&gt;function(result){&lt;BR /&gt;//var x = null;&lt;BR /&gt;if (highlightSelect){&lt;/P&gt;&lt;P&gt;highlightSelect.remove();&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;for(x = 0; x &amp;lt; result.features.length; x++){&lt;/P&gt;&lt;P&gt;var feature = result.features&lt;X&gt;;&lt;BR /&gt;//console.log(feature);&lt;BR /&gt;highlightSelect = layerView.highlight(feature.attributes['OBJECTID']);&lt;BR /&gt;//console.log(highlightSelect);&lt;/X&gt;&lt;/P&gt;&lt;P&gt;//return x;&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;});&lt;/P&gt;&lt;P&gt;})&lt;BR /&gt;});&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;/head&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;body&amp;gt;&lt;BR /&gt;&amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;&lt;BR /&gt;&amp;lt;div id="paneDiv"&amp;gt;&lt;BR /&gt;&amp;lt;h3&amp;gt; Click to polygons with these SQFT &amp;lt;/h3&amp;gt;&lt;BR /&gt;&amp;lt;button&amp;gt;1&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;button&amp;gt;18&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;button&amp;gt;67&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;/div&amp;gt;&lt;BR /&gt;&amp;lt;/body&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/html&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Mar 2019 20:07:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439646#M40542</guid>
      <dc:creator>JeremySingh1</dc:creator>
      <dc:date>2019-03-29T20:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Highlighted Features</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439647#M40543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your for loop, you keep reassigning the highlightSelect to the last feature, so you've lost the reference to all the other highlights to remove them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;x &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; x &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;features&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;length&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; x&lt;SPAN class="operator token"&gt;++&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; feature &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;features&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;x&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// this keeps getting reassigned&lt;/SPAN&gt;
  highlightSelect &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; layerView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;highlight&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;feature&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;attributes&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"OBJECTID"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can fix by pushing all the object ids into an array, and highlight them all at once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; oids &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;x &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; x &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;features&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;length&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; x&lt;SPAN class="operator token"&gt;++&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; feature &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;features&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;x&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
  oids&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;push&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;feature&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;attributes&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'OBJECTID'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
highlightSelect &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; layerView&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;highlight&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;oids&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you can properly remove the highlight on each button click.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:40:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439647#M40543</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T19:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Highlighted Features</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439648#M40544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Apr 2019 12:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/remove-highlighted-features/m-p/439648#M40544</guid>
      <dc:creator>JeremySingh1</dc:creator>
      <dc:date>2019-04-01T12:25:09Z</dc:date>
    </item>
  </channel>
</rss>

