About the RSS weather GraphicTracker Sample
[C#]
AddRSSWeather.cs
using System; using System.Drawing; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Carto; namespace RSSWeatherGraphicTracker { /// <summary> /// Command that works in ArcMap/Map/PageLayout, ArcScene/SceneControl /// or ArcGlobe/GlobeControl /// </summary> [Guid("ffae67a3-92b6-47d6-9d33-a8dd909a53c4")] [ClassInterface(ClassInterfaceType.None)] [ProgId("RSSWeatherGraphicTracker.AddRSSWeather")] public sealed class AddRSSWeather : BaseCommand { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static void RegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); } [ComUnregisterFunction()] [ComVisible(false)] static void UnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); } #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); GMxCommands.Register(regKey); MxCommands.Register(regKey); SxCommands.Register(regKey); 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); GMxCommands.Unregister(regKey); MxCommands.Unregister(regKey); SxCommands.Unregister(regKey); ControlsCommands.Unregister(regKey); } #endregion #endregion private IHookHelper m_hookHelper = null; private IGlobeHookHelper m_globeHookHelper = null; private bool m_bConnected = false; private RSSWeather m_rssWeather = null; public AddRSSWeather() { base.m_category = "Weather"; base.m_caption = "Add RSS Weather"; base.m_message = "Add RSS Weather"; base.m_toolTip = "Add RSS Weather"; base.m_name = "Add RSS Weather"; try { string bitmapResourceName = GetType().Name + ".bmp"; base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap"); } } #region Overriden Class Methods /// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (hook == null) return; // Test the hook that calls this command and disable if nothing is valid try { m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; if (m_hookHelper.ActiveView == null) { m_hookHelper = null; } } catch { m_hookHelper = null; } if (m_hookHelper == null) { //Can be globe try { m_globeHookHelper = new GlobeHookHelperClass(); m_globeHookHelper.Hook = hook; if (m_globeHookHelper.ActiveViewer == null) { m_globeHookHelper = null; } } catch { m_globeHookHelper = null; } } if (m_globeHookHelper == null && m_hookHelper == null) base.m_enabled = false; else base.m_enabled = true; } /// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IBasicMap basicMap = null; if (m_hookHelper != null) { basicMap = m_hookHelper.FocusMap as IBasicMap; } else if (m_globeHookHelper != null) { basicMap = m_globeHookHelper.Globe as IBasicMap; } if (basicMap == null) return; try { if (!m_bConnected) { m_rssWeather = new RSSWeather(); m_rssWeather.Init(basicMap); } else { m_rssWeather.Remove(); m_rssWeather = null; } m_bConnected = !m_bConnected; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } } public override bool Checked { get { return m_bConnected; } } #endregion } }
[Visual Basic .NET]
AddRSSWeather.vb
Imports System.Drawing Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.ADF.BaseClasses Imports ESRI.ArcGIS.ADF.CATIDs Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.Carto ''' <summary> ''' Command that works in ArcMap/Map/PageLayout, ArcScene/SceneControl ''' or ArcGlobe/GlobeControl ''' </summary> <Guid("ffae67a3-92b6-47d6-9d33-a8dd909a53c4")> _ <ClassInterface(ClassInterfaceType.None)> _ <ProgId("RSSWeatherGraphicTracker.AddRSSWeather")> _ Public NotInheritable Class AddRSSWeather Inherits BaseCommand #Region "COM Registration Function(s)" <ComRegisterFunction> _ <ComVisible(False)> _ Private Shared Sub RegisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType) End Sub <ComUnregisterFunction> _ <ComVisible(False)> _ Private Shared Sub UnregisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType) 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) GMxCommands.Register(regKey) MxCommands.Register(regKey) SxCommands.Register(regKey) 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) GMxCommands.Unregister(regKey) MxCommands.Unregister(regKey) SxCommands.Unregister(regKey) ControlsCommands.Unregister(regKey) End Sub #End Region #End Region Private m_hookHelper As IHookHelper = Nothing Private m_globeHookHelper As IGlobeHookHelper = Nothing Private m_bConnected As Boolean = False Private m_rssWeather As RSSWeather = Nothing Public Sub New() MyBase.m_category = "Weather" MyBase.m_caption = "Add RSS Weather" MyBase.m_message = "Add RSS Weather" MyBase.m_toolTip = "Add RSS Weather" MyBase.m_name = "Add RSS Weather" Try Dim bitmapResourceName As String = [GetType]().Name & ".bmp" MyBase.m_bitmap = New Bitmap([GetType](), bitmapResourceName) Catch ex As Exception System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap") End Try End Sub #Region "Overridden Class Methods" ''' <summary> ''' Occurs when this command is created ''' </summary> ''' <param name="hook">Instance of the application</param> Public Overrides Sub OnCreate(ByVal hook As Object) If hook Is Nothing Then Return End If ' Test the hook that calls this command and disable if nothing is valid Try m_hookHelper = New HookHelperClass() m_hookHelper.Hook = hook If m_hookHelper.ActiveView Is Nothing Then m_hookHelper = Nothing End If Catch m_hookHelper = Nothing End Try If m_hookHelper Is Nothing Then 'Can be globe Try m_globeHookHelper = New GlobeHookHelperClass() m_globeHookHelper.Hook = hook If m_globeHookHelper.ActiveViewer Is Nothing Then m_globeHookHelper = Nothing End If Catch m_globeHookHelper = Nothing End Try End If If m_globeHookHelper Is Nothing AndAlso m_hookHelper Is Nothing Then MyBase.m_enabled = False Else MyBase.m_enabled = True End If End Sub ''' <summary> ''' Occurs when this command is clicked ''' </summary> Public Overrides Sub OnClick() Dim basicMap As IBasicMap = Nothing If m_hookHelper IsNot Nothing Then basicMap = TryCast(m_hookHelper.FocusMap, IBasicMap) ElseIf m_globeHookHelper IsNot Nothing Then basicMap = TryCast(m_globeHookHelper.Globe, IBasicMap) End If If basicMap Is Nothing Then Return End If Try If Not m_bConnected Then m_rssWeather = New RSSWeather() m_rssWeather.Init(basicMap) Else m_rssWeather.Remove() m_rssWeather = Nothing End If m_bConnected = Not m_bConnected Catch ex As Exception System.Diagnostics.Trace.WriteLine(ex.Message) End Try End Sub Public Overrides ReadOnly Property Checked() As Boolean Get Return m_bConnected End Get End Property #End Region End Class