Web map created with python API and feature services not displaying features

5874
13
Jump to solution
04-18-2017 09:25 AM
CharlieWare
New Contributor II

I am using the Python API to publish a web map using a hosted feature service that I published from a file geodatabase in My Content. I am following the example in the Python API sample Jupyter Notebook 'Publishing Web Maps and Web Scenes' in the '05 Content Publishers' group of notebooks. The map publishes fine, the basemap displays correctly but the features in the feature service do not show up when I view the web map in the Map Viewer. They are listed in the Details window correctly but do not have any symbology. When I click on the  Legend button it says there is no legend. If I create a web map from with ArcGIS Online using the same feature service, the features show up correctly. 

0 Kudos
13 Replies
by Anonymous User
Not applicable

Daniel, as of Python API versions 1.3 and later, you can directly work with `WebMap` object to add, remove layers, update URLs and finally call the `update()` method off the WebMap object. Below is an example for the problem you are trying to solve (cloning a web map, customizing it with your urls).

# clone web map
template_webmap_item = source_gis.content.get(template_webmap_id)
result_webmaps = target_gis.content.clone_items([template_webmap_item], copy_data=False)

# edit the cloned web map
cloned_webmap_item = result_webmaps[0]

# replace url
from arcgis.mapping import WebMap
cloned_webmap = WebMap(cloned_webmap_item)

# replace url - repeat for as many layers you need
cloned_webmap.layers[0].url = 'replacement_url'

# push updates to portal
cloned_webmap.update()
DanielMast
Esri Contributor

Hi Atma, 

Thanks for the tip! I hadn't worked with the API in a while and didn't realize I could work with the WebMap object directly. We are experiencing strange behaviour with the update() function: when calling cloned_webmap.update() with no parameters, the urls are not updated in the webmap. When I give a dictionary of item_properties as a first argument, then the urls are updated but the properties (ie title, name, description, tags...) are not updated. I have also tried the same properties with .save() which I would expect to create a new WebMap but it seems nothing is happening. Another thing we tried is changing the properties directly such as cloned_WebMap_item.title = webMapTitle and then ran update() again, but that also made no difference... here's the code snippet:

web_map_properties = {
   "title": "Test WebMap",
   "description": "Test WebMap description",
   "tags": "Calculation, Result"
}
cloned_webmap.update(web_map_properties)
cloned_WebMap_item.title = "Test WebMap"
cloned_webmap.update(web_map_properties)

Do you have any suggestions or notice what I am doing wrong? 

Thank you again for your help!

0 Kudos
by Anonymous User
Not applicable

Daniel, I will test this out and get back to you

0 Kudos
CharlieWare
New Contributor II

Thanks Atma for all your help.