Created
January 16, 2015 21:01
-
-
Save geobabbler/652210cc0c7bea694aae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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