I have an issue with labeling. How do you set up a new label class for a feature layer and then set it to that layer to be viewed on the map? I have code that should work, but I can only create new label classes. I am unable to properly associate them to my feature layer so that they can be seen. As an fyi, I can check the label classes in the GUI and my new custom classes do show up. The only way that I can see any labels though is to use the default label class. I have deleted the default label class in the hopes that it will display my custom classes, but that doesn't work either. Any help would be greatly appreciated.
The following is my current code:
private void CreateLabelProperties(string className, System.Drawing.Color color, string whereClause = "")
{
CIMColor annoColor = CIMColor.CreateRGBColor(color.R, color.G, color.B, 100);
CIMTextSymbol textSymbol = SymbolFactory.Instance.ConstructTextSymbol(annoColor, 12, "Arial", "Bold");
CIMSymbolReference textSymRef = textSymbol.MakeSymbolReference();
CIMFeatureLayer layerDef = _gridLayer.GetDefinition() as CIMFeatureLayer;
List<CIMLabelClass> listLabelClasses = new List<CIMLabelClass>();
if (layerDef.LabelClasses?.Length > 0)
{
listLabelClasses = layerDef.LabelClasses.ToList();
}
CIMLabelClass labelClass;
if (className == "Default")
{
labelClass = layerDef.LabelClasses.ToList().FirstOrDefault();
}
else
{
labelClass = new CIMLabelClass();
labelClass.Name = className;
labelClass.ExpressionEngine = LabelExpressionEngine.Arcade;
labelClass.Expression = string.Format("$feature.{0}", CellNameField);
labelClass.WhereClause = whereClause;
labelClass.Visibility = true;
listLabelClasses.Add(labelClass);
}
labelClass.TextSymbol = textSymRef;
CIMStandardLabelPlacementProperties standardLabelPlacementProps = new CIMStandardLabelPlacementProperties
{
FeatureType = LabelFeatureType.Polygon
};
labelClass.StandardLabelPlacementProperties = standardLabelPlacementProps;
layerDef.LabelClasses = listLabelClasses.ToArray();
_gridLayer.AddLabelClass(className);
_gridLayer.SetDefinition(layerDef);
_gridLayer.SetLabelVisibility(true);
}