




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
《ArcGISEngine+C#實(shí)例開(kāi)發(fā)教程》
作者:3SDN.Net文章來(lái)源:3SDN原創(chuàng)點(diǎn)擊數(shù):14478更新時(shí)間:2009-5-12
摘要:《ArcGISEngine+C#實(shí)例開(kāi)發(fā)教程》,面向ArcGISEngine(以下簡(jiǎn)稱(chēng)AE)開(kāi)發(fā)初
學(xué)者,本教程將幫助您進(jìn)一步理解AE的體系結(jié)構(gòu)與開(kāi)發(fā)方法,掌握基本的GIS桌面應(yīng)用程
序的開(kāi)發(fā)。
版權(quán)聲明:
《ArcGISEngine+。實(shí)例開(kāi)發(fā)教程》為3SDN(http://ww)原創(chuàng)教程,版
權(quán)所有。禁止商業(yè)用途轉(zhuǎn)載(如需請(qǐng)聯(lián)系作者),非商業(yè)用途轉(zhuǎn)載請(qǐng)注明出處。教程采用
C#語(yǔ)言,以VS2005為開(kāi)發(fā)工具。
讀者對(duì)象:
ArcGISEngine(以下簡(jiǎn)稱(chēng)AE)開(kāi)發(fā)初學(xué)者,了解AE基本體系,了解C#基本語(yǔ)法,
了解VS2005的基本使用方法。
預(yù)期學(xué)習(xí)效果:
進(jìn)一步理解AE的體系結(jié)構(gòu)與開(kāi)發(fā)方法,掌握基本的GIS桌面應(yīng)用程序的開(kāi)發(fā)。
教程目錄:
《ArcGISEngine+C#實(shí)例開(kāi)發(fā)教程》1
第一講:桌面GIS應(yīng)用程序框架的建立2
1、新建項(xiàng)目3
2、添加控件4
3、控件綁定5
4、添加工具6
5、編譯運(yùn)行7
第二講菜單的添加及其實(shí)現(xiàn)7
1、添加菜單7
2、實(shí)現(xiàn)相關(guān)菜單8
3、編譯運(yùn)行10
第三講MapControl與PageLayoutControl同步11
1、新建同步類(lèi)ControlsSynchronizer11
2、新建Maps類(lèi)17
3、新建打開(kāi)文檔類(lèi)OpenNewMapDocument20
4、兩種視圖的同步21
5、編譯運(yùn)行24
第四講狀態(tài)欄信息的添加與實(shí)現(xiàn)25
1、添加狀態(tài)欄項(xiàng)目25
2、顯示當(dāng)前所用工具信息26
3、顯示當(dāng)前比例尺27
4、顯示當(dāng)前坐標(biāo)27
5、編譯運(yùn)行30
第五講鷹眼的實(shí)現(xiàn)30
1、添加鷹眼控件31
2、鷹眼的實(shí)現(xiàn)34
第六講右鍵菜單添加與實(shí)現(xiàn)39
1、創(chuàng)建右鍵菜單39
2、添加菜單項(xiàng)40
3、彈出右鍵菜單44
4、編譯運(yùn)行45
第六講:教程Bug及解決方法45
到第六講為止已經(jīng)發(fā)現(xiàn)的教程Bug及解決方法如下:45
目前已經(jīng)發(fā)現(xiàn)的優(yōu)化方案如下:46
第七講圖層符號(hào)選擇器的實(shí)現(xiàn)146
1、直接調(diào)用ArcMap中的符號(hào)選擇器49
2、自定義符號(hào)選擇器51
2.1新建符號(hào)選擇器窗體51
2.2設(shè)置控件屬性52
2.3添加引用53
2.4初始化53
2.5調(diào)用自定義符號(hào)選擇器58
2.6符號(hào)參數(shù)調(diào)整60
2.7添加更多符號(hào)菜單65
2.8編譯運(yùn)行67
第八講屬性數(shù)據(jù)表的查詢(xún)顯示67
1.創(chuàng)建屬性表窗體68
2.創(chuàng)建空DataTable69
3.裝載DataTable數(shù)據(jù)73
4.綁定DataTable到DataGridView76
5.調(diào)用屬性表窗體78
6.編譯運(yùn)行81
第一講:桌面GIS應(yīng)用程序框架的建立
本講主要是使用MapControKPageLayoutControLToolbarControKTCXSControl四個(gè)
控件建立起基本的桌面GIS應(yīng)用程序框架。最終成果預(yù)覽如下:
1、新建項(xiàng)目
啟動(dòng)VS2005,選擇“文件|新建|項(xiàng)目”,在項(xiàng)目類(lèi)型中選擇VisualC#,再選擇Windows應(yīng)
用程序模板,輸入名稱(chēng)“3sdnMap”,點(diǎn)擊確定。
在解決方案管理器中將“Form1.cs”重命名為“3sdnMap.cs”,在設(shè)計(jì)視圖中,選中窗體,將其
屬性中的“Text”改為“3sdnMap”。
2、添加控件
選擇工具箱中的“菜單和工具欄|MenuStrip",將其拖入窗體。
選擇工具箱中的“ArcGISWindowsForms”節(jié),將“Toolbarcontrol”控件拖入窗體,并將其屬
性中的Dock設(shè)置為T(mén)op。
選擇工具箱中的“菜單和工具欄|StatusStrip”,將其拖入到窗體。
選擇工具箱中的“容器ISphtContainer”容器拖入窗體,并將其屬性中的Dock設(shè)置為Fill。
將TabControl控件拖入Panell,將Alignment屬性設(shè)置為Bottom,Dock屬性設(shè)置為FilL
點(diǎn)擊TabPages屬性右邊的按鈕,彈出TabPage集合編輯器,將tabPagel的Name設(shè)置為
tabPageLayer,Text設(shè)置為圖層,將tabPage2的Name設(shè)置為tabPageProperty,Text設(shè)
置為屬性。如下所示。
選擇“圖層”選項(xiàng)卡,拖入TOCControl控件,設(shè)置Dock屬性為Fill。
選擇“屬性”選項(xiàng)卡,拖入DataGidView控件,設(shè)置Dock屬性為Fill。
拖入TabControl控件到由nel2,設(shè)置Dock屬性為Fill。并上述類(lèi)似的方法,將兩個(gè)選項(xiàng)卡
的Name和Text分別設(shè)置為:(tabPageMap、地圖),(tabPageLayout,制版)。
選擇“地圖”選項(xiàng)卡,拖入M叩Control控件,設(shè)置Dock屬性為RIL
選擇"制版"選項(xiàng)卡,拖入PageLayoutControl控件,設(shè)置Dock屬性為Fill。
最后將LicenseControl控件拖入到窗體的任意地方。
按F5編譯運(yùn)行,可以看到剛才布局好的程序界面了。
3、控件綁定
通過(guò)以上步驟添加的控件還只是單獨(dú)存在,而我們的程序需要各控件間協(xié)同工作,因此要進(jìn)
行控件綁定。
分別右擊ToolbarControl>TOCControl控件,將Buddy設(shè)置為axM叩Control,如下圖所
Zjso
這樣,工具條和圖層控件就與地圖控件關(guān)聯(lián)了。
4、添加工具
此時(shí),工具條中還沒(méi)有任何工具,添加的方法也很簡(jiǎn)單-右擊Toolbarcontrol,選擇“屬性
|Items",點(diǎn)擊Add,選擇Commands選項(xiàng)卡中的Generic,雙擊Open、SaveAs、Redo、
Undo即可將相應(yīng)工具添加到工具條。
常見(jiàn)的工具有:
MapNavigation中的導(dǎo)航工具,MapInquiry中的查詢(xún)工具,F(xiàn)eatureSelection中的選擇工
具,你可以根據(jù)需要酌情添加工具。
5、編譯運(yùn)行
按F5即可編譯運(yùn)行程序,至此桌面GIS應(yīng)用程序框架基本框架已經(jīng)搭建好了,你可以通過(guò)
工具條的工具打開(kāi)地圖文檔,瀏覽地圖了,效果如開(kāi)篇所示.
第二講菜單的添加及其實(shí)現(xiàn)
在上講中,我們實(shí)現(xiàn)了應(yīng)用程序基本框架,其中有個(gè)小錯(cuò)誤,在此先跟大家說(shuō)明下。在“屬
性”選項(xiàng)卡中,我們當(dāng)時(shí)添加的是DataGridView控件,這個(gè)控件是用來(lái)顯示數(shù)據(jù)表的,而
專(zhuān)門(mén)用于屬性的查詢(xún)和設(shè)置的控件是PropertyGrid控件。因此請(qǐng)你刪除“屬性”選項(xiàng)卡中
的DataGridView控件,再把位于“工具箱I所有Windows窗體IPropertyGrid"(如果沒(méi)
有,右擊選擇“選擇項(xiàng)"以添加此控件)控件拖到該選項(xiàng)卡。
在這一講中,主要講解菜單的添加和實(shí)現(xiàn)。
1、添加菜單
在設(shè)計(jì)視圖中,單擊菜單欄,會(huì)出現(xiàn)“請(qǐng)?jiān)诖颂庢I入”的提示,單擊提示就可以鍵入菜單名
稱(chēng),如“文件”,再單擊“文件”,即可輸入其下拉子菜單,如下所示:
Tips:
每創(chuàng)建一個(gè)菜單,請(qǐng)?jiān)谄鋵傩悦姘逯性O(shè)置Name屬性,而且不要為中文,因此Name值將
是此菜單響應(yīng)函數(shù)的函數(shù)名的一部分,帶中文的函數(shù)名,總是不好吧。
本講中,我們將添加新建(New)、打開(kāi)(Open)、添加數(shù)據(jù)(AddData)、保存(Save)、
另存為(SaveAs)、退出(Exit)這些菜單,()內(nèi)為相應(yīng)的Name屬性值。
Tips:
你可以在屬性面板中的Text屬性中,把菜單名設(shè)置為中英文形式,如“打開(kāi)Open”,帶
下劃線(xiàn)的0表示此項(xiàng)菜單的快捷鍵是字母0,設(shè)置方法是在相應(yīng)字母前加上“&”字
符,如“打開(kāi)&Open但這種快捷鍵只在打開(kāi)此下拉菜單時(shí)才有效,即當(dāng)你單擊“文件”
菜單彈出下拉菜單時(shí),按下字母O就可以定位到“打開(kāi)”菜單。
還有一種在程序運(yùn)行時(shí)都有效的全局快捷鍵,可以在屬性面板中的“ShortCutKeys”中設(shè)
置。
你還可以在屬性面板中的Image屬性中設(shè)置你喜歡的菜單圖標(biāo)。單擊Image那一行右邊的
按鈕,彈出如下菜單。選擇“項(xiàng)目資源文件”,再單擊導(dǎo)入就可以選擇你的圖標(biāo)了。
最終效果如下所示。
注意,在解決方案面板中,選中剛才添加的所有圖標(biāo),在其屬性面板中將生成操作設(shè)置為“嵌
入的資源”,這一點(diǎn)很重要!
2、實(shí)現(xiàn)相關(guān)菜單
首先定義指針(寫(xiě)在publicpartialclassForml:Form下面即可):
privateESRI.ArcGIS.Controls.IM叩Controlm_mapControl=null;
privateESRLArcGIS.Controls.IPageLayoutControl2m_pageLayoutControl=null;
privateIMapDocumentpMapDocument;
若以上指針無(wú)效,請(qǐng)?zhí)砑右韵乱?
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.Controls;
usingESRI.ArcGIS.esriSystem;
usingESRLArcGIS.Display;
usingESRI.ArcGIS.Geometry;
usingESRI.ArcGIS.SystemUI;
在設(shè)計(jì)視圖中的屬性面板中,選擇Forml,即主窗體,單擊事件按鈕(閃電形狀的那個(gè)按
鈕),打到“Load”事件并雙擊,添加此事件。
在Forml_Load函數(shù)中初始化這些指針:
//取得MapControl和PageLayoutControl的引用
m_mapControl=(IMapControl3)this.axMapControl1.Object;
m_pageLayoutControl=(IPageLayoutControl2)this.axPageLayoutControl1.Object;
依次雙擊每個(gè)菜單項(xiàng),添加菜單響應(yīng)函數(shù)。實(shí)現(xiàn)代碼如下:
III<summary>
///新建地圖命令
III</summary>
///<paramname="sender's</param>
///<paramname='*e"></param>
privatevoidNew_Qick(objectsender,EventArgse)
{
//本命令涉及到MapControl和PageLayoutControl同步問(wèn)題,將在下一講中實(shí)現(xiàn)
)
III<summary>
///打開(kāi)地圖文檔Mxd命令
III</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidOpen_Qick(objectsender,EventArgse)
(
//木命令涉及到MapControl和PageLayoutControl同步問(wèn)題,將在下一講中實(shí)現(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)
//首先確認(rèn)當(dāng)前地圖文檔是否有效
if(null!=mjDageLayoutControl.DocumentFlename&&m_mapControl.CheckMxFle(mjDageLayoutControl.
DocumentFilename))
{
//創(chuàng)建一個(gè)新的地圖文檔實(shí)例
IMapDocumentmapDoc=newMapDocumentOassO;
//打開(kāi)當(dāng)前地圖文檔
mapDoc.Open(mjDageLayoutControl.DocumentFilename,string.Empty);
//用PageLayout中的文檔替換當(dāng)前文檔中的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、編譯運(yùn)行
按F5編譯運(yùn)行程序。也許你會(huì)發(fā)現(xiàn),菜單命令的實(shí)現(xiàn)方式都是類(lèi)型的。沒(méi)錯(cuò),在AE9.2中,
內(nèi)置了許多常用的Command和Tool,如ControlsAddDataCommandClass、
ControlsMapZoomlnToolClass、ControlsMapPanToolClass等等,這些內(nèi)置對(duì)象在
ESRLArcGIS.Controls命名空間中,你可以對(duì)象瀏覽器中查看。而且這些內(nèi)置對(duì)象的調(diào)用方
式都類(lèi)似,如下所示:
//定義
ICommandcommand=newControlsSaveAsDocCommandClass();
//創(chuàng)建
command.OnCreate(m_controlsSynchronizer.ActiveControl);
//調(diào)用
command.OnQick();
希望你可以舉一反三,去實(shí)現(xiàn)更多的你想要的功能。
第三講MapControl與PageLayoutControl同步
在ArcMap中,能夠很方面地進(jìn)行MapView和LayoutView兩種視圖的切換,而且二
者之間的數(shù)據(jù)是同步顯示的。
關(guān)于兩種視圖同步的實(shí)現(xiàn)方法有多種,可以使用Objectcopy對(duì)象進(jìn)行數(shù)據(jù)硬拷貝,而比較
簡(jiǎn)單的方法莫過(guò)于二者共享一份地圖了,這也是最常用的方法。
1、新建同步類(lèi)ControlsSynchronizer
在解決方案面板中右擊項(xiàng)目名,選擇“添加|類(lèi)”,在類(lèi)別中選擇“VisualC#項(xiàng)目項(xiàng)",在模板
中選擇“類(lèi)”,輸入類(lèi)名“ControlsSynchronizer.cs",將以下代碼覆蓋自動(dòng)生成的代碼:
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>
///默認(rèn)構(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()
(
〃為類(lèi)成員賦值
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取得當(dāng)前ActiveView的類(lèi)型
///</summary>
publicstringActiveViewType
get
if(mJsMapCtrlactive)
return"MapContror1;
else
return"PageLayoutContror,;
)
)
III<summary>
///取得當(dāng)前活動(dòng)的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!");
〃緩存當(dāng)前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,作為活動(dòng)的tool,賦給MapControl的CurrentTool
if(m_mapActiveTool!=null)
m_mapControl.CurrentTool=m_mapActiveTool;
mJsMapCtrlactive=true;
〃為每?個(gè)的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!");
〃緩存當(dāng)前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,作為活動(dòng)的tool,賦給PageLayoutControlW
CurrentTool
if(mjDageLayoutActiveTool!=null)
m_pageLayoutControl.CurrentTool=mjDageLayoutActiveTool;
m_lsMapCtrlactive=false;
〃為每一個(gè)的frameworkcontrols,設(shè)置Buddycontrol為PageLayoutControl
this.SetBuddies(m_pageLayoutControl.Object);
)
catch(Exceptionex)
(
thrownew
Exception(string.Format(,'OontrolsSynchronizer::ActivatePageLayout:\r\n{0}",ex.Message));
)
}
///<summary>
///給予一個(gè)地圖,置換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)建?個(gè)PageLayout需要用到的,新的IMapscollection的實(shí)例
IMapsmaps=newMaps();
//addthenewmaptotheMapscollection
〃把新的地圖加到Mapscollection里頭去
maps.Add(newMap);
boolblsMapActive=mJsMapCtrlactive;
//callreplacemaponthePageLayoutinordertoreplacethefocusmap
//wemustcallActivatePageLayout,sinceitisthecontrolwecall'ReplaceMaps,
〃調(diào)用PageLayout的replacemap來(lái)置換focusmap
〃我們必須調(diào)用ActivatePageLayout,畫(huà)為它是那個(gè)我們可以調(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
〃確認(rèn)之前活動(dòng)的control被激活
if(blsMapActive)
(
this.ActivateMap();
m_mapControl.ActiveView.Ftefresh();
)
else
{
this.ActivatePageLayout();
m_pageLayoutControl.ActiveView.Refresh();
)
}
///<summary>
///bindtheMapControlandPageLayoutControltogetherbyassigninganewjointfocusmap
///指定共同的Map來(lái)把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來(lái)把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的一個(gè)實(shí)例
IMapnewMap=newMapQass();
newMap.Name="Map";
//createanewinstanceofIMapscollectionwhichisneededbythePageLayout
〃創(chuàng)造一個(gè)新的IMapscollection的實(shí)例,這是PageLayout所需要的
IMapsmaps=newMaps();
//addthenewMapinstancetotheMapscollection
〃把新的Map實(shí)例j賦給Mapscollection
maps.Add(newMap);
//callreplacemaponthePageLayoutinordertoreplacethefocusmap
//痼用PageLayout的replacemap來(lái)置換focusmap
m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
//assignthenewmaptotheMapControl
〃把新的map賦給MapControl
m_mapControl.Map=newMap;
//resettheactivetools
〃重設(shè)activetools
m_pageLayoutActiveTool=null;
m_mapActiveTool=null;
//makesurethatthelastactivecontrolisactivated
〃確定最后活動(dòng)的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中,能夠很方面地進(jìn)行M叩View和LayoutView兩種視圖的切換,而且
二者之間的數(shù)據(jù)是同步顯示的。關(guān)于兩種視圖同步的實(shí)現(xiàn)方法有多種,可以使用ObjectCopy
對(duì)象進(jìn)行數(shù)據(jù)硬拷貝,而比較簡(jiǎn)單的方法莫過(guò)于二者共享一份地圖了,這也是最常用的方法。
2、新建Maps類(lèi)
在同步類(lèi)中,要用到Maps類(lèi),用于管理地圖對(duì)象。與新建同步類(lèi)
ControlsSynchronizer類(lèi)似,我們新建Maps類(lèi),其所有代碼如下所示:
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、新建打開(kāi)文檔類(lèi)OpenNewMapD
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆山東省中學(xué)聯(lián)盟(普高文化)高三開(kāi)學(xué)考-語(yǔ)文試題(含答案)
- 購(gòu)買(mǎi)電纜線(xiàn)合同協(xié)議
- 2025幼兒園數(shù)學(xué)難易結(jié)合考試試題及答案
- 2022年全國(guó)中學(xué)生數(shù)學(xué)奧林匹克競(jìng)賽(預(yù)賽)暨 2022年全國(guó)高中數(shù)學(xué)聯(lián)合競(jìng)賽(B1卷)參考答案及評(píng)分標(biāo)準(zhǔn)
- 商標(biāo)托管合同協(xié)議
- 正規(guī)回遷房合同協(xié)議
- 商家入駐意向合同協(xié)議
- 品牌廣告施工合同協(xié)議
- 商場(chǎng)購(gòu)物停車(chē)協(xié)議合同協(xié)議
- 咖啡車(chē)攤位租賃合同協(xié)議
- 2025年五級(jí)應(yīng)急救援員資格理論考試題庫(kù)(含答案)
- 2025年廣東省深圳市南山實(shí)驗(yàn)教育集團(tuán)中考一模英語(yǔ)試題(含答案)
- 統(tǒng)編版道德與法治四年級(jí)下冊(cè)第9課《生活離不開(kāi)他們》精美課件
- 2025-2030中國(guó)汽車(chē)線(xiàn)控底盤(pán)行業(yè)市場(chǎng)現(xiàn)狀分析及競(jìng)爭(zhēng)格局與投資發(fā)展研究報(bào)告
- 中華農(nóng)耕文化歷史與現(xiàn)實(shí)知到課后答案智慧樹(shù)章節(jié)測(cè)試答案2025年春中國(guó)農(nóng)業(yè)大學(xué)
- 中考語(yǔ)文試卷名著專(zhuān)題匯編《駱駝祥子》看圖題(含答案)(截至2024年)
- 設(shè)備采購(gòu)方案投標(biāo)文件(技術(shù)方案)
- 信息技術(shù)必修2信息系統(tǒng)與社會(huì)3.2《數(shù)據(jù)庫(kù)的構(gòu)建》教學(xué)設(shè)計(jì)
- 氫能源項(xiàng)目融資計(jì)劃書(shū)
- 2025年丹江口水力發(fā)電廠招聘筆試參考題庫(kù)含答案解析
- 住宅室內(nèi)裝飾裝修管理辦法
評(píng)論
0/150
提交評(píng)論