Select to view content in your preferred language

Using ArcPY to turn on labeling in an AGOL hosted feature layer view

495
2
03-05-2020 12:18 PM
ChrisEmmerich1
Emerging Contributor

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

0 Kudos
2 Replies
JamesCrandall
MVP Frequent Contributor

What is the return message? 

Check for: {'success': True}

(I'm not implementing via the Python API but still working with AGOL items via urllib/urllib2/requests, but I still try to check for return messages when executing these types of things)

0 Kudos
ChrisEmmerich1
Emerging Contributor

It does return success: True.  The label visualization tool also has the scale values preset to what I've set in my script.  But there seems to be something that saving in that tool does that isn't happening when I update the label definition in my ArcPy script.

0 Kudos