Hi,
I have layers with in their attributes some value like the color text or the text size and i want to make a label for each layer where the value is what they got in their attributes. So i would got a green text for a layer and a red text for another. I dont know if having a different label for each is possible, and if it is, can you explain me how and how can i get all the values from each layers in my code (C#). Sorry if i'm not explaining well.
Thank you
Solved! Go to Solution.
Yes i wanted to do the second case. I finally found that i can change my label style in Arcade by using Expression.
" <FNT name = '" + $feature.et1_police_txt +"' style = 'Regular' size = '" + $feature.et1_taille_txt+ "' > " + " <CLR " + et1_couleur_txt + " ><BGD " + $feature.et1_couleur_fond +" > "+ $feature.libelle +" </BGD ></CLR ></FNT > "
//And in the code I put this expression in the label class expression
theLabelClass.Expression = myExpression;
//myExpression is the expression at the begin of the code
Now with the same layer i have different color, size, font... depending on the value of each entity.
Thank you very much for your help and your time 🙂
Hi,
You can look at ArcGIS Pro Snippets:
https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-TextSymbols
https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Labeling
private static Task<CIMTextSymbol> CreateSimpleTextAsync()
{
return QueuedTask.Run <CIMTextSymbol>(() =>
{
//Create a simple text symbol
return SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
});
}
//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.
var textSymbol = await CreateSimpleTextAsync();
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);
P.s. Sample for one class, but you can create classes for each attribute value combination
I add something similar
CIMFeatureLayer myCIMFeatureLayer = featureLayer.GetDefinition() as CIMFeatureLayer;
var listLabelClasses = myCIMFeatureLayer.LabelClasses.ToList();
var theLabelClass = listLabelClasses.FirstOrDefault();
var textSymbol = theLabelClass.TextSymbol.Symbol as CIMTextSymbol;
textSymbol.FontStyleName = "Regular";
//@TODO remplacer par les valeurs du featureLayer
textSymbol.FontFamilyName = "Verdana"; //@TODO
textSymbol.SetSize(13); //@TODO
textSymbol.OffsetX = 2; //@TODO
textSymbol.OffsetY = 28; //@TODO
textSymbol.SetColor(ColorFactory.Instance.GreenRGB); //@TODO
var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.WhiteRGB/*@TODO*/, SimpleFillStyle.Solid);
CIMBalloonCallout balloonCallout = new CIMBalloonCallout
{
BalloonStyle = BalloonCalloutStyle.Rectangle,
UseDartSymbol = true,
BackgroundSymbol = polySymbol,
Margin = new CIMTextMargin
{
Left = 5,
Right = 5,
Bottom = 5,
Top = 5
}
};
textSymbol.Callout = balloonCallout;
theLabelClass.Expression = "$feature.libelle";
var test = myCIMFeatureLayer.CustomProperties;
featureLayer.SetDefinition(myCIMFeatureLayer);
featureLayer.SetLabelVisibility(true);
});
This is working. The result is my first screen, and i want to have different Label depending on the attribute value of each layer. How can i change my value here, like the SetSize(13) to SetSize(eachLayer.TextSize) or something like this. I think i have to do a foreach but i can't find on what object.
Thanks for your help
You update only first or default layer label class. You need to create new/update list of LabelClasses as in link .
You can add label classes from symbology layers . Each symbology class will have label class. So you need to set each label class for text size, font and etc. Then you don't need directly to use attribute fields like text size or font.
I will try that, thank you
I'm trying your solution to create many classes as i need but how i tell "this one you will have the classe 2, this other one you will have the class 8 ...". How i tell him wich classes he have to use ?
Is it possible to do too a foreach(entity in layers) to get all the entity present in the map ?
Let's clear up your question: "Have different label for each layer in a FeatureLayer"
Do you mean "Have different label for each layer in a Map" or "Have different label for each feature in a FeatureLayer"?
If first case it is enough to do "foreach(entity in layers)" and set Symbol parameters for first or default LabelClass. But each your layer must have one symbol symbolization.
In second case you need using ArcGIS Pro create symbolization classes for your layer using subtypes or your layer attribute table fields save layer to lyrx. In your code apply symbolization from lyr file to layer then update LabelClasses. You can create and symbolization classes from code.
Simplest solution, I think, is to create lyrx file with symbolization and labeling using ArcGIS Pro and in code apply lyrx for layer only.
Yes i wanted to do the second case. I finally found that i can change my label style in Arcade by using Expression.
" <FNT name = '" + $feature.et1_police_txt +"' style = 'Regular' size = '" + $feature.et1_taille_txt+ "' > " + " <CLR " + et1_couleur_txt + " ><BGD " + $feature.et1_couleur_fond +" > "+ $feature.libelle +" </BGD ></CLR ></FNT > "
//And in the code I put this expression in the label class expression
theLabelClass.Expression = myExpression;
//myExpression is the expression at the begin of the code
Now with the same layer i have different color, size, font... depending on the value of each entity.
Thank you very much for your help and your time 🙂
How to create classes you can find here: