Select to view content in your preferred language

Code for creating map labels from feature attributes

872
2
09-27-2011 10:11 AM
DavidHedberg
New Contributor
I'm trying to find code sample that shows how to create map labels from feature attributes in a graphics layer.  I have a graphics layer with selected polygon features and their attributes.  I've developed the code for displaying the attribute information in maptips but can't figure out how to label the polygons using a textsymbol.
0 Kudos
2 Replies
GarimaVyas
Emerging Contributor
David,
You could follow this sample. Basically, you create a text symbol like this:

   TextSymbol textSymbol = new TextSymbol()
                {
                    FontFamily = new System.Windows.Media.FontFamily("Arial"),
                    Foreground = new System.Windows.Media.SolidColorBrush(Colors.Black),
                    FontSize = 10,
                    Text = <bind it to the graphic's attribute>
                };

and use it for graphics's symbol property. If you already have polygon symbol added to the existing graphics, you might have to create another graphic using the polygon graphics geometry (or its center map point).
0 Kudos
DavidHedberg
New Contributor
Garima,

Thank you for the code.  This is helpful.  Would it be possible for you to also send a code snippet that shows the use of labelpoints for identifying the textsymbol placement.

Thanks.
0 Kudos