![ArcGISEngineC#實例開發(fā)教程_第1頁](http://file4.renrendoc.com/view/27a0d72006025c27d7ce3fd57be3b344/27a0d72006025c27d7ce3fd57be3b3441.gif)
![ArcGISEngineC#實例開發(fā)教程_第2頁](http://file4.renrendoc.com/view/27a0d72006025c27d7ce3fd57be3b344/27a0d72006025c27d7ce3fd57be3b3442.gif)
![ArcGISEngineC#實例開發(fā)教程_第3頁](http://file4.renrendoc.com/view/27a0d72006025c27d7ce3fd57be3b344/27a0d72006025c27d7ce3fd57be3b3443.gif)
![ArcGISEngineC#實例開發(fā)教程_第4頁](http://file4.renrendoc.com/view/27a0d72006025c27d7ce3fd57be3b344/27a0d72006025c27d7ce3fd57be3b3444.gif)
![ArcGISEngineC#實例開發(fā)教程_第5頁](http://file4.renrendoc.com/view/27a0d72006025c27d7ce3fd57be3b344/27a0d72006025c27d7ce3fd57be3b3445.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
《ArcGISEngine+C#實例開發(fā)教程》
作者:3SDN.Net文章來源:3SDN原創(chuàng)點擊數(shù):14478更新時間:2009-5-12
摘要:《ArcGISEngine+C#實例開發(fā)教程》,面向ArcGISEngine(以下簡稱AE)開發(fā)初
學(xué)者,本教程將幫助您進一步理解AE的體系結(jié)構(gòu)與開發(fā)方法,掌握基本的GIS桌面應(yīng)用程
序的開發(fā)。
版權(quán)聲明:
《ArcGISEngine+。實例開發(fā)教程》為3SDN(http://ww)原創(chuàng)教程,版
權(quán)所有。禁止商業(yè)用途轉(zhuǎn)載(如需請聯(lián)系作者),非商業(yè)用途轉(zhuǎn)載請注明出處。教程采用
C#語言,以VS2005為開發(fā)工具。
讀者對象:
ArcGISEngine(以下簡稱AE)開發(fā)初學(xué)者,了解AE基本體系,了解C#基本語法,
了解VS2005的基本使用方法。
預(yù)期學(xué)習(xí)效果:
進一步理解AE的體系結(jié)構(gòu)與開發(fā)方法,掌握基本的GIS桌面應(yīng)用程序的開發(fā)。
教程目錄:
《ArcGISEngine+C#實例開發(fā)教程》1
第一講:桌面GIS應(yīng)用程序框架的建立2
1、新建項目3
2、添加控件4
3、控件綁定5
4、添加工具6
5、編譯運行7
第二講菜單的添加及其實現(xiàn)7
1、添加菜單7
2、實現(xiàn)相關(guān)菜單8
3、編譯運行10
第三講MapControl與PageLayoutControl同步11
1、新建同步類ControlsSynchronizer11
2、新建Maps類17
3、新建打開文檔類OpenNewMapDocument20
4、兩種視圖的同步21
5、編譯運行24
第四講狀態(tài)欄信息的添加與實現(xiàn)25
1、添加狀態(tài)欄項目25
2、顯示當前所用工具信息26
3、顯示當前比例尺27
4、顯示當前坐標27
5、編譯運行30
第五講鷹眼的實現(xiàn)30
1、添加鷹眼控件31
2、鷹眼的實現(xiàn)34
第六講右鍵菜單添加與實現(xiàn)39
1、創(chuàng)建右鍵菜單39
2、添加菜單項40
3、彈出右鍵菜單44
4、編譯運行45
第六講:教程Bug及解決方法45
到第六講為止已經(jīng)發(fā)現(xiàn)的教程Bug及解決方法如下:45
目前已經(jīng)發(fā)現(xiàn)的優(yōu)化方案如下:46
第七講圖層符號選擇器的實現(xiàn)146
1、直接調(diào)用ArcMap中的符號選擇器49
2、自定義符號選擇器51
2.1新建符號選擇器窗體51
2.2設(shè)置控件屬性52
2.3添加引用53
2.4初始化53
2.5調(diào)用自定義符號選擇器58
2.6符號參數(shù)調(diào)整60
2.7添加更多符號菜單65
2.8編譯運行67
第八講屬性數(shù)據(jù)表的查詢顯示67
1.創(chuàng)建屬性表窗體68
2.創(chuàng)建空DataTable69
3.裝載DataTable數(shù)據(jù)73
4.綁定DataTable到DataGridView76
5.調(diào)用屬性表窗體78
6.編譯運行81
第一講:桌面GIS應(yīng)用程序框架的建立
本講主要是使用MapControKPageLayoutControLToolbarControKTCXSControl四個
控件建立起基本的桌面GIS應(yīng)用程序框架。最終成果預(yù)覽如下:
1、新建項目
啟動VS2005,選擇“文件|新建|項目”,在項目類型中選擇VisualC#,再選擇Windows應(yīng)
用程序模板,輸入名稱“3sdnMap”,點擊確定。
在解決方案管理器中將“Form1.cs”重命名為“3sdnMap.cs”,在設(shè)計視圖中,選中窗體,將其
屬性中的“Text”改為“3sdnMap”。
2、添加控件
選擇工具箱中的“菜單和工具欄|MenuStrip",將其拖入窗體。
選擇工具箱中的“ArcGISWindowsForms”節(jié),將“Toolbarcontrol”控件拖入窗體,并將其屬
性中的Dock設(shè)置為Top。
選擇工具箱中的“菜單和工具欄|StatusStrip”,將其拖入到窗體。
選擇工具箱中的“容器ISphtContainer”容器拖入窗體,并將其屬性中的Dock設(shè)置為Fill。
將TabControl控件拖入Panell,將Alignment屬性設(shè)置為Bottom,Dock屬性設(shè)置為FilL
點擊TabPages屬性右邊的按鈕,彈出TabPage集合編輯器,將tabPagel的Name設(shè)置為
tabPageLayer,Text設(shè)置為圖層,將tabPage2的Name設(shè)置為tabPageProperty,Text設(shè)
置為屬性。如下所示。
選擇“圖層”選項卡,拖入TOCControl控件,設(shè)置Dock屬性為Fill。
選擇“屬性”選項卡,拖入DataGidView控件,設(shè)置Dock屬性為Fill。
拖入TabControl控件到由nel2,設(shè)置Dock屬性為Fill。并上述類似的方法,將兩個選項卡
的Name和Text分別設(shè)置為:(tabPageMap、地圖),(tabPageLayout,制版)。
選擇“地圖”選項卡,拖入M叩Control控件,設(shè)置Dock屬性為RIL
選擇"制版"選項卡,拖入PageLayoutControl控件,設(shè)置Dock屬性為Fill。
最后將LicenseControl控件拖入到窗體的任意地方。
按F5編譯運行,可以看到剛才布局好的程序界面了。
3、控件綁定
通過以上步驟添加的控件還只是單獨存在,而我們的程序需要各控件間協(xié)同工作,因此要進
行控件綁定。
分別右擊ToolbarControl>TOCControl控件,將Buddy設(shè)置為axM叩Control,如下圖所
Zjso
這樣,工具條和圖層控件就與地圖控件關(guān)聯(lián)了。
4、添加工具
此時,工具條中還沒有任何工具,添加的方法也很簡單-右擊Toolbarcontrol,選擇“屬性
|Items",點擊Add,選擇Commands選項卡中的Generic,雙擊Open、SaveAs、Redo、
Undo即可將相應(yīng)工具添加到工具條。
常見的工具有:
MapNavigation中的導(dǎo)航工具,MapInquiry中的查詢工具,F(xiàn)eatureSelection中的選擇工
具,你可以根據(jù)需要酌情添加工具。
5、編譯運行
按F5即可編譯運行程序,至此桌面GIS應(yīng)用程序框架基本框架已經(jīng)搭建好了,你可以通過
工具條的工具打開地圖文檔,瀏覽地圖了,效果如開篇所示.
第二講菜單的添加及其實現(xiàn)
在上講中,我們實現(xiàn)了應(yīng)用程序基本框架,其中有個小錯誤,在此先跟大家說明下。在“屬
性”選項卡中,我們當時添加的是DataGridView控件,這個控件是用來顯示數(shù)據(jù)表的,而
專門用于屬性的查詢和設(shè)置的控件是PropertyGrid控件。因此請你刪除“屬性”選項卡中
的DataGridView控件,再把位于“工具箱I所有Windows窗體IPropertyGrid"(如果沒
有,右擊選擇“選擇項"以添加此控件)控件拖到該選項卡。
在這一講中,主要講解菜單的添加和實現(xiàn)。
1、添加菜單
在設(shè)計視圖中,單擊菜單欄,會出現(xiàn)“請在此處鍵入”的提示,單擊提示就可以鍵入菜單名
稱,如“文件”,再單擊“文件”,即可輸入其下拉子菜單,如下所示:
Tips:
每創(chuàng)建一個菜單,請在其屬性面板中設(shè)置Name屬性,而且不要為中文,因此Name值將
是此菜單響應(yīng)函數(shù)的函數(shù)名的一部分,帶中文的函數(shù)名,總是不好吧。
本講中,我們將添加新建(New)、打開(Open)、添加數(shù)據(jù)(AddData)、保存(Save)、
另存為(SaveAs)、退出(Exit)這些菜單,()內(nèi)為相應(yīng)的Name屬性值。
Tips:
你可以在屬性面板中的Text屬性中,把菜單名設(shè)置為中英文形式,如“打開Open”,帶
下劃線的0表示此項菜單的快捷鍵是字母0,設(shè)置方法是在相應(yīng)字母前加上“&”字
符,如“打開&Open但這種快捷鍵只在打開此下拉菜單時才有效,即當你單擊“文件”
菜單彈出下拉菜單時,按下字母O就可以定位到“打開”菜單。
還有一種在程序運行時都有效的全局快捷鍵,可以在屬性面板中的“ShortCutKeys”中設(shè)
置。
你還可以在屬性面板中的Image屬性中設(shè)置你喜歡的菜單圖標。單擊Image那一行右邊的
按鈕,彈出如下菜單。選擇“項目資源文件”,再單擊導(dǎo)入就可以選擇你的圖標了。
最終效果如下所示。
注意,在解決方案面板中,選中剛才添加的所有圖標,在其屬性面板中將生成操作設(shè)置為“嵌
入的資源”,這一點很重要!
2、實現(xiàn)相關(guān)菜單
首先定義指針(寫在publicpartialclassForml:Form下面即可):
privateESRI.ArcGIS.Controls.IM叩Controlm_mapControl=null;
privateESRLArcGIS.Controls.IPageLayoutControl2m_pageLayoutControl=null;
privateIMapDocumentpMapDocument;
若以上指針無效,請?zhí)砑右韵乱?
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.Controls;
usingESRI.ArcGIS.esriSystem;
usingESRLArcGIS.Display;
usingESRI.ArcGIS.Geometry;
usingESRI.ArcGIS.SystemUI;
在設(shè)計視圖中的屬性面板中,選擇Forml,即主窗體,單擊事件按鈕(閃電形狀的那個按
鈕),打到“Load”事件并雙擊,添加此事件。
在Forml_Load函數(shù)中初始化這些指針:
//取得MapControl和PageLayoutControl的引用
m_mapControl=(IMapControl3)this.axMapControl1.Object;
m_pageLayoutControl=(IPageLayoutControl2)this.axPageLayoutControl1.Object;
依次雙擊每個菜單項,添加菜單響應(yīng)函數(shù)。實現(xiàn)代碼如下:
III<summary>
///新建地圖命令
III</summary>
///<paramname="sender's</param>
///<paramname='*e"></param>
privatevoidNew_Qick(objectsender,EventArgse)
{
//本命令涉及到MapControl和PageLayoutControl同步問題,將在下一講中實現(xiàn)
)
III<summary>
///打開地圖文檔Mxd命令
III</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidOpen_Qick(objectsender,EventArgse)
(
//木命令涉及到MapControl和PageLayoutControl同步問題,將在下一講中實現(xiàn)
)
III<summary>
///添加數(shù)據(jù)命令
III</summary>
///<paramname="sender's</param>
///<paramname="eH></param>
privatevoidAddData_Qick(objectsender,EventArgse)
{
intcurrentLayerCount=this.axMapControll.LayerCount;
ICommandpCommand=newControlsAddDataCommandaass();
pCommand.OnCreate(this.axMapControl1.Object);
pCommand.OnQickO;
)
///<summary>
///保存地圖文檔命令
///</summary>
///<paramname="sender"></param>
III<paramname="e"></param>
privatevoidSave_Qick(objectsender,EventArgse)
//首先確認當前地圖文檔是否有效
if(null!=mjDageLayoutControl.DocumentFlename&&m_mapControl.CheckMxFle(mjDageLayoutControl.
DocumentFilename))
{
//創(chuàng)建一個新的地圖文檔實例
IMapDocumentmapDoc=newMapDocumentOassO;
//打開當前地圖文檔
mapDoc.Open(mjDageLayoutControl.DocumentFilename,string.Empty);
//用PageLayout中的文檔替換當前文檔中的PageLayout部分
mapDoc.ReplaceContents((IMxdContents)mj3ageLayoutControl.PageLayout);
//保存地圖文檔
mapDoc.Save(mapDoc.UsesRelativePaths,false);
mapDoc.Qose();
)
)
///<summary>
///另存為地圖文檔命令
///</summary>
///<paramname="sender"></param>
///<paramname="eH></param>
privatevoidSaveAs_Qick(objectsender,EventArgse)
{
//調(diào)用另存為命令
ICommandcommand=newControlsSaveAsDocCommandClass();
command.OnCreate(m_controlsSynchronizer.ActiveControl);
command.OnQick();
)
///<summary>
///退出程序
///</summary>
///<paramname="sender's</param>
///<paramname="e"></param>
privatevoidExit_Oick(objectsender,EventArgse)
{
Application.Exit();
)
3、編譯運行
按F5編譯運行程序。也許你會發(fā)現(xiàn),菜單命令的實現(xiàn)方式都是類型的。沒錯,在AE9.2中,
內(nèi)置了許多常用的Command和Tool,如ControlsAddDataCommandClass、
ControlsMapZoomlnToolClass、ControlsMapPanToolClass等等,這些內(nèi)置對象在
ESRLArcGIS.Controls命名空間中,你可以對象瀏覽器中查看。而且這些內(nèi)置對象的調(diào)用方
式都類似,如下所示:
//定義
ICommandcommand=newControlsSaveAsDocCommandClass();
//創(chuàng)建
command.OnCreate(m_controlsSynchronizer.ActiveControl);
//調(diào)用
command.OnQick();
希望你可以舉一反三,去實現(xiàn)更多的你想要的功能。
第三講MapControl與PageLayoutControl同步
在ArcMap中,能夠很方面地進行MapView和LayoutView兩種視圖的切換,而且二
者之間的數(shù)據(jù)是同步顯示的。
關(guān)于兩種視圖同步的實現(xiàn)方法有多種,可以使用Objectcopy對象進行數(shù)據(jù)硬拷貝,而比較
簡單的方法莫過于二者共享一份地圖了,這也是最常用的方法。
1、新建同步類ControlsSynchronizer
在解決方案面板中右擊項目名,選擇“添加|類”,在類別中選擇“VisualC#項目項",在模板
中選擇“類”,輸入類名“ControlsSynchronizer.cs",將以下代碼覆蓋自動生成的代碼:
usingSystem;
usingSystem.Drawing;
using^stem.Collections;
using^stem.ComponentModel;
using^stem.Windows.Forms;
using0stem.10;
usingstem.Runtime.InteropServices;
usingESRI.ArcGIS.esriSystem;
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.Controls;
usingESRI.ArcGIS.SystemUI;
namespace_sdnMap
(
///<summary>
///ThisclassisusedtosynchronizeagvenPageLayoutControlandaMapControl.
///Wheninitialized,theusermustpassthereferenceofthesecontroltotheclass,bind
///thecontroltogetherbycalling?BindControls'whichinturnsetsajoinedMapreferenced
///bybothcontrol;andsetallthebuddycontrolsjoinedbetweenthesetwocontrols.
///WhenalternatingbetweentheMapControlandPageLayoutControl,youshouldactivatethe
visiblecontrol
///anddeactivatetheotherbycallingActivateXXX.
///Thiscalssislimitedtoasituationwherethecontrolsarenotsimultaneouslyvisible.
///</summary>
publicclassControlsSynchronizer
{
#regionclassmembers
privateIMapControl3m_mapControl=null;
privateIPageLayoutControl2mjageLayoutControl=null;
privateIToolm_mapActiveTool=null;
privateIToolm_pageLayoutActiveTool=null;
privateboolmJsMapCtrlactive=true;
privateArrayListm_frameworkControls=null;
#endregion
#regionconstructor
///<summary>
///默認構(gòu)造函數(shù)
///</summary>
publicControlsSynchronizer()
{
〃初始化ArrayUst
mJrameworkControls=newArrayList();
)
///<summary>
///構(gòu)造函數(shù)
///</summary>
///<paramname="mapControl'S</param>
///<paramname="pageLayoutControl"></param>
publicControlsSynchronizer(IMapControl3mapControl,IPageLayoutControl2
pageLayoutControl)
:this()
(
〃為類成員賦值
m_mapControl=mapControl;
m_pageLayoutControl=pageLayoutControl;
)
#endregion
#regionproperties
///<summary>
///取得或設(shè)匏MapControl
///</summary>
publicIMapControl3MapControl
{
get{returnm_mapControl;}
set{m_mapControl=value;}
)
///<summary>
///取得或設(shè)置PageLayoutControl
///</summary>
publicIPageLayoutControlPageLayoutControl
{
get{returnm_pageLayoutControl;}
set{m_pageLayoutControl=value;}
}
///<summary>
III取得當前ActiveView的類型
///</summary>
publicstringActiveViewType
get
if(mJsMapCtrlactive)
return"MapContror1;
else
return"PageLayoutContror,;
)
)
III<summary>
///取得當前活動的Control
///</summary>
publicobjectActiveControl
{
get
(
if(m_mapControl==null||mjoageLayoutControl==null)
thrownewException(nControlsSynchronizer::ActiveControl:\r\nBtherMapControlor
PageLayoutControlarenotinitialized!'*);
if(m_lsMapCtrlactive)
returnm_mapControl.Object;
else
returnm_pageLayoutControl.Object;
)
)
#endregion
#regionMethods
///<summary>
///激活MapControl并解除thePagleLayoutControl
///</summary>
publicvoidActivateMapO
{
try
(
if(m_pageLayoutControl==null11m_mapControl==null)
thrownewException("ControlsSynchronizer::ActivateMap:\r\nBtherMapControlor
PageLayoutControlarenotinitialized!");
〃緩存當前PageLayout的CurrentTool
if(m_pageLayoutControl.CurrentTool!=null)
m_pageLayoutActiveTool=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;
mJsMapCtrlactive=true;
〃為每?個的frameworkcontrols,設(shè)置Buddycontrol為MapControl
this.SetBuddies(m_mapControl.Object);
)
catch(Exceptionex)
(
thrownewException(string.Format("ControlsSynchronizer::ActivateMap:\r\n{0}",
ex.Message));
)
)
///<summary>
III激活F^gleLayoutControl并減活MapCotrol
///</summary>
publicvoidActivatePagel_ayout()
{
try
(
if(m_pageLayoutControl==null||m_mapControl==null)
thrownewException("ControlsSynchronizer::ActivatePageLayout:\r\nBther
MapControlorPageLayoutControlarenotinitialized!");
〃緩存當前MapControl的CurrentTool
if(m_mapControl.CurrentTool!=null)m_mapActiveTool=m_mapControl.CurrentTool;
〃解除MapControl
m_mapControl.ActiveView.Deactivate();
〃激活PageLayoutControl
m_pageLayoutControl.ActiveView.Activate(m_pageLayoutControl.hWnd);
〃將之前PageLayoutControl最后使用的tool,作為活動的tool,賦給PageLayoutControlW
CurrentTool
if(mjDageLayoutActiveTool!=null)
m_pageLayoutControl.CurrentTool=mjDageLayoutActiveTool;
m_lsMapCtrlactive=false;
〃為每一個的frameworkcontrols,設(shè)置Buddycontrol為PageLayoutControl
this.SetBuddies(m_pageLayoutControl.Object);
)
catch(Exceptionex)
(
thrownew
Exception(string.Format(,'OontrolsSynchronizer::ActivatePageLayout:\r\n{0}",ex.Message));
)
}
///<summary>
///給予一個地圖,置換PageLayoutControl和MapControl的focusmap
///</summary>
///<paramname="newMap"></param>
publicvoidReplaceMap(IMapnewMap)
{
if(newMap==null)
thrownewException("ControlsSynchronizer::ReplaceMap:\r\nNewmapforreplacement
isnotinitialized!");
if(mjDageLayoutControl==null||m_mapControl==null)
thrownewException("Cbntrols麗chronizer::ReplaceMap:\r\nBtherMapControlor
PageLayoutControlarenotinitialized!”);
//createanewinstanceofIMapscollectionwhichisneededbythePageLayout
〃創(chuàng)建?個PageLayout需要用到的,新的IMapscollection的實例
IMapsmaps=newMaps();
//addthenewmaptotheMapscollection
〃把新的地圖加到Mapscollection里頭去
maps.Add(newMap);
boolblsMapActive=mJsMapCtrlactive;
//callreplacemaponthePageLayoutinordertoreplacethefocusmap
//wemustcallActivatePageLayout,sinceitisthecontrolwecall'ReplaceMaps,
〃調(diào)用PageLayout的replacemap來置換focusmap
〃我們必須調(diào)用ActivatePageLayout,畫為它是那個我們可以調(diào)用"ReplaceMaps"的Control
this.ActivatePageLayout();
m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
//assignthenewmaptotheMapControl
〃把新的地圖賦給MapControl
m_mapControl.Map=newMap;
//resettheactivetools
〃重設(shè)activetools
m_pageLayoutActiveTool=null;
m_mapActiveTool=null;
//makesurethatthelastactivecontrolisactivated
〃確認之前活動的control被激活
if(blsMapActive)
(
this.ActivateMap();
m_mapControl.ActiveView.Ftefresh();
)
else
{
this.ActivatePageLayout();
m_pageLayoutControl.ActiveView.Refresh();
)
}
///<summary>
///bindtheMapControlandPageLayoutControltogetherbyassigninganewjointfocusmap
///指定共同的Map來把MapControl和PageLayoutControl綁在?起
///</summary>
///<paramname="mapControl'S</param>
///<paramname="pageLayoutControl"></param>
///<paramname="activateMapFrst">trueiftheMapControlsupposedtobeactivatedfirst,ill
果MapControl被首先激活,則為truev/param>
publicvoidBindControls(IMapControl3mapControl,IPageLayoutControlPageLayoutControl,
boolactivateMapFirst)
(
if(mapControl==null||PageLayoutControl==null)
thrownewException("ControlsSynchronizer::BindControls:\r\nEtherMapControlor
PageLayoutControlarenotinitialized!");
m_mapControl=MapControl;
m_pageLayoutControl=PageLayoutControl;
this.BindControls(activateMapFirst);
)
///<summary>
///bindtheMapControlandPageLayoutControltogetherbyassigninganewjointfocusmap
///指定共同的Map來把MapControl和PageLayoutControl綁在一起
///</summary>
///<paramname="activateMapFrst">trueiftheMapControlsupposedtobeactivatedfirst,Joi
果MapControl被首先激活,則為true</param>
publicvoidBindControls(boolactivateMapFrst)
(
if(m_pageLayoutControl==null||m_mapControl==null)
thrownewException("ControlsSynchronizer::BindControls:\r\nEtherMapControlor
PageLayoutControlarenotinitialized!");
//createanewinstanceofIMap
〃創(chuàng)造IMap的一個實例
IMapnewMap=newMapQass();
newMap.Name="Map";
//createanewinstanceofIMapscollectionwhichisneededbythePageLayout
〃創(chuàng)造一個新的IMapscollection的實例,這是PageLayout所需要的
IMapsmaps=newMaps();
//addthenewMapinstancetotheMapscollection
〃把新的Map實例j賦給Mapscollection
maps.Add(newMap);
//callreplacemaponthePageLayoutinordertoreplacethefocusmap
//痼用PageLayout的replacemap來置換focusmap
m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
//assignthenewmaptotheMapControl
〃把新的map賦給MapControl
m_mapControl.Map=newMap;
//resettheactivetools
〃重設(shè)activetools
m_pageLayoutActiveTool=null;
m_mapActiveTool=null;
//makesurethatthelastactivecontrolisactivated
〃確定最后活動的control被激活
if(activateMapFrst)
this.ActivateMap();
else
this.ActivateF^geLayout();
}
///<summary>
///bypassingtheapplication'stoolbarsandTOCtothesynchronizationclass,itsavesyouthe
///managementofthebuddycontroleachtimetheactivecontrolchanges.Thismethodads
theframework
///controltoanarray;oncetheactivecontrolchanges,theclassiteratesthroughthearrayand
///callesSetBuddyControloneachofthestoredframeworkcontrol.
Ill</summary>
///<paramname="control"></param>
publicvoidAddFrameworkControl(objectcontrol)
(
if(control==null)
thrownewException("ControlsSynchronize匚:AddFrameworkControl:\r\nAddedcontrolis
notinitialized!");
m_frameworkControls.Add(control);
)
///<summary>
///Removeaframeworkcontrolfromthemanagedlistofcontrols
///</summary>
///<paramname="control's</param>
publicvoidFtemoveFrameworkControl(objectcontrol)
{
if(control==null)
thrownewException("ControlsSynchronizer::RemoveFrameworkControl:\r\nControlto
beremovedisnotinitialized!,^);
m_frameworkControls.Remove(control);
r
///<summary>
///Removeaframeworkcontrolfromthemanagedlistofcontrolsbyspecifyingitsindexinthe
list
///</summary>
///<paramname="index's</param>
publicvoidRemoveFrameworkControlAt(intindex)
{
if(m_frameworkControls.Count<index)
thrownewException("ControlsSynchronizer::RemoveFrameworkControlAt:\r\nlndexis
outofrange!'*);
m_frameworkControls.FtemoveAt(index);
r
///<summary>
///whentheactivecontrolchanges,theclassiteratesthroughthearrayoftheframework
controls
///andcallesSetBuddyControloneachofthecontrols.
///</summary>
///<paramname="buddyn>theactivecontrol</param>
privatevoidSetBuddies(objectbuddy)
(
try
(
if(buddy==null)
thrownewException("ControlsSynchronizer::SetBuddies:\r\nTargetBuddyControlis
notinitialized!*');
foreach(objectobjinm_frameworkControls)
(
if(objisIToolbarControl)
(
<(IToolbarControl)obj).SetBuddyControl(buddy);
)
elseif(objisITOCControl)
{
((ITOCControl)obj).SetBuddyControl(buddy);
)
}
)
catch(Exceptionex)
{
thrownewException(string.Format("ControlsSynchronizer::SetBuddies:\r\n{0}”,
ex.Message));
)
}
#endregion
)
)
摘要:在ArcMap中,能夠很方面地進行M叩View和LayoutView兩種視圖的切換,而且
二者之間的數(shù)據(jù)是同步顯示的。關(guān)于兩種視圖同步的實現(xiàn)方法有多種,可以使用ObjectCopy
對象進行數(shù)據(jù)硬拷貝,而比較簡單的方法莫過于二者共享一份地圖了,這也是最常用的方法。
2、新建Maps類
在同步類中,要用到Maps類,用于管理地圖對象。與新建同步類
ControlsSynchronizer類似,我們新建Maps類,其所有代碼如下所示:
usingSystem;
usingSystem.Collections;
using^stem.Collections.Generic;
using耳stem.Text;
using^stem.Runtime.InteropServices;
usingESRI.ArcGIS.Carto;
namespace_sdnMap
(
[Guid(,,f27d8789-fbbc-4801-be78-0e3cd8fff9d5")]
[Qasslnterface(QasslnterfaceType.None)]
[Progld("_sdnMap.Maps")]
publicclassMaps:IMaps,IDisposable
(
//classmember-usinginternallyanArrayListtomanagetheMapscollection
privateArrayListm_array=null;
#regionclassconstructor
publicMaps()
{
m_array=newArrayList();
)
#endregion
#regionIDisposableMembers
///<summary>
///Disposethecollection
///</summary>
publicvoidDispose()
(
if(m_array!=null)
{
m_array.aear();
m_array=null;
)
}
#endregion
#regionIMapsMembers
///<summary>
///RemovetheMapatthegivenindex
///</summary>
///<paramname="Index"></param>
publicvoidRemoveAt(intIndex)
{
if(Index>m_array.Count||Index<0)
thrownewException("Maps::FtemoveAt:\r\nlndexisoutofrange!*');
m_array.RemoveAt(lndex);
)
///<summary>
///ResettheMapsarray
///</summary>
publicvoidReset()
(
m_array.Qear();
}
///<summary>
IllGetthenumberofMapsinthecollection
///</summary>
publicintCount
{
get
{
returnm_array.Count;
)
)
///<summary>
///ReturntheMapatthegivenindex
///</summary>
///<paramname="Index',></param>
///<returns></returns>
publicIMapgetjtern(intIndex)
{
if(Index>m_array.Count11Index<0)
thrownewException("Maps::get_ltem:\r\nIndexisoutofrange!");
returnm_array[Index]asIMap;
)
///<summary>
///RemovetheinstanceofthegivenMap
///</summary>
///<paramname="Map"></param>
publicvoidRemove(IMapMap)
(
m_array.Remove(Map);
)
///<summary>
///CreateanewMap,addittothecollectionandreturnittothecaller
III</summary>
///<returnsx/returns>
publicIMapCreate()
{
IMapnewMap=newMapQass();
m_array.Add(newMap);
returnnewMap;
}
///<summary>
IIIAddthegivenMaptothecollection
///</summary>
///<paramname=*'Map"></param>
publicvoidAdd(IMapMap)
{
if(Map==null)
thrownewException("Maps::Add:\r\nNewMapismotinitialized!1');
m_array.Add(Map);
}
#endregion
)
)
3、新建打開文檔類OpenNewMapD
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年抗?jié)B碳磚項目可行性研究報告
- 2025年多槽超聲波清洗機項目可行性研究報告
- 2025年印染用助劑項目可行性研究報告
- 2025年低溫空調(diào)項目可行性研究報告
- 2025至2030年中國高密度聚乙烯管材數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年鍍前處理酸性除油劑項目投資價值分析報告
- 2025至2030年警燈三輪童車項目投資價值分析報告
- 2025至2030年福美胂可濕性粉劑項目投資價值分析報告
- 2025至2030年火炮半軸模鍛件項目投資價值分析報告
- 2025至2030年桿套項目投資價值分析報告
- 2024九省聯(lián)考適應(yīng)性考試【甘肅省】歷史試卷及答案解析
- 四年級語文下冊第六單元【集體備課】(教材解讀+教學(xué)設(shè)計)
- 蘇教版小學(xué)信息技術(shù)五年級下冊五年級下冊教案全集
- 學(xué)校托管工作方案
- 腎性高血壓的護理查房
- 蘇教版八年級數(shù)學(xué)上冊期末試卷及答案【完美版】
- 法院拍賣議價協(xié)議書
- 2021年人教版八年級物理上冊期末考試卷(完美版)
- TB 10009-2016 鐵路電力牽引供電設(shè)計規(guī)范
- 2024年東南亞雞蛋分級包裝設(shè)備市場深度研究及預(yù)測報告
- 2023高考數(shù)學(xué)藝考生一輪復(fù)習(xí)基礎(chǔ)講義(學(xué)生版)
評論
0/150
提交評論