Select to view content in your preferred language

Dictionary from .get_data() doesnt recognize key that exists in dictionary

279
1
08-07-2024 01:59 PM
ChrisCowin_dhs
Occasional Contributor

Hello, I'm very confused on how to modify the JSON of the actual web map. I have a user who is not really a GIS person and has little interest in developing those skills so I'm just trying to automate the entire process but it is actually really difficult to modify the various elements of the actual map. I've tried to follow this but it just doesn't behave in the same way even when I'm doing basically the same thing with a WebMap instead of a WebScene.

Below is my code and it will get to the part where it is checking the layer's itemId so I modify the correct layer. However, python doesn't seem to think that there is an itemId key in the web_map_obj dictionary but there very much is and when I print web_map_obj I can see there is an itemId key. What gives?

 

gis = GIS('home')

web_map_item = gis.content.get('0b442333de0544569191341e5e64dbad')
web_map_obj = web_map_item.get_data()

display(web_map_obj)
subset_op_layers = [subset for subset in web_map_obj['operationalLayers']]

for layer in subset_op_layers:
    display(layer.keys())
    if layer['itemID'] == '9aa6edefe3dd45febafddffe71d07ca5':
        popup_info = layer['popupInfo']
        layer['popupInfo']['title'] = '{Clinic_Sit}'
        layer['popupInfo']['fieldInfos'][0]['visible'] = False
        layer['popupInfo']['fieldInfos'][1]['label'] = 'Agency Name'
        layer['popupInfo']['fieldInfos'][2]['visible'] = False
        layer['popupInfo']['fieldInfos'][3]['label'] = 'Street Address'
        layer['popupInfo']['fieldInfos'][9]['label'] = 'Website'
        layer['popupInfo']['fieldInfos'][10]['label'] = 'Hours of Operation'
        layer['popupInfo']['fieldInfos'][11]['label'] = 'Accepting New Patients'
        layer['popupInfo']['fieldInfos'][12]['label'] = 'Schedule an Appointment By'
        layer['popupInfo']['fieldInfos'][13]['label'] = 'Bilingual Medical Provider (Yes/No)'
        layer['popupInfo']['fieldInfos'][14]['label'] = 'Bilingual Medical Provider Language'
        layer['popupInfo']['fieldInfos'][15]['label'] = 'Onsite Interpretation Services (Yes/No)'
        layer['popupInfo']['fieldInfos'][16]['label'] = 'Onsite Interpretation Services Language'
        layer['popupInfo']['fieldInfos'][17]['label'] = 'Telehealth Interpretation Services (Yes/No)'
        layer['popupInfo']['fieldInfos'][18]['label'] = 'Telehealth Interpretation Services Language'
        layer['popupInfo']['fieldInfos'][19]['visible'] = False
        layer['popupInfo']['fieldInfos'][20]['visible'] = False
        
new_web_map_properties = web_map_properties
new_web_map_properties['text'] = json.dumps(new_web_scene_obj)

# new_item = gis.content.add(new_web_map_properties)
# new_item

 

 

 output of layer.keys():

 

 

dict_keys(['title', 'opacity', 'visibility', 'id', 'layerDefinition', 'layerType', 'itemId', 'url', 'popupInfo'])

 

 

0 Kudos
1 Reply
Clubdebambos
Frequent Contributor

Hi @ChrisCowin_dhs 

Your...

layer['itemID']

 

Should be...

layer['itemId']

 

Lowercase d at the end.

All the best,

Glen

~ learn.finaldraftmapping.com