基于AE的SimpleGIS框架的搭建

ArcGIS是Esri公司集40余年地理信息系统(GIS)咨询和研发经验,奉献给用户的一套完整的GIS平台产品,具有强大的地图制作、空间数据管理、空间分析、空间信息整合、发布与共享的能力。本人主要就AE搭建框架做简单的介绍

框架是指一个系统的全部或部分可复用设计,通常由一组抽象类和类之间的协助组成,其有几个特点。

1.模块化:应用框架可以从逻辑上划分为若干个不同的功能模块。

2.可重用性:代码的可重用性是衡量代码健壮性的一个标志,无论是函数,类,接口,还是其他更高层次的模型,都是为了提高其重用性。

3.可扩展性:可扩展性是应用框架一个最显著地标志,他意味着框架的能力具有可生长性。

其实arcmap也是一个可以扩展的框架,下面我们通过对arcmap的框架的研究来学习如何搭建自己的框架

首先我们打开arcmap编写一个简单的宏

基于AE的SimpleGIS框架的搭建_第1张图片

 

 

宏命名为zoomin--实现一个简单的放大功能

 2 Dim imxdocument As imxdocument
 3 Dim penovlop As IEnvelope
 4 Set imxdocument = ThisDocument
 5 Set penovlop = imxdocument.ActiveView.Extent
 6 penovlop.Expand 0.2, 0.2, True
 7 imxdocument.ActiveView.Extent = penovlop
 8 imxdocument.ActiveView.Refresh

 

保存宏,在菜单--自定义--自定义模式--工具条  新建工具条

 基于AE的SimpleGIS框架的搭建_第2张图片

我们在arcmap工具条看到一个新的工具栏,

 在菜单--自定义--自定义模式--命令  找到 --宏   将我们刚才写的宏拖到菜单栏,这样我们就实现 了一个简单的功能

基于AE的SimpleGIS框架的搭建_第3张图片

基于AE的SimpleGIS框架的搭建_第4张图片

如此可见arcmap是一个可拓展的框架

2.通过实现接口或者抽象类的方法实现arcgis功能

如图安装了arcgis后 可以使用arcgis addin 来扩展功能

基于AE的SimpleGIS框架的搭建_第5张图片

  1 namespace ClassLibrary1
  2 {
  3     /// <summary>
  4     /// Command that works in ArcMap/Map/PageLayout
  5     /// </summary>
  6     [Guid("86fbcea5-043b-404a-a00c-5c480b42f51e")]
  7     [ClassInterface(ClassInterfaceType.None)]
  8     [ProgId("ClassLibrary1.Command1")]
  9     public sealed class Command1 : BaseCommand
 10     {
 11         // 将.net 注册为com函数
 12         #region COM Registration Function(s)
 13         [ComRegisterFunction()]
 14         [ComVisible(false)]
 15         static void RegisterFunction(Type registerType)
 16         {
 17             // Required for ArcGIS Component Category Registrar support
 18             ArcGISCategoryRegistration(registerType);
 19 
 20             //
 21             // TODO: Add any COM registration code here
 22             //
 23         }
 24 
 25         [ComUnregisterFunction()]
 26         [ComVisible(false)]
 27         static void UnregisterFunction(Type registerType)
 28         {
 29             // Required for ArcGIS Component Category Registrar support
 30             ArcGISCategoryUnregistration(registerType);
 31 
 32             //
 33             // TODO: Add any COM unregistration code here
 34             //
 35         }
 36 
 37         #region ArcGIS Component Category Registrar generated code
 38         /// <summary>
 39         /// Required method for ArcGIS Component Category registration -
 40         /// Do not modify the contents of this method with the code editor.
 41         /// </summary>
 42         private static void ArcGISCategoryRegistration(Type registerType)
 43         {
 44             string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
 45             MxCommands.Register(regKey);
 46             ControlsCommands.Register(regKey);
 47         }
 48         /// <summary>
 49         /// Required method for ArcGIS Component Category unregistration -
 50         /// Do not modify the contents of this method with the code editor.
 51         /// </summary>
 52         private static void ArcGISCategoryUnregistration(Type registerType)
 53         {
 54             string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
 55             MxCommands.Unregister(regKey);
 56             ControlsCommands.Unregister(regKey);
 57         }
 58 
 59         #endregion
 60         #endregion
 61 
 62         private IHookHelper m_hookHelper = null;
 63         public Command1()
 64         {
 65             // 初始化
 66             // TODO: Define values for the public properties
 67             //
 68             base.m_category = ""; //localizable text
 69             base.m_caption = "";  //localizable text 
 70             base.m_message = "This should work in ArcMap/MapControl/PageLayoutControl";  //localizable text
 71             base.m_toolTip = "";  //localizable text
 72             base.m_name = "";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")
 73 
 74             try
 75             {
 76                 //
 77                 // TODO: change bitmap name if necessary
 78                 //
 79                 string bitmapResourceName = GetType().Name + ".bmp";
 80                 base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
 81             }
 82             catch (Exception ex)
 83             {
 84                 System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
 85             }
 86         }
 87 
 88         #region Overridden Class Methods
 89 
 90         /// <summary>
 91         /// Occurs when this command is created
 92         /// </summary>
 93         /// <param name="hook">Instance of the application</param>
 94         public override void OnCreate(object hook)
 95         {
 96             //重写基类
 97             if (hook == null)
 98                 return;
 99 
100             try
101             {
102                 m_hookHelper = new HookHelperClass();
103                 m_hookHelper.Hook = hook;
104                 if (m_hookHelper.ActiveView == null)
105                     m_hookHelper = null;
106             }
107             catch
108             {
109                 m_hookHelper = null;
110             }
111 
112             if (m_hookHelper == null)
113                 base.m_enabled = false;
114             else
115                 base.m_enabled = true;
116 
117             // TODO:  Add other initialization code
118         }
119 
120         /// <summary>
121         /// Occurs when this command is clicked
122         /// </summary>
123         public override void OnClick()
124         {
125             //全图显示
126             IMapControl2 Pmapcontrol2 = m_hookHelper as IMapControl2;
127             Pmapcontrol2.Extent = Pmapcontrol2.FullExtent;
128             Pmapcontrol2.Refresh();
129         }
130 
131         #endregion
132     }
133 }
生成dll文件,将其bin下面的 tlb.格式的文件 加载到 arcmap
基于AE的SimpleGIS框架的搭建_第6张图片
二:基于simplegis的水电工程系统
基于AE的SimpleGIS框架的搭建_第7张图片
初始化
  1  #region 私有变量
  2         IDockableMapWindow m_pMapDockWindow = null;
  3         private IFramework m_pFramework = null;
  4         private ITocWindow m_pTocWindow = new TocWindow();
  5         private bool m_bCanceledExit = false;
  6         //private License m_pLicense = null;
  7         #endregion
  8 
  9         #region 构造函数和窗体事件函数
 10         public MainForm()
 11         {
 12             //ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
 13             ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
 14             //this.m_pLicense = System.ComponentModel.LicenseManager.Validate(typeof(MainForm), this);
 15             m_pMapDockWindow = new MapDockWindow();
 16             this.Controls.Add(m_pMapDockWindow as Control);
 17 
 18 
 19             InitializeComponent();
 20             this.Load += new EventHandler(MainForm_Load);
 21             this.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
 22             (m_pMapDockWindow as Control).Dock = DockStyle.Fill;
 23 
 24 
 25             #region 初始化框架
 26             this.m_pFramework = new FrameworkClass();
 27             this.m_pFramework.MdiForm = this;
 28             IBarManager pBarManager = new BarManagerClass();
 29             pBarManager.BarManager = this.barManager1;
 30             IDockManager pDockManager = new DockManagerClass();
 31             pDockManager.DockManager = this.barManager1;
 32             this.m_pFramework.BarManager = pBarManager;
 33             this.m_pFramework.DockManager = pDockManager;
 34             //(this.m_pFramework as ICommandLineManager).CommandLineWindow = this.m_frmCommandLine;
 35             #endregion
 36 
 37             #region 命令工具栏赋值
 38             //this.m_frmCommandLine.Framework = this.m_pFramework;
 39             //this.m_frmCommandLine.DockManager = this.dockPanel1;
 40             #endregion
 41 
 42             # region 加载TOC
 43             DockableTocControl ctrToc = new DockableTocControl();
 44             IContentsViewManager pContensViewManager = ctrToc as IContentsViewManager;
 45             IContentsView pContentsView = new DisplayWindow();
 46             pContensViewManager.AddContentsView(pContentsView);
 47             pContentsView = new DataSourceWindow();
 48             pContensViewManager.AddContentsView(pContentsView);
 49             pContentsView = new CatalogWindow();
 50             pContensViewManager.AddContentsView(pContentsView);
 51             pContentsView = new VisibleWindow();
 52             pContensViewManager.AddContentsView(pContentsView);
 53             pContentsView = new SelectionView();
 54             pContensViewManager.AddContentsView(pContentsView);
 55 
 56             pDockManager.DockWindow(ctrToc as IDockableWindow);
 57             IDockableWindow pDockableWindow = pDockManager.GetDockableWindow((ctrToc as IDockableWindow).ID);
 58             this.m_pTocWindow.Toc = pDockableWindow;
 59             this.m_pTocWindow.DockManager = this.barManager1;
 60             this.m_pFramework.OverviewWindow = pContensViewManager.OverviewWindow;
 61             this.m_pFramework.TocWindow = this.m_pTocWindow;
 62             #endregion
 63 
 64             #region 加载地图控件
 65             this.m_pFramework.DelayEvents(true);
 66             this.m_pFramework.Hook = this.m_pMapDockWindow.Hook;
 67             this.m_pFramework.ActiveMapControl = this.m_pMapDockWindow.ActiveMapControl;
 68 
 69             #endregion
 70             #region 加载命令窗体
 71 
 72             #endregion
 73 
 74             #region 符号库
 75             IStyleGallery pStyleGallery = new StyleGalleryClass();
 76 
 77             string sStyleFile = Application.StartupPath + @"\SimpleGIS.style";
 78             if (System.IO.File.Exists(sStyleFile))
 79             {
 80                 (pStyleGallery as IStyleGalleryStorage).AddFile(sStyleFile);
 81             }
 82             (pStyleGallery as IStyleGalleryStorage).TargetFile = sStyleFile;
 83             //if (System.IO.File.Exists(Application.StartupPath + @"\Civic.ServerStyle"))
 84             //{
 85             //    (pStyleGallery as IStyleGalleryStorage).AddFile(Application.StartupPath + @"\Civic.ServerStyle");
 86             //}
 87             this.m_pFramework.StyleGallery = pStyleGallery;
 88             #endregion
 89 
 90             #region 绑定图层显示控件和鹰眼图
 91             this.m_pTocWindow.ContentsViewManager.SetBuddyControl(this.m_pMapDockWindow.Hook, this.m_pFramework);
 92             IOverviewWindow pOverviewWindow = this.m_pTocWindow.ContentsViewManager.OverviewWindow;
 93             if (pOverviewWindow != null)
 94             {
 95                 pOverviewWindow.MainActiveView = this.m_pFramework.Application.ActiveView;
 96                 pOverviewWindow.StyleGallery = this.m_pFramework.Application.StyleGallery;
 97                 pOverviewWindow.Framework = this.m_pFramework;
 98             }
 99             #endregion
100 
101             #region 创建状态栏
102             StatusStrip ctrSta = new StatusStrip();
103             ctrSta.Dock = DockStyle.Bottom;
104             ToolStripStatusLabel lblToolTip = new ToolStripStatusLabel();
105             ctrSta.Items.Add(lblToolTip);
106             ToolStripStatusLabel lblMapPosition = new ToolStripStatusLabel();
107             lblMapPosition.Spring = true;
108             lblMapPosition.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
109             ctrSta.Items.Add(lblMapPosition);
110             this.Controls.Add(ctrSta);
111             IStatusBar pStatusBar = new StatusBarClass();
112             pStatusBar.StatusBarControl = ctrSta;
113             pStatusBar.BarMessageItem = lblToolTip;
114             pStatusBar.BarMousePositionItem = lblMapPosition;
115 
116             pBarManager.StatusBar = pStatusBar;
117 
118             #endregion
119 
120             #region 加载插件
121             string sMainFrameCommands = ConfigurationManager.AppSettings["PluginFile"];
122             pBarManager.CreateToolBar(Application.StartupPath + "\\" + sMainFrameCommands);
123             #endregion
124 
125             #region 绑定右键菜单控件
126             pOverviewWindow = this.m_pFramework.OverviewWindow;
127             if (pOverviewWindow is IControlContextMenu)
128             {
129                 pBarManager.RegisterControlWithPopupContext(pOverviewWindow as IControlContextMenu);
130                 IControlContextMenu2 pControlContextMenu = pOverviewWindow as IControlContextMenu2;
131                 pControlContextMenu.Clear();
132                 pControlContextMenu.AddItem("RefreshOverview", false);
133                 pControlContextMenu.AddItem("Overview", false);
134                 pControlContextMenu.AddItem("OverviewWindowProperty", true);
135             }
136             if (this.m_pTocWindow.ContentsViewManager != null)
137             {
138                 for (int i = 0; i < this.m_pTocWindow.ContentsViewManager.Count; i++)
139                 {
140                     IContentsView pView = this.m_pTocWindow.ContentsViewManager.ContentsView(i);
141                     if (pView is IControlContextMenu)
142                     {
143                         pBarManager.RegisterControlWithPopupContext(pView as IControlContextMenu);
144                     }
145                 }
146             }
147             #endregion
148         }
149 
150         private void MainForm_Load(object sender, EventArgs e)
151         {
152             try
153             {
154                 this.Text = ConfigurationManager.AppSettings["AppName"];
155             }
156             catch (Exception)
157             {
158             }
159             //初始化一个当前工具
160             ICommand pCommand = this.m_pFramework.FindCommand("SelectElementTool");
161             if (pCommand is ITool)
162             {
163                 this.m_pFramework.CurrentTool = pCommand as ITool;
164             }
165 
166             ////打开配置文件中指定的MXD文档
167             //string sMxd = ConfigurationManager.AppSettings["Mxd"];
168             //pCommand = this.m_pFramework.FindCommand("OpenDocumentCommand");
169             //if (pCommand != null && System.IO.File.Exists(sMxd))
170             //{
171             //    IMxdFile pMxdFile = pCommand as IMxdFile;
172             //    if (pMxdFile != null)
173             //    {
174             //        pMxdFile.MxdPath = sMxd;
175             //        pMxdFile.Open();
176             //    }
177             //}
178             this.m_pFramework.DelayEvents(false);
179         }
180 
181         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
182         {
183             ICommand pCommand = this.m_pFramework.FindCommand("ExitApplication");
184             if (pCommand != null)
185             {
186                 if (pCommand is IExitApplicationEvents)
187                 {
188                     (pCommand as IExitApplicationEvents).CancelExitApplicationEvent += new OnCancelExitApplicationEventHandler(MainForm_CancelExitApplicationEvent);
189                 }
190                 e.Cancel = this.m_bCanceledExit;
191             }
192         }
193 
194         void MainForm_CancelExitApplicationEvent(bool bCanceledExit)
195         {
196             this.m_bCanceledExit = bCanceledExit;
197         }
198         #endregion
199     }

功能配置:

基于AE的SimpleGIS框架的搭建_第8张图片

 

系统会自动检测配置功能

基于AE的SimpleGIS框架的搭建_第9张图片

 

 

你可能感兴趣的:(基于AE的SimpleGIS框架的搭建)