Skip to content

Instantly share code, notes, and snippets.

@geobabbler
Created January 16, 2015 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geobabbler/652210cc0c7bea694aae to your computer and use it in GitHub Desktop.
Save geobabbler/652210cc0c7bea694aae to your computer and use it in GitHub Desktop.
void win_Closed(object sender, EventArgs e)
{
TextSymbolPropsWindow win = sender as TextSymbolPropsWindow;
if ((bool)win.DialogResult)
{
GraphicsLayer graphicsLayer = BoundMap.Layers["AnnoLayer"] as GraphicsLayer; //the layer on which the anno will be drawn
string input = win.Annotation;
if (!String.IsNullOrEmpty(input))
{
MapPoint pt = _currentPoint; //the location of the original mouse click
TextSymbol sym = new TextSymbol(); //create a new text symbol
sym.FontFamily = new FontFamily(win.TextFont); //set the symbol's font from the window value
sym.FontSize = win.TextFontSize; //set the symbol's font size from the window value
sym.Text = win.Annotation; //apply the text string from the window to the symbol
sym.Foreground = new SolidColorBrush { Color = Colors.Black }; //set the color. this could be user-selectable as well
Zekiah.Samples.Font f = new Font(); //this is a simple container object I wrote to pass font properties around
f.Family = sym.FontFamily;
f.Size = sym.FontSize;
f.Style = FontStyles.Normal;
f.Weight = FontWeights.Normal;
String s = new String(input.ToCharArray());
Size size = s.Measure(f); //use the extension method to measure the string
sym.OffsetX = size.Width / 2; //set offset to center horizontally
sym.OffsetY = size.Height / 2; //set offset to center vertically
//create the graphic and apply the geometry and symbol
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = pt,
Symbol = sym,
};
//set up the mouse event for the context menu
graphic.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(graphic_MouseRightButtonDown);
//this block replaces the previous annotation if this was an edit operation
if (win.EditMode)
{
graphicsLayer.Graphics.Remove(Ambient.SelectedSymbol);
}
graphicsLayer.Graphics.Add(graphic); //add the new graphic to the map
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment