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