ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMGeoFeatureLayerBase Class / LabelClasses Property
Example

In This Topic
    LabelClasses Property (CIMGeoFeatureLayerBase)
    In This Topic
    Gets or sets the collection of label class definitions.
    Syntax
    public CIMLabelClass[] LabelClasses {get; set;}
    Public Property LabelClasses As CIMLabelClass()
    Example
    Modify label expression using Arcade
    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
    if (lyr == null) return;
    QueuedTask.Run(() =>
    {
      //Get the layer's definition
      //community sample Data\Admin\AdminSample.aprx
      var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
      if (lyrDefn == null) return;
      //Get the label classes - we need the first one
      var listLabelClasses = lyrDefn.LabelClasses.ToList();
      var theLabelClass = listLabelClasses.FirstOrDefault();
      //set the label class Expression to use the Arcade expression
      theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;";
      //Set the label definition back to the layer.
      lyr.SetDefinition(lyrDefn);
    });
    
    Apply text symbol to a feature layer
    //Note: call within QueuedTask.Run()
    
    //Get the layer's definition
    var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
    //Get the label classes - we need the first one
    var listLabelClasses = lyrDefn.LabelClasses.ToList();
    var theLabelClass = listLabelClasses.FirstOrDefault();
    //Set the label classes' symbol to the custom text symbol
    //Refer to the ProSnippets-TextSymbols wiki page for help with creating custom text symbols.
    //Example: var textSymbol = await CreateTextSymbolWithHaloAsync();
    theLabelClass.TextSymbol.Symbol = textSymbol;
    lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
    featureLayer.SetDefinition(lyrDefn); //set the layer's definition
                                         //set the label's visiblity
    featureLayer.SetLabelVisibility(true);
    Modify the Placement/Position of labels - Point geometry
    //Note: call within QueuedTask.Run()
    
    //Get the layer's definition
    var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
    //Get the label classes - we need the first one
    var listLabelClasses = lyrDefn.LabelClasses.ToList();
    var theLabelClass = listLabelClasses.FirstOrDefault();
    
    //Modify label Placement 
    //Check if the label engine is Maplex or standard.
    CIMGeneralPlacementProperties labelEngine = 
       MapView.Active.Map.GetDefinition().GeneralPlacementProperties;
    if (labelEngine is CIMStandardGeneralPlacementProperties) //Current labeling engine is Standard labeling engine               
      theLabelClass.StandardLabelPlacementProperties.PointPlacementMethod = 
               StandardPointPlacementMethod.OnTopPoint;
    else    //Current labeling engine is Maplex labeling engine            
      theLabelClass.MaplexLabelPlacementProperties.PointPlacementMethod = 
              MaplexPointPlacementMethod.CenteredOnPoint;
    
    lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
    featureLayer.SetDefinition(lyrDefn); //set the layer's definition
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also