Select to view content in your preferred language

Remap Legend Labels based on Attribute field value

70
0
yesterday
JasperRomero
Occasional Contributor

Hello all,

I am hoping to get some clarification around properties and structures of items for this scenario:

I have a Web Map containing a Point Layer, with the symbology based on a field in that layer ("Stop_Number"). By default, the label in the Legend is just the value of the field that determines the symbology, i.e. Stop_Number - so in this case, stops are labeled things like 1, 2, 3, etc.

I want to programmatically change the labels in the Legend to pull values from another field, "Title". From what I have found so far, it should be possible to do this by modifying the renderer portion JSON layer definition using the Python API:

  • Access the feature layer itself:
    • create a dictionary mapping Stop_Number field values (the keys) to their corresponding Title values (the values)
  • Access the JSON object defining the layer in the Web Map:
    • access the 'renderer' dict in the 'drawingInfo' of the 'layerDefinition' of the relevant layer
    • use the dictionary to change the value for the "label" key to have the Title text, based on a match with the "values" key (which holds Stop_Number)

Does this approach seem correct? Do I have my properties and structures figured out correctly? If so, I would deeply appreciate any suggestions for the syntax of making the actual changes - currently my conceptual framework is to iterate through 'values' in the 'classes' of 'uniqueValueGroups' 'headings', then set the value for 'label' to be the dict value whose key corresponds the current 'values' value? How do I implement/save the changes to the JSON item once made?

Apologies for any unclear language used here - I am learning my way around the API and the JSON items. Thanks in advance for any suggestions!

0 Kudos
0 Replies