ArcObjects SDK 023 开发框架搭建-MainApp
MainApp定义了启动界面,主界面等。主界面的整体流程如下。
//ArcGIS许可验证 RuntimeManager.Bind(ProductCode.Desktop); var myAoLicenseCheck = new AoLicenseCheck { ProductCode = esriLicenseProductCode.esriLicenseProductCodeAdvanced }; string myMessage = myAoLicenseCheck.Check();
2、初始化AxMapControl以及AxPageLayoutControl(如有需要),然后初始化MapApplication或者继承该类的子类。
//初始化地图控件 AxMapControl myAxMapControl = new AxMapControl(); myAxMapControl.BeginInit(); this.UI_Map_WindowsFormsHost.Child = myAxMapControl; myAxMapControl.EndInit(); myAxMapControl.BackColor = System.Drawing.Color.White; myAxMapControl.BorderStyle = esriControlsBorderStyle.esriNoBorder; myAxMapControl.ShowScrollbars = false; var myAxPageLayoutControl = new AxPageLayoutControl { BackColor = System.Drawing.Color.White }; myAxPageLayoutControl.BeginInit(); this.UI_PageLayout_WindowsFormsHost.Child = myAxPageLayoutControl; myAxPageLayoutControl.EndInit(); myAxPageLayoutControl.BackColor = System.Drawing.Color.White; myAxPageLayoutControl.BorderStyle = esriControlsBorderStyle.esriNoBorder; this._AxTOCControlExUI = new AxTocControlExUI(); this.UI_AxTOCControlExUI_Border.Child = this._AxTOCControlExUI; this._AxTOCControlExUI.SetTocBuddy(myAxMapControl.Object); //初始化 Application this._MapApplication = new MapApplication(myAxMapControl, myAxPageLayoutControl); this._AxTOCControlExUI.BindApplication(this._MapApplication); this._MapApplication.MainWindow = this;
3、注册Tab也切换事件
Tab也切换时,要根据切换情况激活MapControl或者PageLayoutControl。
/// <summary> /// 当主视图的Tab页切换后 触发执行的函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DXTabControl_SelectionChanged(object sender, TabControlSelectionChangedEventArgs e) { if (this._MapApplication == null) { return; } DXTabControl myTabControl = sender as DXTabControl; if (myTabControl.SelectedIndex == 0) { this._MapApplication.ActivePattern = MapActivePattern.Map; this._AxTOCControlExUI.SetTocBuddy(this._MapApplication.MapControl); this._MapApplication.CrruteTool = this._MapApplication.MapPanTool; } else if (myTabControl.SelectedIndex == 1) { this._MapApplication.ActivePattern = MapActivePattern.PageLayout; this._AxTOCControlExUI.SetTocBuddy(this._MapApplication.PageLayoutControl); this._MapApplication.CrruteTool = this._MapApplication.PagePanTool; } else if (myTabControl.SelectedIndex == 2) { this._MapApplication.ActivePattern = MapActivePattern.None; } }
4、在菜单和工具栏等位置堆Coomand和Tool,如下图所示。
//初始化菜单 BarSubItem myBarSubItem = null; myBarSubItem = new BarSubItem() { Name = "File" }; myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.NewMapDocCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarItemLinkSeparator()); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.OpenMxdCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.AddDataCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarItemLinkSeparator()); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.SaveMxdCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.SaveAsMxdCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.ViewExportPicCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarItemLinkSeparator()); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.Files.ExitAppCommand(this._MapApplication))); this.UI_MainMenu_Bar.Items.Add(myBarSubItem); myBarSubItem = new BarSubItem() { Name = "Deploy" }; myBarSubItem.Items.Add(new BarButtonItemCommandUI(new DeployUI.Fishnets.FishnetCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new DeployUI.Drainages.DraExtSCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new DeployUI.Slopes.SlopeCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarItemLinkSeparator()); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new DeployUI.PointDeploys.PointDeployCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new DeployUI.PointEncodes.PointEncodeCommand(this._MapApplication))); myBarSubItem.Items.Add(new BarItemLinkSeparator()); myBarSubItem.Items.Add(new BarButtonItemCommandUI(new SaudiDeployUI.SaudiDeployCommand(this._MapApplication))); this.UI_MainMenu_Bar.Items.Add(myBarSubItem); //初始化工具栏 this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.MapZoomInTool(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.MapTools.MapZoomOutTool(this._MapApplication))); FrameworkUI.MapTools.MapPanTool myMapPanTool = new FrameworkUI.MapTools.MapPanTool(this._MapApplication); this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(myMapPanTool)); this._MapApplication.MapPanTool = myMapPanTool; this._MapApplication.CrruteTool = myMapPanTool; this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapFullExtentCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomInFixedCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomOutFixedCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomBackCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.MapTools.MapZoomForwardCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new AxMapScaleBarEditItem(this._MapApplication)); this.UI_Tool_Bar.Items.Add(new BarItemLinkSeparator()); this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.PageTools.PageZoomInTool(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(new FrameworkUI.PageTools.PageZoomOutTool(this._MapApplication))); FrameworkUI.PageTools.PagePanTool myPagePanTool = new FrameworkUI.PageTools.PagePanTool(this._MapApplication); this.UI_Tool_Bar.Items.Add(new BarCheckItemCommandUI(myPagePanTool)); this._MapApplication.PagePanTool = myPagePanTool; this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoomWholePageCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoom100PercentCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoomInFixedCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoomOutFixedCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoomBackCommand(this._MapApplication))); this.UI_Tool_Bar.Items.Add(new BarButtonItemCommandUI(new FrameworkUI.PageTools.PageZoomForwardCommand(this._MapApplication))); //地图右键菜单 this._AxTOCControlExUI.MapContextMenu = new ContextMenuStripTocContextMenu(); this._AxTOCControlExUI.MapContextMenu.AddCommand(new FrameworkUI.Maps.MapSetSpatialReferenceCommand(this._MapApplication)); this._AxTOCControlExUI.MapContextMenu.AddCommand(new FrameworkUI.Maps.MapClearLayerCommand(this._MapApplication)); //图层右键菜单 this._AxTOCControlExUI.LayerContextMenu = new ContextMenuStripTocContextMenu(); this._AxTOCControlExUI.LayerContextMenu.AddCommand(new FrameworkUI.Layers.LayerZoomToCommand(this._MapApplication)); this._AxTOCControlExUI.LayerContextMenu.AddCommand(new FrameworkUI.Layers.TableCommand(this._MapApplication)); this._AxTOCControlExUI.LayerContextMenu.AddCommand(new FrameworkUI.Layers.LayerPropertyCommand(this._MapApplication)); this._AxTOCControlExUI.LayerContextMenu.AddCommand(new FrameworkUI.Layers.LayerRemoveCommand(this._MapApplication)); //添加显示坐标的状态栏 this.UI_StatusBar.ItemLinks.Add(new AxCoordinateBarEditItem(this._MapApplication));
分类:
ArcObjects SDK
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理