About the GraphicTracker with the map Sample
[C#]
AddGT.cs
using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using System.Collections.Generic; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.EngineCore; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; namespace GraphicTrackerMap { [Guid("80D5A1C9-A848-4c58-98D7-F8ED5B5A6235")] [ClassInterface(ClassInterfaceType.None)] [ProgId("GraphicTrackerMap.AddGT")] public sealed class AddGT : BaseTool { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static void RegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); // // TODO: Add any COM registration code here // } [ComUnregisterFunction()] [ComVisible(false)] static void UnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); // // TODO: Add any COM unregistration code here // } #region ArcGIS Component Category Registrar generated code /// <summary> /// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryRegistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Register(regKey); } /// <summary> /// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryUnregistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Unregister(regKey); } #endregion #endregion private IHookHelper m_hookHelper; private GTMapForm m_form = null; public AddGT() { base.m_category = "Add GT"; //localizable text base.m_caption = "Add GT"; //localizable text base.m_message = "Add GT"; //localizable text base.m_toolTip = "Add graphic"; //localizable text base.m_name = "GraphicTrackerMap_AddGT"; //unique id, non-localizable (e.g. "MyCategory_MyTool") try { string bitmapResourceName = GetType().Name + ".bmp"; base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap"); } } #region Overriden Class Methods public override void OnCreate(object hook) { if (m_hookHelper == null) m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; } public override void OnClick() { IToolbarControl2 toolBarControl = m_hookHelper.Hook as IToolbarControl2; IMapControl4 mapControl = m_hookHelper.Hook as IMapControl4; if (toolBarControl != null) mapControl = toolBarControl.Buddy as IMapControl4; if (mapControl == null) return; if (m_form == null) m_form = mapControl.CustomProperty as GTMapForm; return; } public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (m_form.m_graphicTracker == null || m_form.m_GTSymbols == null) return; //Get the 1st Graphic Symbol IGraphicTrackerSymbol gtSymbol = m_form.m_GTSymbols[0]; // get the first one if (gtSymbol == null) return; //Add the point and symbol to the GraphicTracker //This returns an id that you can store in a Dictionary to use later to //(e.g. select from combo and highlight, change symbol, change label) IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); int id = m_form.m_graphicTracker.Add(point as IGeometry, gtSymbol); m_form.m_graphicTracker.SetLabel(id, "ID " + id.ToString()); m_form.m_GTGeometries.Add(id, point as IGeometry); } #endregion } }
[Visual Basic .NET]
AddGT.vb
Imports System.Drawing Imports System.Windows.Forms Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.ADF.BaseClasses Imports ESRI.ArcGIS.ADF.CATIDs Imports System.Collections.Generic Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.EngineCore Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Display Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Carto <Guid("80D5A1C9-A848-4c58-98D7-F8ED5B5A6235")> _ <ClassInterface(ClassInterfaceType.None)> _ <ProgId("GraphicTrackerMap.AddGT")> _ Public NotInheritable Class AddGT Inherits BaseTool #Region "COM Registration Function(s)" <ComRegisterFunction> _ <ComVisible(False)> _ Private Shared Sub RegisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType) ' ' TODO: Add any COM registration code here ' End Sub <ComUnregisterFunction> _ <ComVisible(False)> _ Private Shared Sub UnregisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType) ' ' TODO: Add any COM unregistration code here ' End Sub #Region "ArcGIS Component Category Registrar generated code" ''' <summary> ''' Required method for ArcGIS Component Category registration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryRegistration(registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) ControlsCommands.Register(regKey) End Sub ''' <summary> ''' Required method for ArcGIS Component Category unregistration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryUnregistration(registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) ControlsCommands.Unregister(regKey) End Sub #End Region #End Region Private m_hookHelper As IHookHelper Private m_form As GTMapForm = Nothing Public Sub New() MyBase.m_category = "Add GT" 'localizable text MyBase.m_caption = "Add GT" 'localizable text MyBase.m_message = "Add GT" 'localizable text MyBase.m_toolTip = "Add graphic" 'localizable text MyBase.m_name = "GraphicTrackerMap_AddGT" 'unique id, non-localizable (e.g. "MyCategory_MyTool") Try Dim bitmapResourceName As String = [GetType]().Name & ".bmp" MyBase.m_bitmap = New Bitmap([GetType](), bitmapResourceName) MyBase.m_cursor = New System.Windows.Forms.Cursor([GetType](), [GetType]().Name & ".cur") Catch ex As Exception System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap") End Try End Sub #Region "Overridden Class Methods" Public Overrides Sub OnCreate(ByVal hook As Object) If m_hookHelper Is Nothing Then m_hookHelper = New HookHelperClass() End If m_hookHelper.Hook = hook End Sub Public Overrides Sub OnClick() Dim toolBarControl As IToolbarControl2 = TryCast(m_hookHelper.Hook, IToolbarControl2) Dim mapControl As IMapControl4 = TryCast(m_hookHelper.Hook, IMapControl4) If toolBarControl IsNot Nothing Then mapControl = TryCast(toolBarControl.Buddy, IMapControl4) End If If mapControl Is Nothing Then Return End If If m_form Is Nothing Then m_form = TryCast(mapControl.CustomProperty, GTMapForm) End If Return End Sub Public Overrides Sub OnMouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer) If m_form.m_graphicTracker Is Nothing OrElse m_form.m_GTSymbols Is Nothing Then Return End If 'Get the 1st Graphic Symbol Dim gtSymbol As IGraphicTrackerSymbol = m_form.m_GTSymbols(0) ' get the first one If gtSymbol Is Nothing Then Return End If 'Add the point and symbol to the GraphicTracker 'This returns an id that you can store in a Dictionary to use later to '(e.g. select from combo and highlight, change symbol, change label) Dim point As IPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y) Dim id As Integer = m_form.m_graphicTracker.Add(TryCast(point, IGeometry), gtSymbol) m_form.m_graphicTracker.SetLabel(id, "ID " & id.ToString()) m_form.m_GTGeometries.Add(id, TryCast(point, IGeometry)) End Sub #End Region End Class