ArcObjects SDK开发 023 开发框架搭建-MainApp

MainApp定义了启动界面,主界面等。主界面的整体流程如下。

1、验证许可。

//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));
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章