<?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 How to change the order of layers ? in Java Maps SDK Questions</title>
    <link>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544993#M1707</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to change the order of my Layers programmatically (using ArcGIS Runtime Java 10.1.1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in API Reference there LayerList.set(int index, Layer element) to set the given layer at the given index, but when I'm trying to do same, I'm getting the folowing error :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;java.lang.&lt;/SPAN&gt;&lt;STRONG&gt;IllegalArgumentException: Layer is already in another map&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.map.LayerList.a(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.map.LayerList.set(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.client.samples.mapping.graphics.AddGraphics.changedOrderOfLayer(AddGraphics.java:110)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried with 3 cases:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalTiledLayer and 1 GraphicsLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 2 ArcGISLocalTiledLayer (another point here : LayerList.add() return "true" for 2nd Layer, but I can only see one TPK on my map...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalTiledLayer and 1 ArcGISLocalDynamicMapServiceLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my simple code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;private void changedOrderOfLayer() {
 System.out.println("Before - layer's name at index 1 is : " + map.getLayers().get(1).getName());
 
 // Move Layer to index 0
 map.getLayers().set(0, map.getLayers().get(1)); // IllegalArgumentException HERE !!!
 
 System.out.println("after - layer's name at index 1 : " + map.getLayers().get(0).getName());
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is the best way to change order of Layers in JMap ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are there some limitations depending of layers format (TPK, MPK, GraphicsLayer, etc.) ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:36:28 GMT</pubDate>
    <dc:creator>JeremieJoalland1</dc:creator>
    <dc:date>2021-12-12T16:36:28Z</dc:date>
    <item>
      <title>How to change the order of layers ?</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544993#M1707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to change the order of my Layers programmatically (using ArcGIS Runtime Java 10.1.1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in API Reference there LayerList.set(int index, Layer element) to set the given layer at the given index, but when I'm trying to do same, I'm getting the folowing error :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;java.lang.&lt;/SPAN&gt;&lt;STRONG&gt;IllegalArgumentException: Layer is already in another map&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.map.LayerList.a(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.map.LayerList.set(Unknown Source)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; at com.esri.client.samples.mapping.graphics.AddGraphics.changedOrderOfLayer(AddGraphics.java:110)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried with 3 cases:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalTiledLayer and 1 GraphicsLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 2 ArcGISLocalTiledLayer (another point here : LayerList.add() return "true" for 2nd Layer, but I can only see one TPK on my map...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalTiledLayer and 1 ArcGISLocalDynamicMapServiceLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my simple code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;private void changedOrderOfLayer() {
 System.out.println("Before - layer's name at index 1 is : " + map.getLayers().get(1).getName());
 
 // Move Layer to index 0
 map.getLayers().set(0, map.getLayers().get(1)); // IllegalArgumentException HERE !!!
 
 System.out.println("after - layer's name at index 1 : " + map.getLayers().get(0).getName());
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is the best way to change order of Layers in JMap ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are there some limitations depending of layers format (TPK, MPK, GraphicsLayer, etc.) ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:36:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544993#M1707</guid>
      <dc:creator>JeremieJoalland1</dc:creator>
      <dc:date>2021-12-12T16:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the order of layers ?</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544994#M1708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We've just been working on an API improvement for the next release which will do exactly what you want.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It will work something like map.getLayers().reorderLayer(oldIndex, newIndex)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the moment ay 10.1.1 your best option is to remove the layer you want to reorder from the map control and then add it again at the place you want it; although it's not going to be as efficient as the new method above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mark&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 16:13:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544994#M1708</guid>
      <dc:creator>MarkBaird</dc:creator>
      <dc:date>2013-04-03T16:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the order of layers ?</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544995#M1709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks for the explanation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've implemented the alternative solution, by removing and adding a layer at expected order index seems to work fine, with acceptable performances !&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here is my sample code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public void setOrderOfLayer(Layer layer, int order) {
 // Process the reordering of layer by removing it, then adding it at the expecting order index
 jMap.getLayers().remove(layer);
 jMap.getLayers().add(order,&amp;nbsp; layer);
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this was succefull with following jMap content :&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalTiledLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISLocalDynamicMapServiceLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 GraphicsLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - 1 ArcGISDynamicMapServiceLayer (with Local Server, blanck MPK, to load a Shapefile)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:34:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544995#M1709</guid>
      <dc:creator>JeremieJoalland1</dc:creator>
      <dc:date>2021-12-11T23:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the order of layers ?</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544996#M1710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The blog &lt;/SPAN&gt;&lt;A href="http://blogs.esri.com/esri/arcgis/2012/11/01/coming-up-in-arcgis-runtime-sdks-10-1-1-a-lot/" rel="nofollow noopener noreferrer" target="_blank"&gt;Coming up in the Next Release of the ArcGIS Runtime SDK for Java? A lot&lt;/A&gt;&lt;SPAN&gt; makes mention of a way of doing this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;STRONG&gt;Re-ordering graphics layers in a map&lt;/STRONG&gt;&lt;BR /&gt;It was too bad that this wasn�??t functional and clearer in the first release, but the team nailed it down. You can add *n* number of graphics layers to your map and reorder them on the fly. By the way, you can also use �??send to back�?� and �??bring to front�?� on graphic elements in the same layer. It can work in code as simple as this (Java) (No offense to my WPF friends!):&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;GraphicsLayer gLayer1 = (GraphicsLayer)map.getLayers().get(1);
map.getLayers().remove(2);
map.getLayers().add(3,gLayer1);&lt;/PRE&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sure it works with any type of map layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:34:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/how-to-change-the-order-of-layers/m-p/544996#M1710</guid>
      <dc:creator>CarlosColón-Maldonado</dc:creator>
      <dc:date>2021-12-11T23:34:51Z</dc:date>
    </item>
  </channel>
</rss>

