Hi!
Context:
I am working on generating a set of feature layer views from a template web map, then create a web map with those views using the python api. I have been able to successfully generate the views from the template, then create a web map containing those views.
Problem:
The styling, filters, and PopupInfo from the template are visible on the View visualization tab and when creating a new web map from that view. Only the styling is visible on the programatically generated web map, not the filters or popup formatting.
Visualization Tab
New Web Map Made from GUI:
Python API Web Map:
Code Snipped for View + Web Map Creation
web_map = WebMap()
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
for category, data in feature_categories.items():
name = f"{category} {project} View"
print(name)
if data['type'] == 'scan':
view = scan_data_item.manager.create_view(name = name)
view.update(item_properties={'text': json.dumps({'layers': [data['data']], 'tables': []})})
web_map.add_layer(view, {'title': name})
elif data['type'] == 'strip':
view = strip_data_item.manager.create_view(name = name)
view.update(item_properties={'text': json.dumps({'layers': [data['data']], 'tables': []})})
web_map.add_layer(view, {'title': name})
elif data['type'] == 'ind':
view = ind_data_item.manager.create_view(name = name)
view.update(item_properties={'text': json.dumps({'layers': [data['data']], 'tables': []})})
web_map.add_layer(view, {'title': name})
# Save the WebMap
web_map_properties = {'title': f' Web Map Project {project}',
'snippet': 'This web map was created using the ArcGIS Python API',
'tags': 'ArcGIS Python API'}
web_map_item = web_map.save(item_properties=web_map_properties)
Things I Tried:
I would greatly appreciate some help on the subject!
Solved! Go to Solution.
Ohhh, okay I see. Does the AGO assistant for the web map show the same JSON as the view or is it different? I might try getting the layer and adding to the webmap via the .search() method instead of directly?
Hello,
I have a script I use to create/update view layers that maintains the pop-up info, symbology and form info (editing) from the master hosted feature layer using the python API. The link to the repository is here -- specifically the JurisdictionalViewLayer_CreateUpdate_UCIP: https://github.com/julia-surkis/Utah-Critical-Infrastructure-Prioritization/tree/main
The main thing you will need to do is save the information you want directly to the master hosted feature layer (pop-up and symbology in the Visualization tab of the hosted feature layer, form-info in the Field Maps Designer. Once you have that set up, this script goes through pulling that info from the master feature layer's JSON and including it in the updated/created view layers.
This is great! I wish I knew about this before I started working on this. We have a super similar workflow. Here's a diagram of what I'm trying to do for reference.
It looks like the main difference is that you are adding components of the template definition piece by piece and I'm just pasting the whole definition in there. Is there something else that I'm missing? I'll try to implement your approach and see if it fixes it!
Very cool! Yeah, the only thing I can think of is making sure to save the pop-up info to the layer itself in the visualization tab instead of the map
Here's a screen recording of me further describing the issue! https://www.loom.com/share/2fb1450823ac42329932d8a3eb63ad46?sid=5e2f1414-21b6-41d6-8e04-747af77b4dbe
Ohhh, okay I see. Does the AGO assistant for the web map show the same JSON as the view or is it different? I might try getting the layer and adding to the webmap via the .search() method instead of directly?
That seems to be the issue! The Web Map seems to have a PopupInfo Field that is very different from the View PopupInfo. I'll try that method now
Got it working but it's a bit ugly! I added another loop that applies the formatting to the web map as well. I think it would be a bit cleaner to find a method to add the view to the web map while retaining the formatting from the view but this seems to work. Very similar to your code in: https://github.com/julia-surkis/Utah-Critical-Infrastructure-Prioritization/tree/main
map_data = web_map_item.get_data()
for layer in map_data['operationalLayers']:
view_name = layer['title']
for definition in feature_categories:
if feature_categories[definition]['view_name'] == view_name:
layer['layerDefinition'] = feature_categories[definition]['data']
layer['popupInfo'] = feature_categories[definition]['data']['popupInfo']
break
web_map_item.update(item_properties={'text': json.dumps(map_data)})