About the Add a custom bookmarks MultiItem to the ToolbarControl Sample
[C#]
SpatialBookmarks.cs
using System; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Carto; namespace MultiItemBookmarks { public class SpatialBookmarks : IMultiItem { private IHookHelper m_HookHelper; public SpatialBookmarks() { m_HookHelper = new HookHelperClass(); } public int get_ItemBitmap(int index) { return 0; } public string get_ItemCaption(int index) { //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks) m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to get bookmark names ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { //Get the correct bookmark if (bookmarkCount == index) { //Return the bookmark name return spatialBookmark.Name; } bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } return ""; } public bool get_ItemChecked(int index) { return false; } public bool get_ItemEnabled(int index) { return true; } public void OnItemClick(int index) { //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks) m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to get bookmark to zoom to ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { //Get the correct bookmark if (bookmarkCount == index) { //Zoom to the bookmark spatialBookmark.ZoomTo(m_HookHelper.FocusMap); //Refresh the map m_HookHelper.ActiveView.Refresh(); } bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } } public int OnPopup(object hook) { m_HookHelper.Hook = hook; //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks) m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to count them ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } //Return the number of multiitems return bookmarkCount; } public string Caption { get { return "Spatial Bookmarks"; } } public int HelpContextID { get { return 0; } } public string HelpFile { get { return null; } } public string Message { get { return "Spatial bookmarks in the focus map"; } } public string Name { get { return "Spatial Bookmarks"; } } } }
[Visual Basic .NET]
SpatialBookmarks.vb
Option Strict Off Option Explicit On Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.Carto Friend Class SpatialBookmarksMultiItem Implements IMultiItem Private m_pHookHelper As IHookHelper Public Sub New() MyBase.New() m_pHookHelper = New HookHelperClass End Sub Protected Overrides Sub Finalize() m_pHookHelper = Nothing End Sub Private ReadOnly Property IMultiItem_Caption() As String Implements IMultiItem.Caption Get Return "Spatial Bookmarks" End Get End Property Private ReadOnly Property IMultiItem_HelpContextID() As Integer Implements IMultiItem.HelpContextID Get 'Not implemented End Get End Property Private ReadOnly Property IMultiItem_HelpFile() As String Implements IMultiItem.HelpFile Get Return "" End Get End Property Private ReadOnly Property IMultiItem_ItemCaption(ByVal index As Integer) As String Implements IMultiItem.ItemCaption Get 'Get the bookmarks of the focus map Dim pMapBookmarks As IMapBookmarks pMapBookmarks = m_pHookHelper.FocusMap 'Get bookmarks enumerator Dim pEnumSpatialBookmarks As IEnumSpatialBookmark pEnumSpatialBookmarks = pMapBookmarks.Bookmarks pEnumSpatialBookmarks.Reset() 'Loop through the bookmarks to get bookmark names Dim pSpatialBookmark As ISpatialBookmark Dim bookmarkCount As Integer pSpatialBookmark = pEnumSpatialBookmarks.Next bookmarkCount = 0 Do Until pSpatialBookmark Is Nothing 'Get the correct bookmark If bookmarkCount = index Then 'Return the bookmark name Return pSpatialBookmark.Name Exit Do End If bookmarkCount = bookmarkCount + 1 pSpatialBookmark = pEnumSpatialBookmarks.Next Loop Return "" End Get End Property Private ReadOnly Property IMultiItem_ItemChecked(ByVal index As Integer) As Boolean Implements IMultiItem.ItemChecked Get 'Not implemented End Get End Property Private ReadOnly Property IMultiItem_ItemEnabled(ByVal index As Integer) As Boolean Implements IMultiItem.ItemEnabled Get Return True End Get End Property Private ReadOnly Property IMultiItem_Message() As String Implements IMultiItem.Message Get Return "Spatial bookmarks in the focus map" End Get End Property Private ReadOnly Property IMultiItem_Name() As String Implements IMultiItem.Name Get Return "Spatial Bookmarks" End Get End Property Private Sub IMultiItem_OnItemClick(ByVal index As Integer) Implements IMultiItem.OnItemClick 'Get the bookmarks of the focus map Dim pMapBookmarks As IMapBookmarks pMapBookmarks = m_pHookHelper.FocusMap 'Get bookmarks enumerator Dim pEnumSpatialBookmarks As IEnumSpatialBookmark pEnumSpatialBookmarks = pMapBookmarks.Bookmarks pEnumSpatialBookmarks.Reset() 'Loop through the bookmarks to get bookmark to zoom to Dim pSpatialBookmark As ISpatialBookmark Dim bookmarkCount As Integer pSpatialBookmark = pEnumSpatialBookmarks.Next bookmarkCount = 0 Do Until pSpatialBookmark Is Nothing 'Get the correct bookmark If bookmarkCount = index Then 'Zoom to the bookmark pSpatialBookmark.ZoomTo(m_pHookHelper.FocusMap) 'Refresh the map m_pHookHelper.ActiveView.Refresh() Exit Do End If bookmarkCount = bookmarkCount + 1 pSpatialBookmark = pEnumSpatialBookmarks.Next Loop End Sub Private Function IMultiItem_OnPopup(ByVal hook As Object) As Integer Implements IMultiItem.OnPopup m_pHookHelper.Hook = hook 'Get the bookmarks of the focus map Dim pMapBookmarks As IMapBookmarks pMapBookmarks = m_pHookHelper.FocusMap 'Get bookmarks enumerator Dim pEnumSpatialBookmarks As IEnumSpatialBookmark pEnumSpatialBookmarks = pMapBookmarks.Bookmarks pEnumSpatialBookmarks.Reset() 'Loop through the bookmarks to count them Dim pSpatialBookmark As ISpatialBookmark Dim bookmarkCount As Integer pSpatialBookmark = pEnumSpatialBookmarks.Next bookmarkCount = 0 Do Until pSpatialBookmark Is Nothing bookmarkCount = bookmarkCount + 1 pSpatialBookmark = pEnumSpatialBookmarks.Next Loop 'Return the number of multiitems IMultiItem_OnPopup = bookmarkCount End Function Public ReadOnly Property ItemBitmap(ByVal index As Integer) As Integer Implements ESRI.ArcGIS.SystemUI.IMultiItem.ItemBitmap Get End Get End Property End Class