Select to view content in your preferred language

how to label a graphics layer?

4480
2
Jump to solution
10-15-2014 07:01 PM
PeterBennett
Deactivated User

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

0 Kudos
1 Solution

Accepted Solutions
CedricSeah
Occasional Contributor

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.

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;

View solution in original post

0 Kudos
2 Replies
CedricSeah
Occasional Contributor

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.

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;

0 Kudos
PeterBennett
Deactivated User

Thank you.

That's exactly what I needed.

Best Regards

0 Kudos