<?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 layer order in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-layer-order/m-p/1111697#M75095</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/427535"&gt;@GaryB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had the same problem today.&lt;/P&gt;&lt;P&gt;My solution was to assign each layer an id which is equal to his initial position in the layer.&lt;BR /&gt;Surely you could also use another layer attribute.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//sample layers
const graphicsLayer1 = new GraphicsLayer({
  title: "samplelayer1",
  id: 1
});
map.add(graphicsLayer1);
const graphicsLayer2 = new GraphicsLayer({
  title: "samplelayer2",
  id: 2
});
map.add(graphicsLayer2);

//triggeraction-part
else if (id === "move-layer-up"){
              position = event.item.layer.id;
              if (1 !== +position){
                new_position = +position - +1;
                event.item.layer.id = new_position;
                console.log("new position: "+event.item.layer.id)
                layerList.viewModel.moveListItem(event.item, null, null, new_position);
              }
            }
            else if (event.action.id === "move-layer-down") {
              maxPosition = layerList.viewModel.operationalItems.length
              console.log("maxPosition:"+maxPosition);
              position = event.item.layer.id;
              if (maxPosition !== +position){
                new_position = +position + +1;
                event.item.layer.id = new_position;
                console.log("new position: "+event.item.layer.id)
                layerList.viewModel.moveListItem(event.item, null, null, new_position);
              }
            }&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 27 Oct 2021 16:05:40 GMT</pubDate>
    <dc:creator>MichaelBoschert</dc:creator>
    <dc:date>2021-10-27T16:05:40Z</dc:date>
    <item>
      <title>Change layer order</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-layer-order/m-p/1051757#M72762</link>
      <description>&lt;P&gt;I'm trying to implement functionality so the user can change the order of layers.&amp;nbsp; My "move-layer-up" functionality works but I cannot get the "move-layer-down" functionality working and the layer always seems to end up in some random spot.&amp;nbsp; Any pointers would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layerList.on("trigger-action", function (event) {

    if (event.action.id === "move-layer-up") {

        var layerToMoveName = event.item.title;
        var layerToMoveIdx = -1

        for (var i = 0; i &amp;lt; layerList.viewModel.operationalItems.length; i++) {
            var item = layerList.viewModel.operationalItems.getItemAt(i)
            if (item.title === layerToMoveName) {
                layerToMoveIdx = i
            }
        }

        if (layerToMoveIdx &amp;gt; 0) {
            layerList.viewModel.moveListItem(event.item, null, null, layerToMoveIdx);
        }
    }
    else if (event.action.id === "move-layer-down") {

        var layerToMoveName = event.item.title;
        var layerToMoveIdx = -1

        for (var i = 0; i &amp;lt; layerList.viewModel.operationalItems.length; i++) {
            var item = layerList.viewModel.operationalItems.getItemAt(i)
            if (item.title === layerToMoveName) {
                layerToMoveIdx = i
            }
        }

        if (layerToMoveIdx &amp;lt; layerList.viewModel.operationalItems.length) {
            layerList.viewModel.moveListItem(event.item, null, null, layerToMoveIdx + 1);
        }

    }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 14:54:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-layer-order/m-p/1051757#M72762</guid>
      <dc:creator>GaryB</dc:creator>
      <dc:date>2021-04-27T14:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Change layer order</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-layer-order/m-p/1111697#M75095</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/427535"&gt;@GaryB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had the same problem today.&lt;/P&gt;&lt;P&gt;My solution was to assign each layer an id which is equal to his initial position in the layer.&lt;BR /&gt;Surely you could also use another layer attribute.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//sample layers
const graphicsLayer1 = new GraphicsLayer({
  title: "samplelayer1",
  id: 1
});
map.add(graphicsLayer1);
const graphicsLayer2 = new GraphicsLayer({
  title: "samplelayer2",
  id: 2
});
map.add(graphicsLayer2);

//triggeraction-part
else if (id === "move-layer-up"){
              position = event.item.layer.id;
              if (1 !== +position){
                new_position = +position - +1;
                event.item.layer.id = new_position;
                console.log("new position: "+event.item.layer.id)
                layerList.viewModel.moveListItem(event.item, null, null, new_position);
              }
            }
            else if (event.action.id === "move-layer-down") {
              maxPosition = layerList.viewModel.operationalItems.length
              console.log("maxPosition:"+maxPosition);
              position = event.item.layer.id;
              if (maxPosition !== +position){
                new_position = +position + +1;
                event.item.layer.id = new_position;
                console.log("new position: "+event.item.layer.id)
                layerList.viewModel.moveListItem(event.item, null, null, new_position);
              }
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Oct 2021 16:05:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/change-layer-order/m-p/1111697#M75095</guid>
      <dc:creator>MichaelBoschert</dc:creator>
      <dc:date>2021-10-27T16:05:40Z</dc:date>
    </item>
  </channel>
</rss>

