Hello,
So I have some code that I want to use to modify the JSON of a web_map, but I'm having a hard time getting it to work.
I have a SeDF that I'm converting to a Feature Layer:
fl = sedf.spatial.to_featurelayer(title=title, gis=gis, service_name=title)
Then I add it to the web map object:
wm.add_layer(fl, renderer_properties)
From here do I need to do an update to the web map and then use the get_data() function on the now updated web map object? Because basically I only want two layers in the web map and the fl I'm adding and a county boundary layer. I've tried it both ways but neither is working.
wm_item = gis.content.get(wm_id)
wm_data = wm_item.get_data()
wm = WebMap(wm_item)
When I then go to loop through the layers the fl.id never matches the item_ids from the operational layer, frequently they have different lengths which doesnt make any sense to me they are supposed to be accessing the same thing right?
for i, layer in enumerate(wm_data['operationalLayers']):
# This is for the new Feature Layer
print(layer)
print(layer['itemId'] + ' :: ' + fl.id)
if layer['itemId'] == fl.id:
print(layer.keys())
print(layer['title'] + ' :: ' + layer['itemId'])
popup_info = layer['popupInfo']
layer['title'] = title
layer['disablePopup'] = False
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
# This disables the popups for the county feature layer so you can select the points more easily
elif layer['itemId'] == county_id:
print(str(i) + ' ' + layer['itemId'] + ' removing popups')
layer['disablePopup'] = True
else:
print(str(i) + ' ' + layer['itemId'] + ' removing layer')
wm.remove_layer(layers[i])
itemId and a layer id in a WebMap are two different things. The itemId is the unique id for any item in your AGOL/Portal (Feature Service, Web Map, Dashboard, Form, etc). The layer id in a WebMap definition (from the operationalLayers in the JSON) is a unique id for each layer in that map only. The itemId is generally system maintained, but the layer id in a WebMap you can define yourself by updating the JSON - as long as you keep it unique to other layer ids in the same WebMap. Your itemId will not match a layer id from the operationalLayers in a WebMap.
Each layer in the operationalLayers also has an itemId property that will match the Feature Service item it is referenced from.
Each layer in the operationalLayers also has an itemId property that will match the Feature Service item it is referenced from.
Yeah, that is what I'm doing isn't it?
I'm not comparing from a layer in the layer list (wm.layers). One itemId is from the operationalLayer json:
wm_item.get_data()['operationalLayer'][i]['itemId']
, but the other isnt from a Layer object but the actual Feature Layer object:
fl = sedf.spatial.to_featurelayer(title=title, gis=gis, service_name=title)
fl.id