<?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: How to refresh map after calling GraphicsLayer.remove()? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315526#M29001</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you sure you're getting to selectGraphics.remove()? Try putting a console.log("removed graphic"); after selectGraphics.remove(). I ask because I think you're using array.splice incorrectly. Check out the MDN doc for more info:&amp;nbsp; &lt;A href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice"&gt;https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure what I was thinking on that, but that wasn't the problem.&amp;nbsp; I've updated my code to splice correctly, confirmed that the splice does work correctly (my accounts array has the proper objects in it after the splice), and I've confirmed I do get to selectedGraphics.remove(graphic), and continue without any errors.&amp;nbsp; The map does not update.&amp;nbsp; I've updated my code to show the corrected splice method.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Aug 2012 18:21:01 GMT</pubDate>
    <dc:creator>ShawnHolyoak</dc:creator>
    <dc:date>2012-08-13T18:21:01Z</dc:date>
    <item>
      <title>How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315522#M28997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to allow users to select and unselect parcels in my map.&amp;nbsp; The select works great, becauseGraphicsLayer.add() calls a "refresh" method of some sort that draws my graphics layer when invoked.&amp;nbsp; Unfortunately, when I call GraphicsLayer.remove(), that "refresh" method isn't invoked, and my graphics layer in the map is not updated, showing the graphic as still selected.&amp;nbsp; How do I remove a graphic from a GraphicsLayer and have the map update?&amp;nbsp; I'm on version 2.8 of the api.&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 15:22:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315522#M28997</guid>
      <dc:creator>ShawnHolyoak</dc:creator>
      <dc:date>2012-08-13T15:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315523#M28998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you post some code to reproduce what you're seeing? I'm guessing the argument you're passing to GraphicsLayer.remove() isn't a graphic. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's a simple page that shows using GraphicsLayer.remove():&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://jsfiddle.net/RsbD2/"&gt;http://jsfiddle.net/RsbD2/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 17:37:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315523#M28998</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2012-08-13T17:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315524#M28999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you post some code to reproduce what you're seeing? I'm guessing the argument you're passing to GraphicsLayer.remove() isn't a graphic. &lt;BR /&gt;&lt;BR /&gt;Here's a simple page that shows using GraphicsLayer.remove():&amp;nbsp; &lt;A href="http://jsfiddle.net/RsbD2/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://jsfiddle.net/RsbD2/&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure how it wouldn't be a graphic, or if it's not, it's the same object being passed to the add method as the remove method.&amp;nbsp; My method is shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function showSelection(featureSet) {
 //remove all the selectedGraphics from the map, unless the CTRL key is pressed, leaving any drawnGraphics on the map
 if (!selectEvent.ctrlKey) {
&amp;nbsp; selectedGraphics.clear();
&amp;nbsp; accounts = [];
 }
 
 //QueryTask returns a feature set.&amp;nbsp; Loop through the featureset and add them to the map
 dojo.forEach(featureSet.features, function(feature){
&amp;nbsp; var graphic = feature;
&amp;nbsp; 
&amp;nbsp; //add the feature if it is not already in the collection
&amp;nbsp; if (accounts.indexOf(feature.attributes.ACCT) == -1) {
&amp;nbsp;&amp;nbsp; accounts.push(feature.attributes.ACCT);
&amp;nbsp;&amp;nbsp; graphic.setSymbol(symbol);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //add the graphic to the selectedGraphics layer
&amp;nbsp;&amp;nbsp; selectedGraphics.add(graphic);
&amp;nbsp; } else {
&amp;nbsp;&amp;nbsp; accounts.splice(accounts.indexOf(feature.attributes.ACCT),1);
&amp;nbsp;&amp;nbsp; selectedGraphics.remove(graphic);
&amp;nbsp; }
 });
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:00:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315524#M28999</guid>
      <dc:creator>ShawnHolyoak</dc:creator>
      <dc:date>2021-12-11T15:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315525#M29000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you sure you're getting to selectGraphics.remove()? Try putting a console.log("removed graphic"); after selectGraphics.remove(). I ask because I think you're using array.splice incorrectly. Check out the MDN doc for more info:&amp;nbsp; &lt;/SPAN&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice"&gt;https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 18:02:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315525#M29000</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2012-08-13T18:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315526#M29001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you sure you're getting to selectGraphics.remove()? Try putting a console.log("removed graphic"); after selectGraphics.remove(). I ask because I think you're using array.splice incorrectly. Check out the MDN doc for more info:&amp;nbsp; &lt;A href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice"&gt;https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure what I was thinking on that, but that wasn't the problem.&amp;nbsp; I've updated my code to splice correctly, confirmed that the splice does work correctly (my accounts array has the proper objects in it after the splice), and I've confirmed I do get to selectedGraphics.remove(graphic), and continue without any errors.&amp;nbsp; The map does not update.&amp;nbsp; I've updated my code to show the corrected splice method.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 18:21:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315526#M29001</guid>
      <dc:creator>ShawnHolyoak</dc:creator>
      <dc:date>2012-08-13T18:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315527#M29002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Taking a closer look at this, graphic is a reference to a feature returned from a query task, meaning that it isn't actually in your graphics layer yet. You need to find the graphic in selectedGraphics.graphics with a particular ACCT value and pass that to selectedGraphics.remove(). I would use dojo.filter or maybe dojo.some with selectedGraphics.graphics to do this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 18:35:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315527#M29002</guid>
      <dc:creator>derekswingley1</dc:creator>
      <dc:date>2012-08-13T18:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to refresh map after calling GraphicsLayer.remove()?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315528#M29003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Taking a closer look at this, graphic is a reference to a feature returned from a query task, meaning that it isn't actually in your graphics layer yet. You need to find the graphic in selectedGraphics.graphics with a particular ACCT value and pass that to selectedGraphics.remove(). I would use dojo.filter or maybe dojo.some with selectedGraphics.graphics to do this.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;That indeed was the problem.&amp;nbsp; Once I referenced the actual graphic in the GraphicsLayer, things work properly.&amp;nbsp; Final code below.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function showSelection(featureSet) {
 //remove all the selectedGraphics from the map, unless the CTRL key is pressed, leaving any drawnGraphics on the map
 if (!selectEvent.ctrlKey) {
&amp;nbsp; selectedGraphics.clear();
&amp;nbsp; accounts = [];
 }
 
 //QueryTask returns a feature set.&amp;nbsp; Loop through the featureset and add them to the map
 dojo.forEach(featureSet.features, function(feature){
&amp;nbsp; var graphic = feature;
&amp;nbsp; 
&amp;nbsp; //add the feature if it is not already in the collection
&amp;nbsp; if (accounts.indexOf(feature.attributes.ACCT) == -1) {
&amp;nbsp;&amp;nbsp; accounts.push(feature.attributes.ACCT);
&amp;nbsp;&amp;nbsp; graphic.setSymbol(symbol);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //add the graphic to the selectedGraphics layer
&amp;nbsp;&amp;nbsp; selectedGraphics.add(graphic);
&amp;nbsp; } else {
&amp;nbsp;&amp;nbsp; accounts.splice(accounts.indexOf(feature.attributes.ACCT),1);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; //get the graphic that matches the feature
&amp;nbsp;&amp;nbsp; var filteredGraphics = dojo.filter(selectedGraphics.graphics, function(item) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; return item.attributes.ACCT == feature.attributes.ACCT;
&amp;nbsp;&amp;nbsp; })
&amp;nbsp;&amp;nbsp; graphic = filteredGraphics[0];
&amp;nbsp;&amp;nbsp; selectedGraphics.remove(graphic);
&amp;nbsp; }
 });
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:00:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-refresh-map-after-calling-graphicslayer/m-p/315528#M29003</guid>
      <dc:creator>ShawnHolyoak</dc:creator>
      <dc:date>2021-12-11T15:00:53Z</dc:date>
    </item>
  </channel>
</rss>

