I'm trying to use the Python API to turn on labels for a layer in a hosted feature view. My methodology is to retrieve a feature layer collection, loop the layers, and then turn the labeling on as part of setting the symbology. When I complete this, I end up with a section that looks like this in my service definition:
"drawingInfo":{"renderer":{"type":"simple","label":"","description":"","symbol":{"color":null,"outline":{"color":[230,76,0,255],"width":3,"type":"esriSLS","style":"esriSLSLongDash"},"type":"esriSFS","style":"esriSFSSolid"}},"labelingInfo":[{"labelExpression":null,"labelExpressionInfo":{"expression":"$feature[\"site_name\"]","value":"{site_name}"},"useCodedValues":true,"maxScale":0,"minScale":1725490,"where":null,"labelPlacement":"esriServerPolygonPlacementAlwaysHorizontal","symbol":{"color":[0,0,0,255],"type":"esriTS","backgroundColor":null,"borderLineColor":null,"borderLineSize":null,"haloSize":0,"haloColor":null,"verticalAlignment":"bottom","horizontalAlignment":"center","rightToLeft":false,"angle":0,"xoffset":0,"yoffset":0,"text":"","rotated":false,"kerning":true,"font":{"size":8.25,"style":"normal","decoration":"none","weight":"normal","family":"Arial"}}}],"transparency":0}
However, when I check the layer out in the Visualization module of AGOL I can not see the labels (nor can I see them when I open the later in the map viewer). I have to select the label icon, unclick the label features, click them back on, and then save the layer. Then the labels appear. When I look at the service definition, it looks the same as above. In fact, the only difference is that the last edit date for the layer is updated after I save. Any idea what saving the layer does that my Python scripting (fragment below) needs to do?
view_flc = FeatureLayerCollection.fromitem(view_search[0])
site_labels = []
site_labels.append(json.loads(util.site_labels()))
for lyr in view_flc.layers :
if lyr.properties.name == "Mining Site":
lyr.manager.update_definition({"drawingInfo": {"renderer":{"type":"simple","label":"","description":"","symbol":
{"color":None,"outline":{"color [230,76,0,255],"width":3,"type":"esriSLS","style":"esriSLSLongDash"},
"type":"esriSFS","style":"esriSFSSolid"}},"labelingInfo":site_labels,"transparency":0}})