BookmarksGallery.cs
// Copyright 2011 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using ESRI.ArcGISExplorer; using ESRI.ArcGISExplorer.Mapping; using ESRI.ArcGISExplorer.Geometry; using ESRI.ArcGISExplorer.Data; using ESRI.ArcGISExplorer.Threading; using ESRI.ArcGISExplorer.Application; namespace BookmarksGalleryCS { /// <summary> /// Implements a custom bookmarks gallery /// </summary> /// <remarks> /// Listens to the DocumentOpened event on the Application and includes /// a gallery item for each View in the map. The Views are attached as tags /// to the gallery items so the map can be navigated to them when they are clicked. /// </remarks> public class BookmarksGallery : ESRI.ArcGISExplorer.Application.Gallery { /// <summary> /// Creates a new BookmarksGallery instance /// </summary> public BookmarksGallery() { // listen for the document opened event ESRI.ArcGISExplorer.Application.Application.DocumentOpened += new EventHandler(Application_DocumentOpened); // listen for the map item changed ESRI.ArcGISExplorer.Application.Application.MapItemChanged += new EventHandler<MapItemEventArgs>(Application_MapItemChanged); // call the event handler in case the gallery is loaded // after the document has been opened Application_DocumentOpened(null, EventArgs.Empty); } /// <summary> /// Raised when a new map document (.nmf) is opened /// </summary> void Application_DocumentOpened(object sender, EventArgs e) { // add the views from the map to the gallery PopulateGallery(); } /// <summary> /// Raised when an item in the map changes /// </summary> void Application_MapItemChanged(object sender, MapItemEventArgs e) { // if the changed item is a view, then re-populate the gallery if (e.MapItem is View) PopulateGallery(); } /// <summary> /// Raised when a gallery item is clicked /// </summary> /// <param name="item"></param> public override void OnClick(GalleryItem item) { // get the view from the item's tag property and zoom // the map to its viewpoint View view = item.Tag as View; ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.ZoomTo(view.Viewpoint); } /// <summary> /// Helper method to clear and populate the gallery items /// with the views in the map /// </summary> private void PopulateGallery() { Items.Clear(); // find all the Views in the map and add a gallery item for each one Map map = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map; foreach (View view in map.GetMapItems<View>()) Items.Add(new GalleryItem(view.Name, Resources.Flag64, view.Name) { Tag = view }); } } }