Hello All,
I have an attribute "Id" in my graphics layer, may I use it to label it? would someone please share some code sample?
Thank you in advance
Best Regards
Not done this myself, and assuming you are using the Runtime SDK for .NET 10.2.4:
Each GraphicLayer has a Labelling Property
GraphicsLayer.Labeling Property
Within this LabellingProperty you are expected to add AttributeLabelClasses
LabelProperties Class ,
Within the AttributeLabelClass, you can specify the label placement and other properties of the label.
AttributeLabelClass Class
I am assuming that it is the TextExpression property that you will use to indicate that the "Id" attribute should be used for the label's text content.
// create a new TextSymbol for displaying graphic labels
var labelSym = new Esri.ArcGISRuntime.Symbology.TextSymbol();
// define the font: Arial, 10pt, non-italic, non-underlined, bold
labelSym.Font = new Esri.ArcGISRuntime.Symbology.SymbolFont ("Arial", 10.0, Esri.ArcGISRuntime.Symbology.SymbolFontStyle.Normal, Esri.ArcGISRuntime.Symbology.SymbolTextDecoration.None, Esri.ArcGISRuntime.Symbology.SymbolFontWeight.Bold);
// define the font color and halo (border)
labelSym.Color = Colors.Blue; labelSym.BorderLineColor = Colors.LightBlue; labelSym.BorderLineSize = 1;
// create a new LabelClass
var labelClass = new Esri.ArcGISRuntime.Layers.AttributeLabelClass();
// assign the TextSymbol
labelClass.Symbol = labelSym;
// provide a text expression:
// attribute names in [brackets]
// hard-coded text in "quotes"
// CONCAT to concatenate
// NEWLINE for line break
labelClass.TextExpression = "[Name] CONCAT NEWLINE CONCAT [Rating] CONCAT \" stars\"";
// add the new LabelClass to the GraphicsLayer's collection
graphicsLayer.Labeling.LabelClasses.Add(labelClass);
// enable labeling
graphicsLayer.Labeling.IsEnabled = true;
Thank you.
That's exactly what I needed.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.