Version: 10.2.1c and 10.2.1c SP3 |
ArcFM Engine Overview > Application Framework Overview > Commands in ArcFM Engine Applications > Flyout Command Code Sample |
This code sample creates a flyout menu that lists the available bookmarks in the selected stored display. The flyout menu class determines how the control acts when the user expands and contracts the menu. Each time a stored display is selected, the OnBeforeDropDown gathers a collection of bookmarks and creates a command class for each one. This command class (or bookmark command) executes the bookmark when the user selects it. Control commands must be added to a custom layout XML file before they will appear in the user interface.
A flyout command may reside on a toolbar or as a menu item. The sample code in this section creates a Bookmark command that displays available bookmarks in the currently selected stored display. The command may be placed on a toolbar or as a menu item, as shown below.
|
|
![]() |
The default transparent color for bitmap icons is magenta (RGB - 255, 0, 255). |
This sample requires installation of the ArcFM Solution Software Developer Kit (SDK). You may need to change the existing installation in Add/Remove Programs to add Developer Resources.
While custom flyout commands may be created for Responder Explorer, this particular sample may not be used in Responder Explorer as there are no stored displays.
This section contains two code samples: the flyout menu and the bookmark command.
Product Availability: ArcFM Engine applications, ArcFM Viewer for ArcGIS Engine
References: Miner.Interop.Framework, Miner.Windows, Miner.Windows.ArcGIS
Set the required using directives.
This command inherits from CommandPopupMenu.
Set the base class properties and command properties in the constructor.
Sets up the event handler for when the current map changes.
Override the OnBeforeDropDown event. This event gets a collection of bookmarks from the stored display.
The OnBeforeDropDown event creates a command for each bookmark it finds and adds it to its menu.
Override the OnAfterDropDownCloseup event. This event clears the list of bookmarks.
Override the Enabled event. The Enabled event in this sample calls IsEnabled. The code executed in IsEnabled, may also be executed in the Enabled event instead.
The IsEnabled event determines under which conditions the command is enabled. This event is not required; the Enabled event may be used instead.
Executes when the event is fired.
C# Sample - Flyout Menu |
Copy Code
|
---|---|
using System; using System.Windows.Forms; using Esri.ArcGIS.Carto; using Esri.ArcGIS.esriSystem; using Miner.Interop; //1 using Miner.Windows.ArcGIS; using Miner.Windows; using Miner.Windows.Command; namespace Miner.DeveloperSamples.Engine { /// <summary> /// Summary description for BookmarkCommand. /// </summary> public sealed class DevBookmarkCommand : CommandPopupMenu { #region Public Constructors/Destructors //2 public DevBookmarkCommand() : base("DevBookmarkCommand") { base.Caption = "Bookmark Command"; //3 this.Category = "ArcFM Developer Samples"; this.CustomizerCaption = "Bookmarks"; this.CustomizerDescription = "Allows the user to select a bookmark from a list of bookmarks"; Enabled = false; //4 MainArcEngineApp.CurrentMapChanged +=new MainArcEngineApp.CurrentMapChangedEventHandler(MainArcEngineApp_CurrentMapChanged); } #endregion Public Constructors/Destructors #region CommandPopup Overrides //5 public override void OnBeforeDropDown(CancelableCommandEventArgs args) { try { for(int idx = this.Commands.Count - 1; idx >= 0; --idx) { Command cmd = this.Commands[idx]; Command cmdRemove = MainApp.MainWin.CommandManager.Commands[cmd.Key]; this.Commands.Remove(cmd.Key); MainApp.MainWin.CommandManager.Commands.Remove(cmdRemove); } IMap currentMap = MainArcEngineApp.FocusMap(); if (null == currentMap) return; IMapBookmarks currentBookmarks = currentMap as IMapBookmarks; if (null == currentBookmarks) return; IEnumSpatialBookmark enumSpatialBookmarks = currentBookmarks.Bookmarks; if (null == enumSpatialBookmarks) return; enumSpatialBookmarks.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); while (null != spatialBookmark) { //6 DevBookmark newBookmark = new DevBookmark(currentMap, spatialBookmark, spatialBookmark.Name); if (null != newBookmark) { this.Commands.Add(newBookmark); } spatialBookmark = enumSpatialBookmarks.Next(); } base.OnBeforeDropDown(args); } catch(Exception exc) { MessageBox.Show("BookmarkCommand::BeforeDropDown" + exc.ToString()); return; } } //7 public override void OnAfterDropDownCloseup(CommandEventArgs args) { this.Commands.Clear(true); } //8 public override bool Enabled { get { base.Enabled = IsEnabled(MainArcEngineApp.FocusMap()); return base.Enabled; } set { base.Enabled = value; } } #endregion CommandPopup Overrides #region Private Methods //9 private bool IsEnabled(IMap pMap) { try { bool bEnabled = false; if (null == pMap) return bEnabled; //now do the selecting UID pUID = new UIDClass(); if (null == pUID) return bEnabled; pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; IEnumLayer pEnumLayers = null; try { pEnumLayers = pMap.get_Layers(pUID, true); } catch { return bEnabled; } if (null == pEnumLayers) return bEnabled; pEnumLayers.Reset(); IFeatureLayer pFLayer = null; ILayer pLayer = pEnumLayers.Next(); while (null != pLayer) { pFLayer = pLayer as IFeatureLayer; if (null != pFLayer) { bEnabled = true; break; } pLayer = pEnumLayers.Next(); } return bEnabled; } catch(Exception exc) { MessageBox.Show("BookMarkCommand::IsEnabled" + exc.ToString()); return false; } } //10 private void MainArcEngineApp_CurrentMapChanged(object sender, CurrentMapChangedArgs e) { bool checkEnabledStatus = Enabled; } #endregion Private Methods } } |
Bookmark Command
Set the using directive for Miner.Windows.Command.
The empty base class is required. DevBookmark passes a key to this class. The key is then displayed in the list of bookmarks.
The map and spatial bookmark information is passed in from the flyout menu command.
The OnClick event zooms to the extent of the selected spatial bookmark and refreshes the data view.
C# Sample - Bookmark Command |
Copy Code
|
---|---|
using System; using System.Windows.Forms; using Esri.ArcGIS.Carto; //1 using Miner.Windows.Command; namespace Miner.DeveloperSamples.Engine { /// <summary> /// Summary description for MMBookmark. /// </summary> public sealed class DevBookmark : CommandButton { #region Private Declarations ISpatialBookmark _spatialBookmark = null; IMap _currentMap = null; #endregion #region Public Constructors/Destructors //2 public DevBookmark() : base(string.Empty) { } //3 public DevBookmark(IMap currentMap, ISpatialBookmark spatialBookmark, string newKey) : base(newKey, newKey) { _spatialBookmark = spatialBookmark; _currentMap = currentMap; } #endregion Public Constructors/Destructors #region CommandButtons Overrides //Execute /// <summary> /// user selected a bookmark - apply it to the map /// </summary> //4 protected override void OnClick(EventArgs args) { if (null == _spatialBookmark) return; if (null == _currentMap) return; try { _spatialBookmark.ZoomTo(_currentMap); IActiveView activeView = _currentMap as IActiveView; if (null != activeView) { activeView.Refresh(); } } catch (Exception exc) { MessageBox.Show("MMBookmark::Execute" + exc.ToString()); return; } } #endregion CommandButton Overrides } } |
Return to Custom Commands and Controls