arcgis engine c#實例開發(fā)教程63382_第1頁
arcgis engine c#實例開發(fā)教程63382_第2頁
arcgis engine c#實例開發(fā)教程63382_第3頁
arcgis engine c#實例開發(fā)教程63382_第4頁
arcgis engine c#實例開發(fā)教程63382_第5頁
已閱讀5頁,還剩77頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、?ArcGISEngine+C#實例開發(fā)教程? HYPERLINK :/ o 3SDN.Net 文章來源: HYPERLINK :/ 3SDN原創(chuàng)點擊數(shù): 14478更新時間:2021-5-12摘要:?ArcGIS Engine+C#實例開發(fā)教程?,面向 ArcGIS Engine以下簡稱AE開發(fā)初學(xué)者,本教程將幫助您進一步理解AE的體系結(jié)構(gòu)與開發(fā)方法,掌握根本的GIS桌面應(yīng)用程序的開發(fā)。 版權(quán)聲明: ?ArcGIS Engine+C#實例開發(fā)教程?為3SDN HYPERLINK :/ o 原創(chuàng)教程,版權(quán)所有。禁止商業(yè)用途轉(zhuǎn)載如需請聯(lián)系作者,非商業(yè)用途轉(zhuǎn)載請注明出處。教程采用C#語言,以VS2

2、005為開發(fā)工具。讀者對象: ArcGIS Engine以下簡稱AE開發(fā)初學(xué)者, 了解AE根本體系,了解C#根本語法,了解VS2005的根本使用方法。預(yù)期學(xué)習(xí)效果: 進一步理解AE的體系結(jié)構(gòu)與開發(fā)方法,掌握根本的GIS桌面應(yīng)用程序的開發(fā)。教程目錄: TOC o 1-3 h z u HYPERLINK l _Toc280290897 ?ArcGISEngine+C#實例開發(fā)教程? PAGEREF _Toc280290897 h 1 HYPERLINK l _Toc280290898 第一講:桌面GIS應(yīng)用程序框架的建立 PAGEREF _Toc280290898 h 2 HYPERLINK l

3、_Toc280290899 1、新建工程 PAGEREF _Toc280290899 h 3 HYPERLINK l _Toc280290900 2、添加控件 PAGEREF _Toc280290900 h 4 HYPERLINK l _Toc280290901 3、控件綁定 PAGEREF _Toc280290901 h 5 HYPERLINK l _Toc280290902 4、添加工具 PAGEREF _Toc280290902 h 6 HYPERLINK l _Toc280290903 5、編譯運行 PAGEREF _Toc280290903 h 7 HYPERLINK l _Toc2

4、80290904 第二講 菜單的添加及其實現(xiàn) PAGEREF _Toc280290904 h 7 HYPERLINK l _Toc280290905 1、 添加菜單 PAGEREF _Toc280290905 h 7 HYPERLINK l _Toc280290906 2、 實現(xiàn)相關(guān)菜單 PAGEREF _Toc280290906 h 8 HYPERLINK l _Toc280290907 3、 編譯運行 PAGEREF _Toc280290907 h 12 HYPERLINK l _Toc280290908 第三講 MapControl與PageLayoutControl同步 PAGEREF

5、 _Toc280290908 h 13 HYPERLINK l _Toc280290909 1、新建同步類ControlsSynchronizer PAGEREF _Toc280290909 h 13 HYPERLINK l _Toc280290910 2、新建Maps類 PAGEREF _Toc280290910 h 22 HYPERLINK l _Toc280290911 3、新建翻開文檔類OpenNewMapDocument PAGEREF _Toc280290911 h 25 HYPERLINK l _Toc280290912 4、兩種視圖的同步 PAGEREF _Toc2802909

6、12 h 27 HYPERLINK l _Toc280290913 5、編譯運行 PAGEREF _Toc280290913 h 30 HYPERLINK l _Toc280290914 第四講 狀態(tài)欄信息的添加與實現(xiàn) PAGEREF _Toc280290914 h 30 HYPERLINK l _Toc280290915 1、 添加狀態(tài)欄工程 PAGEREF _Toc280290915 h 31 HYPERLINK l _Toc280290916 2、 顯示當前所用工具信息 PAGEREF _Toc280290916 h 32 HYPERLINK l _Toc280290917 3、 顯示當

7、前比例尺 PAGEREF _Toc280290917 h 33 HYPERLINK l _Toc280290918 4、 顯示當前坐標 PAGEREF _Toc280290918 h 34 HYPERLINK l _Toc280290919 5、 編譯運行 PAGEREF _Toc280290919 h 36 HYPERLINK l _Toc280290920 第五講 鷹眼的實現(xiàn) PAGEREF _Toc280290920 h 36 HYPERLINK l _Toc280290921 1 、添加鷹眼控件 PAGEREF _Toc280290921 h 38 HYPERLINK l _Toc28

8、0290922 2 、鷹眼的實現(xiàn) PAGEREF _Toc280290922 h 41 HYPERLINK l _Toc280290923 第六講 右鍵菜單添加與實現(xiàn) PAGEREF _Toc280290923 h 46 HYPERLINK l _Toc280290924 1、創(chuàng)立右鍵菜單 PAGEREF _Toc280290924 h 46 HYPERLINK l _Toc280290925 2、添加菜單項 PAGEREF _Toc280290925 h 47 HYPERLINK l _Toc280290926 3、彈出右鍵菜單 PAGEREF _Toc280290926 h 51 HYPE

9、RLINK l _Toc280290927 4、編譯運行 PAGEREF _Toc280290927 h 52 HYPERLINK l _Toc280290928 第六講:教程Bug及解決方法 PAGEREF _Toc280290928 h 52 HYPERLINK l _Toc280290929 到第六講為止已經(jīng)發(fā)現(xiàn)的教程Bug及解決方法如下: PAGEREF _Toc280290929 h 52 HYPERLINK l _Toc280290930 目前已經(jīng)發(fā)現(xiàn)的優(yōu)化方案如下: PAGEREF _Toc280290930 h 53 HYPERLINK l _Toc280290931 第七講

10、圖層符號選擇器的實現(xiàn)1 PAGEREF _Toc280290931 h 53 HYPERLINK l _Toc280290932 1、直接調(diào)用ArcMap中的符號選擇器 PAGEREF _Toc280290932 h 56 HYPERLINK l _Toc280290933 2、自定義符號選擇器 PAGEREF _Toc280290933 h 58 HYPERLINK l _Toc280290934 2.1 新建符號選擇器窗體 PAGEREF _Toc280290934 h 58 HYPERLINK l _Toc280290935 2.2 設(shè)置控件屬性 PAGEREF _Toc28029093

11、5 h 59 HYPERLINK l _Toc280290936 2.3 添加引用 PAGEREF _Toc280290936 h 60 HYPERLINK l _Toc280290937 2.4 初始化 PAGEREF _Toc280290937 h 60 HYPERLINK l _Toc280290938 2.5 調(diào)用自定義符號選擇器 PAGEREF _Toc280290938 h 65 HYPERLINK l _Toc280290939 2.6 符號參數(shù)調(diào)整 PAGEREF _Toc280290939 h 67 HYPERLINK l _Toc280290940 2.7 添加更多符號菜單

12、 PAGEREF _Toc280290940 h 72 HYPERLINK l _Toc280290941 2.8 編譯運行 PAGEREF _Toc280290941 h 74 HYPERLINK l _Toc280290942 第八講屬性數(shù)據(jù)表的查詢顯示 PAGEREF _Toc280290942 h 74 HYPERLINK l _Toc280290943 1.創(chuàng)立屬性表窗體 PAGEREF _Toc280290943 h 75 HYPERLINK l _Toc280290944 2.創(chuàng)立空DataTable PAGEREF _Toc280290944 h 76 HYPERLINK l

13、_Toc280290945 3.裝載DataTable數(shù)據(jù) PAGEREF _Toc280290945 h 80 HYPERLINK l _Toc280290946 4.綁定DataTable到DataGridView PAGEREF _Toc280290946 h 83 HYPERLINK l _Toc280290947 5.調(diào)用屬性表窗體 PAGEREF _Toc280290947 h 85 HYPERLINK l _Toc280290948 6.編譯運行 PAGEREF _Toc280290948 h 88第一講:桌面GIS應(yīng)用程序框架的建立本講主要是使用MapControl、PageL

14、ayoutControl、ToolbarControl、TOCControl四個控件建立起根本的桌面GIS應(yīng)用程序框架。最終成果預(yù)覽如下:1、新建工程啟動VS2005,選擇“文件|新建|工程,在工程類型中選擇Visual C#,再選擇Windows應(yīng)用程序模板,輸入名稱“3sdnMap,點擊確定。在解決方案管理器中將“Form1.cs重命名為“3sdnMap.cs,在設(shè)計視圖中,選中窗體,將其屬性中的“Text改為“3sdnMap。2、添加控件選擇工具箱中的“菜單和工具欄|MenuStrip,將其拖入窗體。選擇工具箱中的“ArcGIS Windows Forms節(jié),將“ToolbarContr

15、ol控件拖入窗體,并將其屬性中的Dock設(shè)置為Top。選擇工具箱中的“菜單和工具欄|StatusStrip,將其拖入到窗體。選擇工具箱中的“容器|SplitContainer容器拖入窗體,并將其屬性中的Dock設(shè)置為Fill。將TabControl控件拖入Panel1,將Alignment屬性設(shè)置為Bottom,Dock屬性設(shè)置為Fill。點擊TabPages屬性右邊的按鈕,彈出TabPage集合編輯器,將tabPage1的Name設(shè)置為tabPageLayer,Text設(shè)置為圖層,將tabPage2的Name設(shè)置為tabPageProperty,Text設(shè)置為屬性。如下所示。選擇“圖層選項卡

16、,拖入TOCControl控件,設(shè)置Dock屬性為Fill。選擇“屬性選項卡,拖入DataGridView控件,設(shè)置Dock屬性為Fill。拖入TabControl控件到Panel2,設(shè)置Dock屬性為Fill。并上述類似的方法,將兩個選項卡的Name和Text分別設(shè)置為:tabPageMap、地圖,tabPageLayout,制版。選擇“地圖選項卡,拖入MapControl控件,設(shè)置Dock屬性為Fill。選擇“制版選項卡,拖入PageLayoutControl控件,設(shè)置Dock屬性為Fill。最后將LicenseControl控件拖入到窗體的任意地方。按F5編譯運行,可以看到剛剛布局好的程

17、序界面了。3、控件綁定通過以上步驟添加的控件還只是單獨存在,而我們的程序需要各控件間協(xié)同工作,因此要進行控件綁定。分別右擊ToolbarControl、TOCControl控件,將Buddy設(shè)置為axMapControl1,如下列圖所示。這樣,工具條和圖層控件就與地圖控件關(guān)聯(lián)了。4、添加工具此時,工具條中還沒有任何工具,添加的方法也很簡單。右擊ToolbarControl,選擇“屬性|Items,點擊Add,選擇Commands選項卡中的Generic,雙擊Open、SaveAs、Redo、Undo即可將相應(yīng)工具添加到工具條。常見的工具有:Map Navigation中的導(dǎo)航工具,Map In

18、quiry中的查詢工具,F(xiàn)eature Selection中的選擇工具,你可以根據(jù)需要酌情添加工具。5、編譯運行按F5即可編譯運行程序,至此桌面GIS應(yīng)用程序框架根本框架已經(jīng)搭建好了,你可以通過工具條的工具翻開地圖文檔,瀏覽地圖了,效果如開篇所示.ticle/1555.htm o 第二講 菜單的添加及其實現(xiàn)在上一講中,我們實現(xiàn)了應(yīng)用程序根本框架,其中有個小錯誤,在此先跟大家說明下。在“屬性選項卡中,我們當時添加的是 DataGridView 控件,這個控件是用來顯示數(shù)據(jù)表的,而專門用于屬性的查詢和設(shè)置的控件是 PropertyGrid 控件。因此請你刪除“屬性選項卡中的 DataGridVie

19、w 控件,再把位于“工具箱 | 所有 Windows 窗體 |PropertyGrid 如果沒有,右擊選擇“選擇項以添加此控件控件拖到該選項卡。 在這一講中,主要講解菜單的添加和實現(xiàn)。 1、 添加菜單 在設(shè)計視圖中,單擊菜單欄,會出現(xiàn)“請在此處鍵入的提示,單擊提示就可以鍵入菜單名稱,如“文件,再單擊“文件,即可輸入其下拉子菜單,如下所示: Tips : 每創(chuàng)立一個菜單,請在其屬性面板中設(shè)置 Name 屬性,而且不要為中文,因此 Name 值將是此菜單響應(yīng)函數(shù)的函數(shù)名的一局部,帶中文的函數(shù)名,總是不好吧。 本講中,我們將添加新建 New 、翻開 Open 、添加數(shù)據(jù) AddData 、保存 Sa

20、ve 、另存為 SaveAs 、退出 Exit 這些菜單,內(nèi)為相應(yīng)的 Name 屬性值。 Tips: 你可以在屬性面板中的 Text 屬性中,把菜單名設(shè)置為中英文形式,如“翻開 O pen ,帶下劃線的 O 表示此項菜單的快捷鍵是字母 O ,設(shè)置方法是在相應(yīng)字母前加上“ & 字符,如“翻開 &Open 。但這種快捷鍵只在翻開此下拉菜單時才有效,即當你單擊“文件菜單彈出下拉菜單時,按下字母 O 就可以定位到“翻開菜單。 還有一種在程序運行時都有效的全局快捷鍵,可以在屬性面板中的“ ShortCutKeys 中設(shè)置。 你還可以在屬性面板中的 Image 屬性中設(shè)置你喜歡的菜單圖標。單擊 Image

21、 那一行右邊的按鈕,彈出如下菜單。選擇“工程資源文件,再單擊導(dǎo)入就可以選擇你的圖標了。 最終效果如下所示。 注意,在解決方案面板中,選中剛剛添加的所有圖標,在其屬性面板中將生成操作設(shè)置為“嵌入的資源,這一點很重要! 2、 實現(xiàn)相關(guān)菜單 首先定義指針寫在 public partial class Form1 : Form 下面即可: private ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = null; private ESRI.ArcGIS.Controls.IPageLayoutControl2 m_pageLayoutControl =

22、 null; private IMapDocument pMapDocument; 假設(shè)以上指針無效,請?zhí)砑右韵乱茫?using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; 在設(shè)計視圖中的屬性面板中,選擇 Form1 ,即主窗體,單擊事件按鈕閃電形狀的那個按鈕,打到“ Load 事件并雙擊,添加此事件。 在 Form1_

23、Load 函數(shù)中初始化這些指針: / 取得 MapControl 和 PageLayoutControl 的引用 m_mapControl = (IMapControl3)this.axMapControl1.Object; m_pageLayoutControl = (IPageLayoutControl2)this.axPageLayoutControl1.Object; 依次雙擊每個菜單項,添加菜單響應(yīng)函數(shù)。實現(xiàn)代碼如下: / / 新建地圖命令 / / / private void New_Click(object sender, EventArgs e) / 本命令涉及到 MapCon

24、trol 和 PageLayoutControl 同步問題,將在下一講中實現(xiàn) / / 翻開地圖文檔 Mxd 命令 / / / private void Open_Click(object sender, EventArgs e) / 本命令涉及到 MapControl 和 PageLayoutControl 同步問題,將在下一講中實現(xiàn) / / 添加數(shù)據(jù)命令 / / / private void AddData_Click(object sender, EventArgs e) int currentLayerCount = this.axMapControl1.LayerCount; ICom

25、mand pCommand = new ControlsAddDataCommandClass(); pCommand.OnCreate(this.axMapControl1.Object); pCommand.OnClick(); / / 保存地圖文檔命令 / / / private void Save_Click(object sender, EventArgs e) / 首先確認當前地圖文檔是否有效 &m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename) / 創(chuàng)立一個新的地圖文檔實例 IMapDocument map

26、Doc = new MapDocumentClass(); / 翻開當前地圖文檔 mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty); / 用 PageLayout 中的文檔替換當前文檔中的 PageLayout 局部 mapDoc.ReplaceContents(IMxdContents)m_pageLayoutControl.PageLayout); / 保存地圖文檔 mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); / / 另存為地圖文檔命

27、令 / / / private void SaveAs_Click(object sender, EventArgs e) / 調(diào)用另存為命令 ICommand command = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_controlsSynchronizer.ActiveControl); command.OnClick(); / / 退出程序 / / / private void Exit_Click(object sender, EventArgs e) Application.Exit(); 3、 編譯運行 按

28、F5 編譯運行程序。也許你會發(fā)現(xiàn),菜單命令的實現(xiàn)方式都是類型的。沒錯,在 AE9.2 中,內(nèi)置了許多常用的 Command 和 Tool ,如 ControlsAddDataCommandClass 、 ControlsMapZoomInToolClass 、 ControlsMapPanToolClass 等等,這些內(nèi)置對象在 ESRI.ArcGIS.Controls 命名空間中,你可以對象瀏覽器中查看。而且這些內(nèi)置對象的調(diào)用方式都類似,如下所示: / 定義 ICommand command = new ControlsSaveAsDocCommandClass(); / 創(chuàng)立 comman

29、d.OnCreate(m_controlsSynchronizer.ActiveControl); / 調(diào)用 command.OnClick(); 希望你可以舉一反三,去實現(xiàn)更多的你想要的功能。 HYPERLINK :/ o 第三講 MapControl與PageLayoutControl同步在ArcMap中,能夠很方面地進行MapView和Layout View兩種視圖的切換,而且二者之間的數(shù)據(jù)是同步顯示的。關(guān)于兩種視圖同步的實現(xiàn)方法有多種,可以使用ObjectCopy對象進行數(shù)據(jù)硬拷貝,而比擬簡單的方法莫過于二者共享一份地圖了,這也是最常用的方法。1、 新建同步類ControlsSynch

30、ronizer在解決方案面板中右擊工程名,選擇“添加|類,在類別中選擇“Visual C#工程項,在模板中選擇“類,輸入類名“ControlsSynchronizer.cs,將以下代碼覆蓋自動生成的代碼:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.IO;using System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem;u

31、sing ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.SystemUI;namespace _sdnMap / / This class is used to synchronize a gven PageLayoutControl and a MapControl. / When initialized, the user must pass the reference of these control to the class, bind / the control together by calling B

32、indControls which in turn sets a joined Map referenced / by both control; and set all the buddy controls joined between these two controls. / When alternating between the MapControl and PageLayoutControl, you should activate the visible control / and deactivate the other by calling ActivateXXX. / Th

33、is calss is limited to a situation where the controls are not simultaneously visible. / public class ControlsSynchronizer #region class members private IMapControl3 m_mapControl = null; private IPageLayoutControl2 m_pageLayoutControl = null; private ITool m_mapActiveTool = null; private ITool m_page

34、LayoutActiveTool = null; private bool m_IsMapCtrlactive = true; private ArrayList m_frameworkControls = null; #endregion#region constructor/ / 默認構(gòu)造函數(shù) / public ControlsSynchronizer() /初始化ArrayList m_frameworkControls = new ArrayList(); / / 構(gòu)造函數(shù) / / / public ControlsSynchronizer(IMapControl3 mapContro

35、l, IPageLayoutControl2 pageLayoutControl) : this() /為類成員賦值 m_mapControl = mapControl; m_pageLayoutControl = pageLayoutControl; #endregion #region properties / / 取得或設(shè)置MapControl / public IMapControl3 MapControl get return m_mapControl; set m_mapControl = value; / / 取得或設(shè)置PageLayoutControl / public IPa

36、geLayoutControl2 PageLayoutControl get return m_pageLayoutControl; set m_pageLayoutControl = value; / / 取得當前ActiveView的類型 / public string ActiveViewType get if (m_IsMapCtrlactive) return MapControl; else return PageLayoutControl; / / 取得當前活動的Control / public object ActiveControl get if (m_mapControl

37、= null | m_pageLayoutControl = null) throw new Exception(ControlsSynchronizer:ActiveControl:rnEither MapControl or PageLayoutControl are not initialized!); if (m_IsMapCtrlactive) return m_mapControl.Object; else return m_pageLayoutControl.Object; #endregion#region Methods / / 激活MapControl并解除the Pagl

38、eLayoutControl / public void ActivateMap() try if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ActivateMap:rnEither MapControl or PageLayoutControl are not initialized!); /緩存當前PageLayout的CurrentToolif(m_pageLayoutControl.CurrentTool!=null)m_pageLayoutAc

39、tiveTool=m_pageLayoutControl.CurrentTool; /解除PagleLayout m_pageLayoutControl.ActiveView.Deactivate(); /激活MapControl m_mapControl.ActiveView.Activate(m_mapControl.hWnd); /將之前MapControl最后使用的tool,作為活動的tool,賦給MapControl的CurrentTool if (m_mapActiveTool != null) m_mapControl.CurrentTool = m_mapActiveTool;

40、 m_IsMapCtrlactive = true;tBuddies(m_mapControl.Object); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:ActivateMap:rn0, ex.Message); / / 激活PagleLayoutControl并減活MapCotrol / public void ActivatePageLayout() try if (m_pageLayoutControl = null | m_mapControl = null) throw n

41、ew Exception(ControlsSynchronizer:ActivatePageLayout:rnEither MapControl or PageLayoutControl are not initialized!); /緩存當前MapControl的CurrentTool if (m_mapControl.CurrentTool != null) m_mapActiveTool = m_mapControl.CurrentTool; /解除MapControl m_mapControl.ActiveView.Deactivate(); /激活PageLayoutControl

42、m_pageLayoutControl.ActiveView.Activate(m_pageLayoutControl.hWnd); /將之前PageLayoutControl最后使用的tool,作為活動的tool,賦給PageLayoutControl的CurrentTool if (m_pageLayoutActiveTool != null) m_pageLayoutControl.CurrentTool = m_pageLayoutActiveTool; m_IsMapCtrlactive = false; /為每一個的framework controls,設(shè)置Buddy contro

43、l為PageLayoutControl this.SetBuddies(m_pageLayoutControl.Object); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:ActivatePageLayout:rn0, ex.Message); / / 給予一個地圖, 置換PageLayoutControl和MapControl的focus map / / public void ReplaceMap(IMap newMap) if (newMap = null) throw new

44、Exception(ControlsSynchronizer:ReplaceMap:rnNew map for replacement is not initialized!); if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ReplaceMap:rnEither MapControl or PageLayoutControl are not initialized!); /create a new instance of IMaps collecti

45、on which is needed by the PageLayout /創(chuàng)立一個PageLayout需要用到的,新的IMaps collection的實例 IMaps maps = new Maps(); /add the new map to the Maps collection /把新的地圖加到Maps collection里頭去 maps.Add(newMap); bool bIsMapActive = m_IsMapCtrlactive; /call replace map on the PageLayout in order to replace the focus map /

46、we must call ActivatePageLayout, since it is the control we call ReplaceMaps /調(diào)用PageLayout的replace map來置換focus map /我們必須調(diào)用ActivatePageLayout,因為它是那個我們可以調(diào)用ReplaceMaps的Control this.ActivatePageLayout(); m_pageLayoutControl.PageLayout.ReplaceMaps(maps); /assign the new map to the MapControl /把新的地圖賦給MapC

47、ontrol m_mapControl.Map = newMap; /reset the active tools /重設(shè)active tools m_pageLayoutActiveTool = null; m_mapActiveTool = null; /make sure that the last active control is activated /確認之前活動的control被激活 if (bIsMapActive) this.ActivateMap(); m_mapControl.ActiveView.Refresh(); else this.ActivatePageLayo

48、ut(); m_pageLayoutControl.ActiveView.Refresh(); / / bind the MapControl and PageLayoutControl together by assigning a new joint focus map / 指定共同的Map來把MapControl和PageLayoutControl綁在一起 / / / / true if the MapControl supposed to be activated first,如果MapControl被首先激活,那么為true public void BindControls(IMap

49、Control3 mapControl, IPageLayoutControl2 pageLayoutControl, bool activateMapFirst) if (mapControl = null | pageLayoutControl = null) throw new Exception(ControlsSynchronizer:BindControls:rnEither MapControl or PageLayoutControl are not initialized!); m_mapControl = MapControl; m_pageLayoutControl =

50、pageLayoutControl; this.BindControls(activateMapFirst); / / bind the MapControl and PageLayoutControl together by assigning a new joint focus map / 指定共同的Map來把MapControl和PageLayoutControl綁在一起 / / true if the MapControl supposed to be activated first,如果MapControl被首先激活,那么為true public void BindControls(

51、bool activateMapFirst) if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:BindControls:rnEither MapControl or PageLayoutControl are not initialized!); /create a new instance of IMap /創(chuàng)造IMap的一個實例 IMap newMap = new MapClass(); newMap.Name = Map; /create a ne

52、w instance of IMaps collection which is needed by the PageLayout /創(chuàng)造一個新的IMaps collection的實例,這是PageLayout所需要的 IMaps maps = new Maps(); /add the new Map instance to the Maps collection /把新的Map實例賦給Maps collection maps.Add(newMap); /call replace map on the PageLayout in order to replace the focus map /調(diào)

53、用PageLayout的replace map來置換focus map m_pageLayoutControl.PageLayout.ReplaceMaps(maps); /assign the new map to the MapControl /把新的map賦給MapControl m_mapControl.Map = newMap; /reset the active tools /重設(shè)active tools m_pageLayoutActiveTool = null; m_mapActiveTool = null; /make sure that the last active co

54、ntrol is activated /確定最后活動的control被激活 if (activateMapFirst) this.ActivateMap(); else this.ActivatePageLayout(); / /by passing the applications toolbars and TOC to the synchronization class, it saves you the /management of the buddy control each time the active control changes. This method ads the fr

55、amework /control to an array; once the active control changes, the class iterates through the array and /calles SetBuddyControl on each of the stored framework control. / / public void AddFrameworkControl(object control) if (control = null) throw new Exception(ControlsSynchronizer:AddFrameworkContro

56、l:rnAdded control is not initialized!); m_frameworkControls.Add(control); / / Remove a framework control from the managed list of controls / / public void RemoveFrameworkControl(object control) if (control = null) throw new Exception(ControlsSynchronizer:RemoveFrameworkControl:rnControl to be remove

57、d is not initialized!); m_frameworkControls.Remove(control); / / Remove a framework control from the managed list of controls by specifying its index in the list / / public void RemoveFrameworkControlAt(int index) if (m_frameworkControls.Count index) throw new Exception(ControlsSynchronizer:RemoveFr

58、ameworkControlAt:rnIndex is out of range!); m_frameworkControls.RemoveAt(index); / / when the active control changes, the class iterates through the array of the framework controls / and calles SetBuddyControl on each of the controls. / / the active control private void SetBuddies(object buddy) try

59、if (buddy = null) throw new Exception(ControlsSynchronizer:SetBuddies:rnTarget Buddy Control is not initialized!); foreach (object obj in m_frameworkControls) if (obj is IToolbarControl) (IToolbarControl)obj).SetBuddyControl(buddy); else if (obj is ITOCControl) (ITOCControl)obj).SetBuddyControl(buddy); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:SetBuddies:rn0, ex.Message); #endregion 摘要:在ArcMap中,能夠很方面地進行MapView和Layout View兩種視圖的切換,而且二者之間的數(shù)據(jù)是同步顯示的。關(guān)于兩種視圖同步的實現(xiàn)方法有多種,可以使用ObjectCopy對象進行數(shù)據(jù)硬拷貝,而比擬簡單的方法莫過于二者共享一份地圖了,這也是最常用的方法。 2、 新建Maps類在同步類中,要用到Maps類,用于管理地圖對象。與新建同步類C

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論