ArcFM Engine Developer Guide
DevBookmarkCommand.cs Code

Resource Center Home

Flyout Command Developer Sample (C#)

DevBookmarkCommand.cs

Copy Code
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using Miner.Windows.ArcGIS;
using Miner.Windows;
using Miner.Windows.Commands;
namespace Miner.DeveloperSamples.Engine
{
 public sealed class DevBookmarkCommand : PopupMenuCommand
 {
  #region Public Constructors/Destructors
  public DevBookmarkCommand() : base("DevBookmarkCommand")
  {
   base.Caption = "Dev: Bookmark Command";
   this.Category = "ArcFM Developer Samples";
   this.CustomizerCaption = "Dev: Bookmarks";
   this.CustomizerDescription = "Allows the user to select a bookmark from a list of bookmarks";
   
   Enabled = false;
   MainArcEngineApp.CurrentMapChanged +=new MainArcEngineApp.CurrentMapChangedEventHandler(MainArcEngineApp_CurrentMapChanged);
  }
  #endregion Public Constructors/Destructors
  
  #region CommandPopup Overrides
  public override void OnDropDownOpening(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) 
    {
     DevBookmark newBookmark = new DevBookmark(currentMap, spatialBookmark, spatialBookmark.Name);
     if (null != newBookmark) 
     {
      this.Commands.Add(newBookmark);
     }
     spatialBookmark = enumSpatialBookmarks.Next();
    }
    base.OnDropDownOpening(args);
   }
   catch(Exception exc) 
   {
    MessageBox.Show("BookmarkCommand::BeforeDropDown" + exc.ToString());
    return;
   }
  }
  public override void OnDropDownClosed(CommandEventArgs args)
  {
   this.Commands.Clear(true);
  }
  public override bool Enabled
  {
   get
   {
    base.Enabled = IsEnabled(MainArcEngineApp.FocusMap()); 
    return base.Enabled;
   }
   set
   {
    base.Enabled = value;
   }
  }
  
  #endregion CommandPopup Overrides
  #region Private Methods
  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;
   }
  }
  private void MainArcEngineApp_CurrentMapChanged(object sender, CurrentMapChangedEventArgs e)
  {
   bool checkEnabledStatus = Enabled;   
  }
  
  #endregion Private Methods
 }
}

 

 

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com