I would like to be able to create a new label class on a featurelayer using the sdk.
Here is a code snippet to create a new label class and assign it to a feature layer.
Thanks
Uma
QueuedTask.Run(() => {
var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
//get the layer's defintion
var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
//Text symbol to use for labelling
var textSymbol = SymbolFactory.Instance.ConstructTextSymbol();
//Create the new label class and initialize props
var newLabelClass = new CIMLabelClass
{
//Define the label expression engine
ExpressionEngine = LabelExpressionEngine.Arcade,
//Expression to use to label
Expression = "$feature.NAME + $feature.Shape_Area",
Visibility = true,
TextSymbol = textSymbol.MakeSymbolReference(),
Name = "MyNewLabelClass"
};
//Most of the Maplex and standard engine placement properties get set automatically.
//But you have to set the feature type explicitly. Line seems default.
var maplexLabelPlacementProps = new CIMMaplexLabelPlacementProperties
{
FeatureType = LabelFeatureType.Polygon
};
var standardLabelPlacementProps = new CIMStandardLabelPlacementProperties
{
FeatureType = LabelFeatureType.Polygon
};
//Set the placement prop defined to the label class.
newLabelClass.MaplexLabelPlacementProperties = maplexLabelPlacementProps;
newLabelClass.StandardLabelPlacementProperties = standardLabelPlacementProps;
//Get the layer's label classes
var lyrsLabelsClasses = lyrDefn.LabelClasses.ToList();
//Add the new label class to the labels label class
lyrsLabelsClasses.Add(newLabelClass);
lyrDefn.LabelClasses = lyrsLabelsClasses.ToArray(); //Set the labelClasses back
lyr.SetDefinition(lyrDefn); //set the layer's definition;
});
I tried it and it did not work. It does not create the label class and assign it on any of the layers.
Never mind , I was able to get it to work.
Thank you
I actually figured it out….AutoReorder on the CIMLegend
Thank you