Hi Everbody
I am trying to label a FeatureLayer with values from an attribute, but somehow it fails. I have calculated the z-value and want to label that, but for some reason it label another attribute.
In the CIMLabelClass I define the Expression to be the 'zValue' attribute:
var labelFeatureLayer = new CIMLabelClass
{
Name = "labelFeatureLayer",
ExpressionEngine = LabelExpressionEngine.Arcade,
Expression = "$feature.zValue",
TextSymbol = SymbolFactory.Instance.ConstructTextSymbol().MakeSymbolReference(),
Visibility = true
};
var lyrDefn = fcLayer.GetDefinition() as CIMFeatureLayer;
var listLabelClasses = lyrDefn.LabelClasses.ToList();
listLabelClasses.Add(labelFeatureLayer);
lyrDefn.LabelClasses = listLabelClasses.ToArray();
fcLayer.SetDefinition(lyrDefn);
fcLayer.SetLabelVisibility(true);
But its just showing a different attribute (in this case its the objectid)
Hi,
I think you need to switch off visibility for other existing label classes. Look at Esri community sample LabelLineFeatures
//Turn off all the label classes except this one
foreach (var lc in listLabelClasses)
{
lc.Visibility = lc.Name == "labelFeatureLayer" ? true : false;
}
The following snippet worked for me:
protected override async void OnClick()
{
var fcLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name == "TestPoints").FirstOrDefault();
await QueuedTask.Run(() =>
{
List<CIMLabelClass> newLabels = new List<CIMLabelClass>()
{ new CIMLabelClass
{
Name = "labelFeatureLayer",
ExpressionEngine = LabelExpressionEngine.Arcade,
Expression = "Geometry($feature).z",
TextSymbol = SymbolFactory.Instance.ConstructTextSymbol().MakeSymbolReference(),
Visibility = true
}
};
var lyrDefn = fcLayer.GetDefinition() as CIMFeatureLayer;
lyrDefn.LabelClasses = newLabels.ToArray();
fcLayer.SetDefinition(lyrDefn);
fcLayer.SetLabelVisibility(true);
});
}
@GKmieliauskas is correct as there can be multiple labels with visibility. The snippet above removes all but the new label from the array of labels.
Hi, thanks.
I tried with your code @Wolf but ArcGIS Pro doesn't show the label.
The label tab dont show the new label class:
But if I manual in ArcGis Pro create a label class (eg. 'test'), suddenly the new label class appires:
Do I need to delete some Label Classes before? Or do I need do to something with 'Class 1'?