<?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: Change index of a graphic in a GraphicsLayer in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721629#M66986</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The setzindex of a graphic in a layer is what I'd be interested in but it looks like it's been removed in the latest version of the API (at least I don't see it anywhere in the API reference guide).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did see another old post that used getDojoShape().moveToFront(). I suppose I could iterate through all the graphics and move them to front/back in the right order to reorder them. But, moveToFront only makes it look like that shape is the top graphic. The order of the graphics are still the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's looking like remove all and add in the order that I want them in. I just don't want to see graphics flashing. Maybe it's going to be fast enough that the user doesn't see them redrawn?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Nov 2015 20:53:37 GMT</pubDate>
    <dc:creator>TyroneBiggums</dc:creator>
    <dc:date>2015-11-20T20:53:37Z</dc:date>
    <item>
      <title>Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721627#M66984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have used the draw toolbar to create a collection of graphics on added those graphics to a graphicsLayer. Is there a way to change the order, or index, of the graphics within the layer once the graphics have been added?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, can I draw a rectangle, circle and triangle (in that order) and change map.getLayer('myLayer').graphics to reorder these graphics?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there an Esri way, or will I need to redraw all of the shapes in the order that I would like them?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 20:23:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721627#M66984</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2015-11-20T20:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721628#M66985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tyrone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At least back in 2011, there wasn't a clean way to do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/thread/24535"&gt;Change GraphicsLayer Z Index&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Esri way then was to remove and re-add.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 20:42:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721628#M66985</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-11-20T20:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721629#M66986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The setzindex of a graphic in a layer is what I'd be interested in but it looks like it's been removed in the latest version of the API (at least I don't see it anywhere in the API reference guide).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did see another old post that used getDojoShape().moveToFront(). I suppose I could iterate through all the graphics and move them to front/back in the right order to reorder them. But, moveToFront only makes it look like that shape is the top graphic. The order of the graphics are still the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's looking like remove all and add in the order that I want them in. I just don't want to see graphics flashing. Maybe it's going to be fast enough that the user doesn't see them redrawn?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 20:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721629#M66986</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2015-11-20T20:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721630#M66987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interestingly, it's in the Silverlight API:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~SetZIndex.html" title="http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~SetZIndex.html"&gt;http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~SetZIndex.html&lt;/A&gt; &lt;/P&gt;&lt;P&gt;It's clear in the documentation it's really adjusting the z-index.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 21:00:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721630#M66987</guid>
      <dc:creator>ChrisSmith7</dc:creator>
      <dc:date>2015-11-20T21:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721631#M66988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yea, we're going from SL to rewriting in JS. We had that ability in SL. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 21:05:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721631#M66988</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2015-11-20T21:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721632#M66989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can move items to any index in the 4.0 version of the API using the Collection API - &lt;A href="https://developers.arcgis.com/javascript/beta/api-reference/esri-core-Collection.html#moveItem" title="https://developers.arcgis.com/javascript/beta/api-reference/esri-core-Collection.html#moveItem"&gt;Collection | API Reference | ArcGIS API for JavaScript&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since &lt;A href="https://developers.arcgis.com/javascript/beta/api-reference/esri-layers-GraphicsLayer.html#graphics"&gt;GraphicsLayer.graphics &lt;/A&gt;​is a Collection, you can use the &lt;A href="https://developers.arcgis.com/javascript/beta/api-reference/esri-core-Collection.html#moveItem"&gt;moveItem() &lt;/A&gt;method to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Gets the item in the 0 index&lt;/P&gt;&lt;P&gt;var graphic = layer.graphics.getItemAt(0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//moves it to the 5 index&lt;/P&gt;&lt;P&gt;layer.graphics.moveItem(graphic, 5);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jan 2016 01:21:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721632#M66989</guid>
      <dc:creator>KristianEkenes</dc:creator>
      <dc:date>2016-01-16T01:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721633#M66990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would it also be best to wait on 4.0 for re-ordering the layers themselves? If I add LayerA and LayerB (in that order), LayerB will display on top of LayerA. If I want LayerA shown on top, in 3.x, is that also a remove then re-add as mentioned above for graphics?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 15:23:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721633#M66990</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2016-01-19T15:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721634#M66991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Layers are treated the same way as graphics in 4.0 since they are also part of a collection in the map. &lt;A href="https://developers.arcgis.com/javascript/beta/api-reference/esri-Map.html#layers" title="https://developers.arcgis.com/javascript/beta/api-reference/esri-Map.html#layers"&gt;Map | API Reference | ArcGIS API for JavaScript&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you can use the same moveItem() method to reorder:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//moves LayerA into index 1 (on top of LayerB)&lt;/P&gt;&lt;P&gt;map.layers.moveItem(LayerA, 1);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:09:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721634#M66991</guid>
      <dc:creator>KristianEkenes</dc:creator>
      <dc:date>2016-01-19T17:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721635#M66992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What about 3.x?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 17:19:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721635#M66992</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2016-01-19T17:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721636#M66993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a method in Map class to change the layer order. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/jsapi/map-amd.html#reorderlayer" title="https://developers.arcgis.com/javascript/jsapi/map-amd.html#reorderlayer"&gt;Map | API Reference | ArcGIS API for JavaScript&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 19:37:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721636#M66993</guid>
      <dc:creator>GirishYadav</dc:creator>
      <dc:date>2016-01-19T19:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721637#M66994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a magic trick for graphics? Or is remove/add graphics the way to go still. Thanks for the pointer to reorderLayer. That worked great.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 20:28:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721637#M66994</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2016-01-19T20:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721638#M66995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no in-built method to reorder the graphics, But, as Layer.Graphics is an array, we can manipulate it with javascript array methods. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sure, you can also use remove/add graphics, but the way I prefer is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Array.prototype.reorder = function (fromIndex, toIndex){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.splice(toIndex, 0, this.splice(fromIndex, 1)[0]);
}
//an example
var a = [1,2,3,4,5];
a.reorder(3, 0);
console.log(a)
//a is now [4,1,2,3,5]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is added as an extension method, therefore it can be used with any array in your app. However, if you just want to use it in one place then simply use one line that is inside the function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:52:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721638#M66995</guid>
      <dc:creator>GirishYadav</dc:creator>
      <dc:date>2021-12-12T06:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721639#M66996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't had a chance to test this out, yet. Do the graphics re-order on the map with this method, or are there further steps? In other words, if the graphics are all on top of each other with 100 opacity, does this bring a graphic to the top? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jan 2016 17:53:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721639#M66996</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2016-01-20T17:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721640#M66997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the .moveItem() method does not appear to exist at 4.5. I tried using .reorder(graphic, 0). Using .indexOf(graphic) I see that indeed the graphic was moved to the 0 position in the graphics collection, but the graphicsLayer does not redraw. Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Nov 2017 17:25:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721640#M66997</guid>
      <dc:creator>BrandonFlessner</dc:creator>
      <dc:date>2017-11-08T17:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Change index of a graphic in a GraphicsLayer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721641#M66998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brandon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; It sounds like a bug where the layer does not re-draw based on the reorder. You can force the view to refresh by setting the view.extent = view.extent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Nov 2017 17:36:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-index-of-a-graphic-in-a-graphicslayer/m-p/721641#M66998</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2017-11-08T17:36:00Z</dc:date>
    </item>
  </channel>
</rss>

