<?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: Dragging LayerList Items to Re-order Layers in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/1099730#M74705</link>
    <description>&lt;P&gt;I decided it would be better to separate the code from the esri code. To install rename the&amp;nbsp;LayerListView.js to&amp;nbsp;LayerListView_esri.js and copy over the files.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This version also adds a drag handle styled as per the map viewer&lt;/P&gt;</description>
    <pubDate>Mon, 20 Sep 2021 01:53:07 GMT</pubDate>
    <dc:creator>DavidWilton</dc:creator>
    <dc:date>2021-09-20T01:53:07Z</dc:date>
    <item>
      <title>Dragging LayerList Items to Re-order Layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/521706#M48636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working on making LayerList items to be draggable so that users would be able to reorder the layers by dragging them. I've found &lt;A _jive_internal="true" href="https://community.esri.com/thread/204403-moveble-layerlist"&gt;Shopify Draggable&lt;/A&gt;&amp;nbsp;might be the closest approach. However, the application(&lt;A href="https://codepen.io/solowt/pen/yPeeeL?editors=1000"&gt;open CodePen&lt;/A&gt;) loses some of its functionalities after the LayerList is dragged. It's a shame that v4.x doesn't support dragging natively like v3.x did. Is there any other way to perfectly reorder LayerList layers with dragging?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2019 06:55:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/521706#M48636</guid>
      <dc:creator>JerryChen</dc:creator>
      <dc:date>2019-09-10T06:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dragging LayerList Items to Re-order Layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/521707#M48637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I used the dojo Drag and Drop package in the LayerListView.js file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This&amp;nbsp;code is&amp;nbsp;probably 2 year old&amp;nbsp; Below are some &amp;nbsp;code snippets. Hope it helps. This is done for js 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;
_setUpDnD: function () {
&amp;nbsp;this.dndList = new Source(this.layerListTable, {
&amp;nbsp;&amp;nbsp;skipForm: true,
&amp;nbsp;&amp;nbsp;withHandles: true,
&amp;nbsp;&amp;nbsp;singular:true,
&amp;nbsp;&amp;nbsp;creator: dojo.hitch(this, this.createItem)
&amp;nbsp;});
&amp;nbsp;dojo.connect(this.dndList, "onDropInternal", this, "onDrop");
&amp;nbsp;this.dndContainer = new Container(this.layerListTable);
},

&amp;nbsp;onDrop: function (nodes) {
&amp;nbsp;var layertrArr = dojo.query('.jimu-widget-wslayerList .dojoDndHandle')
&amp;nbsp;//VT: we need to loop through everything to ensure the structure integrity in the &amp;lt;table&amp;gt;.
&amp;nbsp;array.forEach(layertrArr,lang.hitch(this,function(layertr){
&amp;nbsp;&amp;nbsp;let layertrNodeId=dojo.attr(layertr,'layertrnodeid');
&amp;nbsp;&amp;nbsp;let nextSiblingNodeId = layertr.nextSibling?dojo.attr(layertr.nextSibling,'layercontenttrnodeid'):'';
&amp;nbsp;&amp;nbsp;if(!nextSiblingNodeId || nextSiblingNodeId!==layertrNodeId){
&amp;nbsp;&amp;nbsp;&amp;nbsp;let node = dojo.query('[layercontenttrnodeid="'+ layertrNodeId +'"]')
&amp;nbsp;&amp;nbsp;&amp;nbsp;this.layerListTable.insertBefore(node[0], layertr.nextSibling);
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}))
&amp;nbsp;this.emit('dnd-drop', nodes);
&amp;nbsp;var previousNode=null;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;var allNodes = this.dndList.getAllNodes();
&amp;nbsp;for(var i = 0; i &amp;lt; allNodes.length; i ++){
&amp;nbsp;&amp;nbsp;if(allNodes&lt;I&gt;.id===nodes[0].id){
&amp;nbsp;&amp;nbsp;&amp;nbsp;break
&amp;nbsp;&amp;nbsp;}else{
&amp;nbsp;&amp;nbsp;&amp;nbsp;previousNode = allNodes&lt;I&gt;;
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;}&lt;/I&gt;&lt;/I&gt;
&amp;nbsp;var layerInfo = this.dndList.getItem(nodes[0].id).data;
&amp;nbsp;var steps = this._getMovedStepsAfterDnD(layerInfo , previousNode?this.dndList.getItem(previousNode.id).data:null);
&amp;nbsp;if(steps.movedown){
&amp;nbsp;&amp;nbsp;this.moveDownLayer(layerInfo,steps.steps)
&amp;nbsp;}else{
&amp;nbsp;&amp;nbsp;this.moveUpLayer(layerInfo,steps.steps)
&amp;nbsp;}
&amp;nbsp;console.log(steps);
},


&lt;/BLOCKQUOTE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/521707#M48637</guid>
      <dc:creator>VictorTey</dc:creator>
      <dc:date>2021-12-12T16:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dragging LayerList Items to Re-order Layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/1099262#M74690</link>
      <description>&lt;P&gt;I had to do this and Victors sample is definitely missing functions (e.g. createItem) and things with the laterlist look like they have changed since.&lt;BR /&gt;&lt;BR /&gt;I have wrapped up the code into blocks that can just be pasted into layerListview.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The css will give you the map viewer style dotted line.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Notes &lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Because wab doesn't nest the expanded items (the layer swatch) it only supports dragging above an item.&lt;/LI&gt;&lt;LI&gt;Feature layers can't be moved, this is a limitation of 3x.&lt;/LI&gt;&lt;LI&gt;there well may be edge layer types I haven't tested.&lt;/LI&gt;&lt;LI&gt;tested and working with 2.20&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rjk3zSC07D.gif" style="width: 422px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23249i486FB365D634E597/image-size/large?v=v2&amp;amp;px=999" role="button" title="rjk3zSC07D.gif" alt="rjk3zSC07D.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;LayerListView.js&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;   _setUpDnD: function () {
      this.dndList = new Source(this.layerListTable.parentNode, {
        skipForm: true,
        singular: true
      });
      dojo.connect(this.dndList, "onDropInternal", this, "onDrop");
      this.dndContainer = new Container(this.layerListTable);

      // listen for drag and check we can drop
      this.onMouseMoveHandler = this.own(dojo.connect(this.dndList, "onMouseMove", lang.hitch(this, "handleDragMoveDnd")));
      this.onMouseMoveHandler = this.own(dojo.connect(this.dndList, "onDndStart", lang.hitch(this, "handleDragStart")));


      aspect.around(this, "addLayerNode", function (orig) {
        return function(){
          var args = orig.apply(this, arguments);
          // ignore any layer which isn't a parent
          if(arguments[0].parentLayerInfo){
              return args;
          }
          // we need to add a node and a class as the dnd requires it
          var id = args.layerTrNode.getAttribute("layerTrNodeId");
          var layerInfo = this.operLayerInfos.getLayerInfoById(id);
          // you can't move feature layers! 
          var lyr = layerInfo.originOperLayer.layerObject;
          if (lyr.type &amp;amp;&amp;amp; lyr.type.toLowerCase() === "feature layer") {
            return args;
          }
          args.layerTrNode.setAttribute("id", args.layerTrNode.getAttribute("layerTrNodeId"));
          // we also need the d&amp;amp;d class
          domClass.add(args.layerTrNode, "dojoDndItem");
          this.dndList.setItem(args.layerTrNode.id, args.layerTrNode)
          return args;
        }
      }, true)
    },

    handleDragMoveDnd: function (a) {

      Manager.manager().canDropFlag = true;

      if (this.dndList.isDragging) {
        // var layer2ContentTrNode = query("tr[layerContentTrNodeId='" + this.dndList.current.id + "']", this.layerListTable)[0];


        query(".dndDashedLine", this.layerListTable).forEach(function (n) {
          domClass.remove(n, "dndDashedLine");
        })
        if (this.dndList.current) {
          if (this.dndList.currentDragInfo &amp;amp;&amp;amp; this.dndList.currentDragInfo != this.dndList.current.id) {
            // if its the next node don't let it drop it before/after depending on direction
            // turn the map into an array
            var layerInfoArray = this.operLayerInfos.getLayerInfoArray();
            var ids = []
            array.forEach(layerInfoArray, function (currentLayerInfo, index) {
              if (this.dndList.map[currentLayerInfo.id]) {
                ids.push(currentLayerInfo.id);
              }
            }, this);

            var currentIdx = ids.indexOf(this.dndList.currentDragInfo);
            var nextIdx = ids.indexOf(this.dndList.current.id);
            if (domClass.contains(this.dndList.current, "dojoDndItemAfter")) {
                // do not let users drop before. This is the issue with the jimu list which doesn't
                // have the content (eg the layer swatch) is not a child of the layer item. we let this 
                // go if its the very bottom item
                domClass.add(this.dndList.current, "dndDashedLine");
                if(!nextIdx == ids.length - 1){
                  Manager.manager().canDropFlag = false;
                  domClass.remove(this.dndList.current, "dndDashedLine");
                }
            }
            if (domClass.contains(this.dndList.current, "dojoDndItemBefore")) {

              domClass.add(this.dndList.current, "dndDashedLine");
              if (nextIdx - currentIdx === 1) {
                Manager.manager().canDropFlag = false;
                domClass.remove(this.dndList.current, "dndDashedLine");
              }

            }


          } else if (this.dndList.currentDragInfo === this.dndList.current.id) {
            Manager.manager().canDropFlag = false;  // don't let it drop on top of itself
          }else{
            Manager.manager().canDropFlag = false;
          }
        }
        else {
          // this will happen when user mouses over a feature layer
          Manager.manager().canDropFlag = false;
        }
        dojo.toggleClass(Manager.manager().avatar.node, "dojoDndAvatarCanDrop", Manager.manager().canDropFlag);
      }

    },

    handleDragStart: function (a, c, e) {
      if (this.dndList.current) {
        this.dndList.currentDragInfo = this.dndList.current.id;;
      }else{
        this.dndList.currentDragInfo = null;
      }

    },

    onDrop: function (nodes) {

      this.dndList.getAllNodes().forEach(function (n) {
        domClass.remove(n, "dndDashedLine");
      })

      // new position
      var allNodes = this.dndList.getAllNodes();
      var newPos = -1;
      for (var i = 0; i &amp;lt; allNodes.length; i++) {
        if (allNodes[i].id === nodes[0].id) {
          newPos = i;
          break;
        }
      }


      // old position
      var layerInfo = this.operLayerInfos.getLayerInfoById(nodes[0].id);
      var oldPos = -1;
      var layerInfoArray = this.operLayerInfos.getLayerInfoArray();
      array.forEach(layerInfoArray, function (currentLayerInfo, index) {
        if (layerInfo.id === currentLayerInfo.id) {
          oldPos = index;
        }
      }, this);

      // if we have less d&amp;amp;d nodes its because there are feature layers
      if (layerInfoArray.length !== allNodes.length) {
        newPos += (layerInfoArray.length - allNodes.length);
      }

      var steps = -1;
      if (oldPos &amp;lt; newPos) {
        steps = newPos - oldPos;
        steps = this.operLayerInfos.moveDownLayer(layerInfo, steps)
      } else {
        steps = oldPos - newPos;
        steps = this.operLayerInfos.moveUpLayer(layerInfo, steps)
      }

      this.emit('dnd-drop', nodes);

      // just for good look 
      this.refresh();
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;style.css&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;.jimu-widget-layerList .dojoDndItemBefore.dndDashedLine{
  border-width: 0 !important;
  border-top: #009cff !important;
  border-style: dashed  !important;
  border-top-width: 2px  !important;
}
.jimu-widget-layerList .dojoDndItemAfter.dndDashedLine{
  border-width: 0 !important;
  border-bottom: #009cff !important;
  border-style: dashed  !important;
  border-bottom-width: 2px  !important;
}
.jimu-widget-layerList .dojoDndItem{
  border-width: 0 !important;
}
.jimu-widget-layerList .layer-list-table  {
  border-collapse: collapse !important;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 05:42:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/1099262#M74690</guid>
      <dc:creator>DavidWilton</dc:creator>
      <dc:date>2021-09-17T05:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dragging LayerList Items to Re-order Layers</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/1099730#M74705</link>
      <description>&lt;P&gt;I decided it would be better to separate the code from the esri code. To install rename the&amp;nbsp;LayerListView.js to&amp;nbsp;LayerListView_esri.js and copy over the files.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This version also adds a drag handle styled as per the map viewer&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 01:53:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dragging-layerlist-items-to-re-order-layers/m-p/1099730#M74705</guid>
      <dc:creator>DavidWilton</dc:creator>
      <dc:date>2021-09-20T01:53:07Z</dc:date>
    </item>
  </channel>
</rss>

