I'd like to re-order webmap layers with Python. I'm using the arcgis package (the ArcGIS API for Python) to add a layer, but the newest layer just goes to the top of the layer list (table of content), which may not be where I want it. How do I re-order it after I add it?
I'd also be interested to know if the WebMap.add_layer() function can just put the layer in the right order in the first place.
thanks!
@PaulHallett1305 you have "GISIS RAG Status" twice in your dictionary and set as [5] and [6], layer names will need to be unique for this to work, otherwise one entry gets removed from the dictionary because of the duplicate key.
I've edited it to be how it should be.
Hey, I was running into a similar issue when I noticed you are using item.update() rather than webmap.update(). Took me a while to notice that to reorder operational layers you need to update the item data not necessarily the webmap object. Do you know why this is? It's not very intuitive (to me at least) that you need to update the item and not the webmap. Both have similar update functions but they seem to be capable of different things. Anyway, thank you for posting this code. Cheers!
I think it's as you're updating an item within the webmap; it's not the web map per se.
@Clubdebambos' example--getting the item data, updating it, then updating item w/item_properties--worked for me. Wrestled with trying to update the web map object for a while; had no luck there. Switched to item and it works. Much appreciated!
It would be great if esri could way in here.
Well I finally got it working, and it wasn't Clubdebambos code that wasn't working, but my brain and I had named a layer slightly incorrectly (it had a trailing s), so your work is magic, super quick and does what it needs to do, right on the money.
Thanks so much for your help, you went over and beyond what I would have expected.
Great stuff
Thank you for this post and discussion. It helped me create this Jupyter Notebook that prompts the user for a layer to replace, and a layer to replace it with, then it loops through all of the web maps the user has access to and replaces the layers. Check it out, I hope it helps...