Extracting id from MapView Object and then Making this Map available for everyone to view in Python.

447
4
Jump to solution
04-05-2021 08:36 AM
Labels (3)
findyourinvasive
New Contributor II

Here is the code I have so far. I am using the ArcGIS Python API.

g = GIS("https://www.arcgis.com", "USERNAME", "PASSWORD")

p = {
'type':"CSV",
'title': '2020#12',
'snippet':'hwa',
'description':'test ' + \
'dataframe object to a GIS item',
'tags': 'python',

}

i=g.content.add (item_properties=p,
data="C:/Users/NAME/PycharmProjects/colors/Map/5TXHV8NTC5.csv"
)
q=i.publish ()
print (q)
search = g.content.search(query="owner:USERNAME",
item_type="Feature Layer")
print (search)
from arcgis.mapping import WebMap
#map = WebMap()
map=g.map (location="United States")
item=search [0]
print (item)
map.add_layer(item)
props={'title': '2020#156',
'snippet':'hwa',
'tags': 'python',
"renderer":"autocast",
"field_name": "Threat",
}
map.save (props)

1. I realize that I can get the id for the MapView object from the url. However, is there a way I can get this id from Python?

2. When I try an embed my map in my website, credentials are requested. I would like everyone to be able to view my map. Is there a way I can configure sharing privileges for my map from Python?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Notable Contributor

The MapView object may reference the web map, but is not the web map itself, so it won't have direct access to the id. Instead, you'll need to return the Item. You can pass the title you defined back into another query and get the ID that way.

map_id = g.content.search('new-title', item_type='Web Map')[0].id

Sharing is likewise defined at the Item level. 

g.content.search('new-title', item_type='Web Map')[0].share(everyone=True)
- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
4 Replies
jcarlson
MVP Notable Contributor

The MapView object may reference the web map, but is not the web map itself, so it won't have direct access to the id. Instead, you'll need to return the Item. You can pass the title you defined back into another query and get the ID that way.

map_id = g.content.search('new-title', item_type='Web Map')[0].id

Sharing is likewise defined at the Item level. 

g.content.search('new-title', item_type='Web Map')[0].share(everyone=True)
- Josh Carlson
Kendall County GIS
0 Kudos
findyourinvasive
New Contributor II

I tried this:

map_id = g.content.search('2020#156', item_type='Web Map')[0].id
g.content.search('2020#156', item_type='Web Map')[0].share(everyone=True)

IndexError: list index out of range

The search comes up empty. However, it is in my contents (see image) 

0 Kudos
findyourinvasive
New Contributor II

I converted the map to a web map and it worked perfectly. Thank you.

from arcgis.mapping import WebMap
map = WebMap()

I also did 

time.sleep(5)

It takes some time to update.  

jcarlson
MVP Notable Contributor

Great! I have noticed that searching for content can treat the '#' character differently, so perhaps that was involved. But as long as it's working!

- Josh Carlson
Kendall County GIS
0 Kudos