Select to view content in your preferred language

Retrieve text from TextSymbol

591
1
03-21-2011 07:35 AM
ErikEngstrom
Frequent Contributor
I have a snippet that saves/opens graphics within a project, writing to a CSV.
I have a TextSymbol in my map and would like to save these markup graphics that contain text/labels to the CSV as well, but I'm having a hard time retrieving the text of the TextSymbol.

GraphicCollection pGC = graphicsLayer.Graphics;
foreach (Graphic g in pGc)
{
if (g.Geometry is ESRI.ArcGIS.Client.Symbols.TextSymbol)
{
MapPoint pPoint = (MapPoint)g.Geometry;
pStreamWriter.WriteLine("TEST, " + pPoint.X.ToString() + ", " + pPoint.Y.ToString());
}


In the WriteLine, I would like to add the text of the TextSymbol.
Any ideas?
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
If the Text of your TextSymbol is set to one of your graphic attributes, you can simply get the attribute value. Otherwise, you can cast the Symbol to TextSymbol to get Text property.
private void GraphicsLayer_Initialized(object sender, System.EventArgs e)
{
 GraphicsLayer layer = sender as GraphicsLayer;
 foreach (var g in layer.Graphics)
 {
  g.Attributes["Location"] = g.Geometry;
  g.Symbol = new TextSymbol() { Text = g.Attributes["Location"].ToString()};
  //System.Diagnostics.Debug.WriteLine(g.Attributes["Location"]); //from attribute
  System.Diagnostics.Debug.WriteLine((g.Symbol as TextSymbol).Text); //as TextSymbol
 }
}
0 Kudos