Select to view content in your preferred language

create annotations

136
6
Monday
rs_gs
by
New Contributor

Hi All

 

Hi All

I am working to implement an annotation tool,Click the button to display all annotations.Why do I use this code to create annotations, but when the program runs it shows blank space?Am i missing something?

(c sharp code)

CIMLabelClass labelClass = new CIMLabelClass
{Visibility = true };
 labelClasses.Add(labelClass);
layerDef.LabelClasses = labelClasses.ToArray();
layerDef.LabelVisibility = true;
layer.SetDefinition(layerDef);
mapView.Redraw(true);

Thanks!

rs

0 Kudos
6 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Annotation layers haven't labels. Showing of annotations is organized with sublayers.

GKmieliauskas_0-1718692339159.png

CIMAnnotationLayer Sublayers property is array of  CIMAnnotationSubLayer.

0 Kudos
rs_gs
by
New Contributor

I'm sorry I made a mistake.I want to display multiple groups of labels that I have set.Thank you.

rs_gs_0-1718721731422.png

rs_gs_1-1718721811769.png

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

I think that you need to set  TextSymbol property for your created labelClass.

  // Blue label
  CIMLabelClass blueLabelClass = new CIMLabelClass
  {
    Name = "Blue",
    ExpressionTitle = "Expression-Blue",
    ExpressionEngine = LabelExpressionEngine.Arcade,
    Expression = "$feature.OBJECTID",
    ID = 2,
    Priority = 0,
    Visibility = true,
    TextSymbol = new CIMSymbolReference
    {
      Symbol = new CIMTextSymbol()
      {
        Angle = 45,
        FontType = FontType.Type1,
        FontFamilyName = "Consolas",
        FontEffects = FontEffects.Normal,
        HaloSize = 2.0,

        Symbol = new CIMPolygonSymbol
        {
          SymbolLayers = new CIMSymbolLayer[]
          {
            new CIMSolidFill
            {
              Color = CIMColor.CreateRGBColor(0, 0, 255)
            }
          },
          UseRealWorldSymbolSizes = true
        }
      },
      MaxScale = 0,
      MinScale = 0,
      SymbolName = "TextSymbol-Blue"
    },
    StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
    {
      AllowOverlappingLabels = true,
      LineOffset = 1.0
    },
    MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
    {
      AlignLabelToLineDirection = true,
      AvoidPolygonHoles = true
    }
  };
0 Kudos
rs_gs
by
New Contributor

I've created several tag classes.After the code is run,  tag classes are generated,but it doesn't show.However, without changing any parameters, manually operate ArcGIS pro, click the Apply button, the label will be displayed.

Thanks.

rs_gs_0-1718764536354.png

 

CIMLabelClass labelClass = new CIMLabelClass

{
Name = $"LabelClass_{value}",
Expression = "$feature.Label", 
ExpressionEngine = LabelExpressionEngine.Arcade, 
Priority = 0,
Visibility = true,
WhereClause = $"Label = '{river}'", 
TextSymbol = SymbolFactory.Instance.ConstructTextSymbol(color, 15, "Arial").MakeSymbolReference(),

};

labelClasses.Add(labelClass);

var layerDef = featureLayer.GetDefinition() as CIMFeatureLayer;
layerDef.LabelClasses = labelClasses.ToArray();
featureLayer.SetDefinition(layerDef);
featureLayer.SetLabelVisibility(true);

mapView.Redraw(true);

0 Kudos
GKmieliauskas
Esri Regular Contributor

Try to put mapView.Redraw(true); in another QueuedTask.Run. Sometimes separating MCT threads helps.

Or use RedrawAsync method outside QueuedTask.Run  which doesn't need MCT thread.

0 Kudos
rs_gs
by
New Contributor

Okay, I tried it. The problem still persists. I will try other methods. Thank you for your reply many times.

 

0 Kudos