Add multiple layers to a Map Python Api

415
2
Jump to solution
08-06-2020 11:33 AM
PaulSweeney3
Occasional Contributor II
item1 = gis.content.search(query = "title:HSF",item_type='Feature Layer', max_items=1000,)
display(item1)

item2 = gis.content.search(query = "title:xxxxxxxxx",item_type='Web Map', max_items=1000,)
display(item2)
wm_item = item2[0]
from arcgis.mapping import WebMap
web_map_obj = WebMap(wm_item)
for item in item1:
 web_map_obj.add_layer(item)

See above code can anyone tell me what i need to specify to get every item in the list item 1 added to the Map. it iterates through the list but only adds the first feature over and over. 

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

Hi Paul Sweeney

The code needs some tweaks to get it working.

First you can limit the number of max_items down to 4 or 5 to speed up the process. Once it gets to work you can increase the number.

Second I recommend using gis.map() instead of WebMap().

The code will be something like below:

item1 = gis.content.search(query = "title:HSF",item_type='Feature Layer', max_items=5)
for item in item1:
    display(item)
======================================
item2 = gis.content.search(query = "title:xxxxxxxxx",item_type='Web Map', max_items=1000)
wm_item = item2[0]
web_map_obj = gis.map(wm_item)
web_map_obj
======================================
for item in item1:
   web_map_obj.add_layer(item)‍‍‍‍‍‍‍‍‍‍

Run each block (delineated by =======) on a separate cell in notebook to have a better check.

View solution in original post

2 Replies
MehdiPira1
Esri Contributor

Hi Paul Sweeney

The code needs some tweaks to get it working.

First you can limit the number of max_items down to 4 or 5 to speed up the process. Once it gets to work you can increase the number.

Second I recommend using gis.map() instead of WebMap().

The code will be something like below:

item1 = gis.content.search(query = "title:HSF",item_type='Feature Layer', max_items=5)
for item in item1:
    display(item)
======================================
item2 = gis.content.search(query = "title:xxxxxxxxx",item_type='Web Map', max_items=1000)
wm_item = item2[0]
web_map_obj = gis.map(wm_item)
web_map_obj
======================================
for item in item1:
   web_map_obj.add_layer(item)‍‍‍‍‍‍‍‍‍‍

Run each block (delineated by =======) on a separate cell in notebook to have a better check.

PaulSweeney3
Occasional Contributor II

Thanks Mehdi thats worked now, just so i know why has this not worked for me was it simply down to the fact i used WebMap() .  

0 Kudos