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
Solved! Go to Solution.
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
Within the AttributeLabelClass, you can specify the label placement and other properties of the label.
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.
Sample lifted from the ArcGIS Runtime docs |
---|
// 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; |
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
Within the AttributeLabelClass, you can specify the label placement and other properties of the label.
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.
Sample lifted from the ArcGIS Runtime docs |
---|
// 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.
Best Regards