Hello all,
I am trying to work on a notebook that will pull in a specified feature layer and add it to an existing web map. So far the script I have will add all the data as expected, however it is never in the same order as it is in the hosted layer, and the group that layers are out into is not named the same things as the hosted layer (always being named Custom Group Layer). The layers should be in the opposite order to my screenshot below (waypoints first, then worksites, etc with Incident Area at the bottom of the list). I have tried a few different methods of adding layers and all of them produce the same exact result. Does anyone have any guidance on this?
from arcgis.gis import GIS
gis = GIS("home")
layer_item_id = "<Layer ID>"
webmap_item_id = "<Map ID>"
layer_item = gis.content.get(layer_item_id)
webmap_item = gis.content.get(webmap_item_id)
layer_collection = layer_item.layers
wm = gis.map(webmap_item)
wm.content.add(layer_collection)
wm.update()
Have you tried looping through the layer collection and adding them in reverse index order? Assuming Waypoints is layer id 0, it's adding them in ascending order of layer id, with each new one added on top. So reverse it and it should be correct.