Select to view content in your preferred language

reorder webmap layers with Python?

4413
18
04-07-2020 05:17 PM
davedoesgis
Frequent Contributor

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!

18 Replies
Clubdebambos
Frequent Contributor

@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.

~ learn.finaldraftmapping.com
0 Kudos
PaulHallett1305
Emerging Contributor
Sorry that’s a typo.





##- Please type your reply above this line
0 Kudos
PaulHallett1305
Emerging Contributor

I've edited it to be how it should be.

 

0 Kudos
AustinDoezema
Occasional Contributor

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!

0 Kudos
PaulHallett1305
Emerging Contributor

I think it's as you're updating an item within the webmap; it's not the web map per se.

0 Kudos
AlderMaps
Frequent Contributor

@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!

LanceKirby2
Frequent Contributor

It would be great if esri could way in here.

0 Kudos
PaulHallett1305
Emerging Contributor

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

0 Kudos
JoeGuziStarkCountyOH
Frequent Contributor

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...

ArcGIS Online Replace Layer in a Web Map