Popup and Filter information not showing on Python API generated Web Map with Views

421
7
Jump to solution
04-10-2024 11:05 AM
BrandonYates1
New Contributor II

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

Screenshot 2024-04-10 124651.jpg

New Web Map Made from GUI:

Screenshot 2024-04-10 125122.png

Python API Web Map:

Screenshot 2024-04-10 125703.png

 

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:

  1. Reviewed the View and Web Map item on ArcGIS Assistant (They look normal, can provide the json if it is helpful)
  2. Refreshing Web Map
  3. Verified that Popups are enabled on the Web Map

 

I would greatly appreciate some help on the subject!

 

Tags (1)
1 Solution

Accepted Solutions
GIS_utahDEM
Occasional Contributor II

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? 

View solution in original post

7 Replies
GIS_utahDEM
Occasional Contributor II

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. 

BrandonYates1
New Contributor II

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.

Untitled Diagram.drawio.png

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!

0 Kudos
GIS_utahDEM
Occasional Contributor II

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

0 Kudos
BrandonYates1
New Contributor II
0 Kudos
GIS_utahDEM
Occasional Contributor II

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? 

BrandonYates1
New Contributor II

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

0 Kudos
BrandonYates1
New Contributor II

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)})

 

 

0 Kudos