mapView.map.allLayers.reorder not working

155
2
05-19-2021 04:13 AM
AJasper
New Contributor

ArcGIS JavaScript API v4.19

I have some code to recorder layers. Code below is the function that does the reorder. Unfortunately, this is not working in 4.19, any ideas what I am doing wrong. The order of the layers changes but does not render on the map.

  moveLayer(oldIndexnumbernewIndexnumber😞 void {
    const mapView = this.mapFactory.getMapView();
    if (!mapView) {
      return;
    }

    const numberOfLayers = mapView.map.allLayers.length;
    if (oldIndex < numberOfLayers && newIndex < numberOfLayers) {
      const layer = mapView.map.allLayers.getItemAt(oldIndex);
      mapView.map.allLayers.reorder(layernewIndex);

      this.updateMapLayers();
    }
  }
0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Map.allLayers returns collection of ALL layers including basemap and ground layers.  Do you mean to re-order absolutely all layers in your map? If you are re-ordering layers using this collection, your operational layers maybe being moved underneath the basemap layers. Map.layers  will give you collection of operational layers (the layers drawn on top of basemap and ground layers). 

-Undral

 

0 Kudos
AJasper
New Contributor

Yes, that is what I wanted to do, put the basemap above other layers.

0 Kudos