版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
GIS應(yīng)用開發(fā)DevelopingGISApplicationswithArcObjectsusingC#.NET
精選課件ppt教學(xué)目標(biāo)《GIS應(yīng)用開發(fā)》課程是GIS研究生重要的專業(yè)課程,通過(guò)課程的學(xué)習(xí),了解ArcGIS軟件體系結(jié)構(gòu)及ArcObjects
(ArcGIS
Engine)組件構(gòu)成,并能熟練使用ArcObjects(ArcGIS
Engine)
進(jìn)行應(yīng)用型GIS開發(fā);掌握應(yīng)用型GIS開發(fā)的基本思路、技術(shù)方法.精選課件pptChap.3使用ArcObjects控件編程(6學(xué)時(shí))為了能夠快速建構(gòu)一個(gè)具有GIS功能的獨(dú)立應(yīng)用程序,ArcGIS
Engine為開發(fā)者提供了多個(gè)可視化的組件即控件,如LicenseControl
、MapControl、PageLayoutControl、TOCControl、ToolbarControl和SymbologyControl等。在VS.NET中使用ArcObjects,需要使用ESRIinterop程序集,這些程序集在托管的.NET代碼和非托管的COM代碼之間起了橋梁作用。ESRIinterop程序集為ArcGIS控件提供了能夠位于.NET窗體上的控件(繼承自AxHost類),這些控件名前綴為“Ax”,如AxMapControl、AxPageLayoutControl、AxTOCControl和AxToolbarControl等。精選課件pptUsingArcGISEnginecontrols
in
WinformsUsingArcGISEngineControlsinWPF精選課件ppt本章內(nèi)容:MapControl控件PageLayoutControl控件TOCControl控件ToolbarControl及相關(guān)對(duì)象ControlCommands(SymbologyControlinChapter6)在WPF程序中使用ArcGISEngine控件精選課件ppt3.1MapControl控件MapControl對(duì)應(yīng)于ArcMap中的數(shù)據(jù)視圖,其主要功能為空間數(shù)據(jù)瀏覽、空間數(shù)據(jù)可視化、空間查詢、空間分析、空間數(shù)據(jù)編輯等。在可視化環(huán)境中,可以通過(guò)控件的“屬性”頁(yè)設(shè)置控件的相關(guān)屬性,也可以通過(guò)編程來(lái)設(shè)置。精選課件ppt精選課件pptMapControl是對(duì)Map對(duì)象的封裝,并提供了額外的屬性、方法、事件用于:管理控件的外觀、顯示屬性和地圖屬性;添加并管理控件中的數(shù)據(jù)層(datalayers);裝載Map文檔(mxd)到控件中;從其它應(yīng)用程序拖放數(shù)據(jù)到控件中;使用鼠標(biāo)拉繪幾何形狀并繪制到屏幕顯示中。精選課件ppt3.1.1
MapControl的主要接口MapControl實(shí)現(xiàn)的主要接口有:IMapControlDefaultIMapControl2IMapControl3IMapControl4(newin9.2)
IMapControlEvents2事件接口ITOCBuddyIToolbarBuddy精選課件ppt
IMapControlDefault接口IMapControlDefault接口是地圖控件缺省接口,多數(shù)開發(fā)環(huán)境自動(dòng)使用這個(gè)接口定義的屬性、方法。由于MapControl是一個(gè)自動(dòng)化控件,當(dāng)它被放到一個(gè)容器--如窗體上后,它會(huì)自動(dòng)產(chǎn)生一個(gè)被稱為axMapControl1的對(duì)象,這個(gè)對(duì)象可以直接使用缺省接口定義的屬性和方法。這個(gè)接口也代表了控件最新版本的接口,MapControl當(dāng)前最新版本接口為IMapControl4.當(dāng)需要使用這個(gè)接口的時(shí)候,可以使用下面的代碼:
IMapControlDefaultpMapControl=axMapControl1.ObjectasIMapControlDefault;精選課件pptIMapControl2.Extent:地圖的可視范圍;IMapControl2.FullExtent:地圖中所有圖層的覆蓋范圍.精選課件ppt
IMapControl4接口IMapControl4是任何一個(gè)與MapControl相關(guān)的任務(wù)的出發(fā)點(diǎn),如設(shè)置控件外觀,設(shè)置Map對(duì)象或控件的顯示屬性,添加或者管理圖層、地圖文檔,在控件上繪制圖形和返回Geometry等。精選課件pptIMapControl2精選課件ppt精選課件ppt
IMapControl3與IMapControl4IMapControl3接口繼承IMapControl2,并增加了以下8個(gè)屬性和一個(gè)方法:CustomProperty--object:使用該屬性關(guān)聯(lián)有用信息DocumentFilename
--string):返回MapControl裝入的地圖文檔的文件名DocumentMap--string:返回MapControl最后裝入的地圖(Map)名稱KeyIntercept--int:返回或設(shè)置MapControl截取鍵盤按鍵信息精選課件pptObject--object:返回潛在的MapControl控件,當(dāng)在VB.NET或C#.NET中使用IMapControl2時(shí),一定要使用Object屬性或者使用指定容器的代碼。因?yàn)閷?duì)于.NET,真正的控件是被包裝于宿主對(duì)象里面的。ShowMapTips--bool:確定是否顯示地圖的MapTipsTipDelay--int:設(shè)置MapTips的延遲時(shí)間TipStyle--esriTipStyle
:設(shè)置MapTips的顯示樣式SuppressResizeDrawing():在控件尺寸發(fā)生變化過(guò)程中,阻止數(shù)據(jù)實(shí)時(shí)重繪精選課件ppt與IMapControl3相比,IMapControl4多了以下兩個(gè)可讀寫屬性:publicboolAutoKeyboardScrolling{get;set;}:確定是否使用鍵盤上的‘Home’(keyCode36)鍵、‘End’(keyCode35)鍵、‘PageDown’(keyCode34)鍵、‘PageUp’(keyCode33)鍵和箭頭鍵(keyCode37-40)來(lái)平移控件中的地圖,缺省情況下該屬性為true.絕大多數(shù)開發(fā)環(huán)境使用箭頭鍵來(lái)切換窗體或容器中的焦點(diǎn)控件;在這些開發(fā)環(huán)境中,缺省情況下MapControl不會(huì)接收箭頭鍵來(lái)平移地圖的顯示。為確保箭頭鍵能夠被MapControl接收并平移地圖的顯示,KeyIntercept屬性應(yīng)設(shè)置為攔截箭頭鍵(esriKeyInterceptArrowKeys),且AutoKeyboardScrolling設(shè)置為true。精選課件pptpublicboolAutoMouseWheel{get;set;}:確定鼠標(biāo)滾輪是否用于縮放地圖的顯示;缺省情況下該屬性為true。精選課件ppt引用控件本身當(dāng)使用IMapControl2接口時(shí):IMapControl2pMapControl=axMapControl1.ObjectasIMapControl2;或IMapControl2pMapControl=axMapControl1.GetOcx()asIMapControl2;當(dāng)使用IMapControl3接口時(shí):IMapControl3pMapControl=axMapControl1.ObjectasIMapControl3;或IMapControl3pMapControl=axMapControl1.GetOcx()asIMapControl3;精選課件ppt當(dāng)使用IMapControl4接口時(shí):IMapControl4pMapControl;pMapControl=axMapControl1.ObjectasIMapControl4;或pMapControl=axMapControl1.GetOcx()asIMapControl4;精選課件ppt使用箭頭鍵、鼠標(biāo)滾輪實(shí)現(xiàn)地圖導(dǎo)航使用箭頭鍵平移(Panning)地圖axMapControl1.KeyIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;axMapControl1.AutoKeyboardScrolling=true;使用鼠標(biāo)滾輪縮放地圖axMapControl1.AutoMouseWheel=true;精選課件pptaxMapControl1.KeyIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;AutoKeyboardScrolling=true;ConstantValueDescriptionesriKeyInterceptNone0Nokeysareintercepted.esriKeyInterceptArrowKeys1Interceptsthearrowkeys,normallyhandledbythecontainertochangecontrolfocus.esriKeyInterceptAlt2InterceptstheAltkey,normallyhandledbyacontainertochangefocus.esriKeyInterceptTab4InterceptstheTabkey,normallyhandledbythecontainertochangecontrolfocus.esriKeyInterceptEnter8InterceptstheEnterkey,normallyhandledbythecontainertoclickthedefaultbutton.精選課件ppt
IMapControlEvents2接口IMapControlEvents2是一個(gè)事件接口,它定義了MapControl能夠處理的全部事件,如OnExtentUpdated是地圖的Extent(可視范圍)屬性發(fā)生變化時(shí)觸發(fā)的事件,OnAfterscreenDraw是繪屏結(jié)束后觸發(fā)的事件等。
當(dāng)?shù)貓D的覆蓋范圍變化時(shí),觸發(fā)OnFullExtentUpdated事件,例如,往地圖中新增加一個(gè)圖層,其覆蓋范圍大于原圖的范圍。???精選課件ppt在絕大多數(shù)開發(fā)環(huán)境中,沒有必要手工編寫代碼進(jìn)行事件的注冊(cè),而只需在控件的屬性窗口中雙擊某事件自動(dòng)進(jìn)行事件與其處理方法的關(guān)聯(lián)。精選課件ppt
ITOCBuddy該接口定義了以下2個(gè)方法:GetActiveViewReturnstheunderlyingobjectimplementingbasicmapandActiveView.ThisisusedtopopulatetheTOC.GetScaleReturnsthescaleofthesuppliedBasicMap,thisallowsforobjectsthatdonotsupportIMap.精選課件ppt
IToolbarBuddyObjectsthatimplementtheIToolbarBuddyinterfacecanbepassedtotheIToolbarControl.SetBuddyControlmethod.TheCurrentToolisthetoolusedtointeractwiththedisplayareaofthe
IToolbarControl.Buddy.精選課件pptSamples:MapAndPageLayoutSynchAppMapControlMapTipsMapControlGeoEventsMapControlDrawTextMapControlCADViewerMapControlSaveLayerFile精選課件pptGuid.ToString(stringformat)命名空間:System;程序集:mscorlibformat一個(gè)單格式說(shuō)明符,它指示如何格式化此Guid的值。format參數(shù)可以是“N”、“D”、“B”或“P”。說(shuō)明符返回值的格式N32位:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxD由連字符分隔的
32位數(shù)字:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxB括在大括號(hào)中、由連字符分隔的
32位數(shù)字:
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}P括在圓括號(hào)中、由連字符分隔的
32位數(shù)字:
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)精選課件ppt3.1.2MapControl控件與MXD文件MapControl控件可以“鏈接”或“包含”地圖文檔。對(duì)于文檔文件,MapControl控件可以直接使用LoadMxFile方法來(lái)載入,這是最簡(jiǎn)單的方法。除此之外,可以使用IMapDocument接口定義的屬性和方法來(lái)加載一個(gè)MXD文件。精選課件ppt下面是一個(gè)載入文檔的例子--axMapControl1.LoadMxFileprivatevoidLoadMapDocument(){ System.Windows.Forms.OpenFileDialogopenFileDialog2; openFileDialog2=newOpenFileDialog(); openFileDialog2.Title="OpenMapDocument";
openFileDialog2.Filter="MapDocuments(*.mxd)|*.mxd"; openFileDialog2.ShowDialog(); stringsFilePath=openFileDialog2.FileName;
if(axMapControl1.CheckMxFile(sFilePath)) { axMapControl1.LoadMxFile(sFilePath,0,Type.Missing); }
else { MessageBox.Show(sFilePath+"isnotavalidArcMapdocument"); return; } }
精選課件ppt在ArcMap中使用的地圖文檔對(duì)象為MxDocument,其主要接口是IMxDocument;在使用控件開發(fā)的獨(dú)立應(yīng)用程序中,使用的地圖文檔對(duì)象為MapDocument
,其主要接口是IMapDocument。IMapDocument接口定義了操作和管理文檔對(duì)象的方法和屬性。MapDocument類能夠封裝地圖文檔文件,如mxd、mxt和pmf等,它也可以封裝一個(gè)圖層文件(*.lyr)。使用這個(gè)對(duì)象可以獲取和更新一個(gè)文檔的內(nèi)容,設(shè)置文檔文件的讀、寫屬性,保存一個(gè)文檔文件(*.mxd)。精選課件pptIMxDocument與IMapDocument精選課件ppt精選課件pptIApplication的屬性、方法精選課件pptIMxDocument.ActivatedView與ActiveView屬性在ArcMap的布局視圖(layoutview)狀態(tài)下,圖形元素可以添加到頁(yè)面布局(PageLayout)或焦點(diǎn)地圖(focusMap)的圖形元素容器(graphicscontainer)中;這時(shí),IMxDocument.ActiveView屬性與IMxDocument.ActivatedView屬性不同,ActiveView屬性引用PageLayout對(duì)象,ActivatedView屬性引用焦點(diǎn)地圖對(duì)象(如果該地圖對(duì)象處于活動(dòng)狀態(tài))。在ArcMap的數(shù)據(jù)視圖(dataview)狀態(tài)下,ActiveView與ActivatedView屬性都引用焦點(diǎn)地圖對(duì)象。精選課件pptIMapDocumentm_MapDocument=newMapDocumentClass();privatevoidLoadMapDoc(){OpenFileDialogopenFileDialog2=newOpenFileDialog();openFileDialog2.Title="OpenMapDocument";openFileDialog2.Filter="MapDocuments(*.mxd)|*.mxd";openFileDialog2.ShowDialog(); stringsFilePath=openFileDialog2.FileName; If(m_MapDocument.get_IsMapDocument(sFilePath)){m_MapDocument.Open(sFilePath,"");axMapControl1.Map=m_MapDocument.get_Map(0);axMapControl1.Refresh(); }}publicvoidOpen(string
sDocument,string
bsPassword);publicboolget_IsMapDocument(string
sDocument);精選課件pptprivatevoidSaveDocument(){
if(m_MapDocument.get_IsReadOnly(m_MapDocument.DocumentFilename)==true){MessageBox.Show("Thismapdocumentisreadonly!"); return; }m_MapDocument.Save(m_MapDocument.UsesRelativePaths,true);MessageBox.Show("Changessavedsuccessfully!");}publicvoidSave(bool
bUseRelativePaths,bool
bCreateThumnbail);精選課件ppt3.1.3鼠標(biāo)與控件的交互用鼠標(biāo)和地圖控件進(jìn)行交互是最常用的操作,例如改變地圖顯示范圍、移動(dòng)地圖,在控件上繪制幾何圖形等。精選課件ppt使用鼠標(biāo)拖曳確定地圖顯示的范圍(拉框放大)privatevoidaxMapControl1_OnMouseDown
(objectsender,ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente) { //改變地圖控件顯示范圍為當(dāng)前拖曳的區(qū)域
axMapControl1.Extent=axMapControl1.TrackRectangle(); //刷新地圖 axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null); }publicvoidRefresh(
esriViewDrawPhase
phase,
object
layerOrElement,
object
envelope);精選課件ppt移動(dòng)、旋轉(zhuǎn)地圖在MapControl中有一種更簡(jiǎn)單便利的方法pan()來(lái)移動(dòng)其中的地圖。下面的方法使用在MapControl控件的OnMoseDown事件中:
axMapControl1.pan();
axMapControl1.Rotation=45;精選課件ppt在MapControl控件中繪制圖形MapControl控件提供了直接在控件上繪制圖形和文字的方法DrawShape與DrawText,這兩種繪制方法繪制的圖形都是緩存(cache),而不能真正保存,一旦窗口重繪,這些圖形就將消失。精選課件pptprivatevoidaxMapControl1_OnMouseDown
(objectsender,ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente) { //產(chǎn)生拖曳多邊形,并繪制
IGeometrypGeom=axMapControl1.TrackPolygon();
DrawMapShape(pGeom); //刷新地圖 //axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null); }精選課件pptprivatevoidDrawMapShape
(IGeometrypGeom){ IRgbColorpColor; pColor=newRgbColorClass(); pColor.Red=220; pColor.Green=112; pColor.Blue=60; //新建一個(gè)繪制圖形的填充符號(hào)
ISimpleFillSymbolpFillsyl; pFillsyl=newSimpleFillSymbolClass(); pFillsyl.Color=pColor; objectoFillsyl=pFillsyl;
axMapControl1.DrawShape(pGeom,refoFillsyl);}publicvoidDrawShape(IGeometryShape,
refobjectsymbol
);精選課件ppt3.1.4數(shù)據(jù)選擇在MapControl控件中用戶可以很方便地使用SelectByShape方法來(lái)構(gòu)造一個(gè)基于Map的選擇集。SelectByShape()方法選擇控件中所有圖層上處于選擇范圍內(nèi)的要素,并將其設(shè)置為一個(gè)選擇集。精選課件pptprivatevoidaxMapControl1_OnMouseDown(objectsender,IMapControlEvents2_OnMouseDownEvente){ //產(chǎn)生拖曳多邊形
IGeometrypGeom=axMapControl1.TrackPolygon();axMapControl1.Map.SelectByShape(pGeom,null,false);
axMapControl1.
Refresh(esriViewDrawPhase.esriViewGeoSelection,null,null); } 精選課件ppt清除選擇集的方法
axMapControl1.Map.Clearselection();axMapControl1.ActiveView.Refresh();精選課件ppt
3.1.5實(shí)現(xiàn)鷹眼功能精選課件ppt這個(gè)例子中有兩個(gè)AxMapControl控件:主控件axMapControl1和鷹眼控件axMapControl2.要實(shí)現(xiàn)鷹眼功能,關(guān)鍵有兩點(diǎn):一是如何讓兩個(gè)控件顯示的數(shù)據(jù)保持一致,另一點(diǎn)是如何繪制鷹眼控件中的顯示方框。
精選課件ppt兩個(gè)控件的數(shù)據(jù)共享privatevoidaxMapControl1_OnMapReplaced
(objectsender,IMapControlEvents2_OnMapReplacedEvente){ IMappMap; pMap=axMapControl1.Map; inti; for(i=0;i<=pMap.LayerCount-1;i++) {
axMapControl2.Map.AddLayer(pMap.get_Layer(i)); }}精選課件ppt繪制鷹眼控件中的顯示方框主窗體視圖的范圍發(fā)生變化后,會(huì)觸發(fā)控件的OnExtentUpdated事件,繪制方框的方法就在這個(gè)事件中進(jìn)行:privatevoidaxMapControl1_OnExtentUpdated(objectsender,IMapControlEvents2_OnExtentUpdatedEvente) {
…….}精選課件ppt3.2PageLayoutControl控件PageLayoutControl對(duì)應(yīng)于ArcMap中的布局視圖(LayoutView),它封裝了PageLayout對(duì)象,提供了在布局視圖中控制地圖元素的屬性和方法。PageLayoutControl控件用于制圖,它可以方便地操作各種元素對(duì)象,以產(chǎn)生一幅制作精美的地圖對(duì)象。與MapControl控件相似,PageLayoutControl控件并不僅僅只是包含了一個(gè)PageLayout對(duì)象,它也擁有許多附加的事件、屬性和方法。精選課件ppt頁(yè)面布局(通常簡(jiǎn)稱為布局)是在頁(yè)面上編排和組織的地圖元素的集合,旨在用于地圖的排版設(shè)計(jì)、打印等。布局中排布的常見地圖元素包括一個(gè)或多個(gè)數(shù)據(jù)框(每個(gè)數(shù)據(jù)框都含有一組有序的地圖圖層)、比例尺、指北針、地圖標(biāo)題、描述性文本和符號(hào)圖例。打印機(jī)、頁(yè)面布局、大小、單位精選課件ppt精選課件ppt精選課件ppt數(shù)據(jù)驅(qū)動(dòng)頁(yè)面根據(jù)地圖文檔的某個(gè)要素圖層或規(guī)則格網(wǎng)將地圖分割為多個(gè)部分,然后為每個(gè)部分生成一個(gè)相應(yīng)的頁(yè)面。精選課件ppt創(chuàng)建數(shù)據(jù)驅(qū)動(dòng)頁(yè)面精選課件pptPageLayoutControl控件同樣實(shí)現(xiàn)了多個(gè)接口IPageLayoutControlDefaultIPageLayoutControlIPageLayoutControl2IPageLayoutControl3(Newin9.2)IPageLayoutControlEvents精選課件pptIPageLayoutControl3精選課件pptSamples:PageLayoutControlLoadMapDocumentPageLayoutControlCopyFocusMapPageLayoutControlOverviewPageLayoutControlPageAppearancePageLayoutControlPrintPreviewPageLayoutControlPrinting精選課件ppt3.2.1PageLayoutControl操作MXD文件在AxPageLayoutControl控件對(duì)MXD文件的操作,與MapControl類似。publicvoidLoadMxFile(string
fileName,
object
password);
精選課件ppt下面是在PageLayout控件中打開一個(gè)MXD文件的方法:privatevoidOpenMapDocument(){
IMapDocumentm_MapDocument=newMapDocumentClass();
OpenFileDialogopenFileDialog1; openFileDialog1=newOpenFileDialog(); openFileDialog1.Title="OpenMapDocument"; openFileDialog1.Filter="MapDocuments(*.mxd)|*.mxd";
openFileDialog1.ShowDialog(); stringsFilePath=openFileDialog1.FileName;
m_MapDocument.Open(sFilePath,"");
axPageLayoutControl1.PageLayout=m_MapDocument.PageLayout; axPageLayoutControl1.Refresh();}精選課件pptprivatevoidSaveDocument()
{
//Checkthatthedocumentisnotreadonly.if(m_MapDocument.get_IsReadOnly(m_MapDocument.DocumentFilename)==true)
{MessageBox.Show("Thismapdocumentisreadonly!");return;
}
//Savewiththecurrentrelativepathsetting.m_MapDocument.Save(m_MapDocument.UsesRelativePaths,true);MessageBox.Show("Changessavedsuccessfully!");
}精選課件pptprivatevoidcmdSaveAs_Click(objectsender,System.EventArgse){//Openafiledialogforsavingmapdocuments.saveFileDialog1.Title="SaveMapDocumentAs";
saveFileDialog1.Filter="MapDocuments(*.mxd)|*.mxd";saveFileDialog1.ShowDialog();
stringsFilePath=saveFileDialog1.FileName;
if(sFilePath==“”)
return;
if(sFilePath==m_MapDocument.DocumentFilename)
{//Savechangestothecurrentdocument.SaveDocument();
}else
{//SaveAsanewdocumentwithrelativepaths.m_MapDocument.SaveAs
(sFilePath,true,true);//Openthedocument.OpenDocument((sFilePath));MessageBox.Show("Documentsavedsuccessfully!");
}
}精選課件ppt3.2.2PageLayout與MapControl聯(lián)動(dòng)在ArcMap程序中,數(shù)據(jù)視圖和布局視圖中的數(shù)據(jù)改變是實(shí)時(shí)互動(dòng)的。在使用ArcObjects控件開發(fā)的獨(dú)立程序中實(shí)現(xiàn)這個(gè)功能,由于MapControl、PageLayoutControl兩個(gè)控件本身并不能自動(dòng)實(shí)時(shí)互動(dòng),用戶只能夠通過(guò)拷貝的方法來(lái)實(shí)時(shí)傳遞兩個(gè)控件的內(nèi)容。Sample:
MapAndPageLayoutSynchApp精選課件ppt3.3TOCControl控件TOCControl控件概述ITOCControl與ITOCControl2ITOCControlEvents應(yīng)用開發(fā)實(shí)例精選課件ppt3.3.1TOCControl控件概述
TOCControl要與一個(gè)“伙伴控件”協(xié)同工作?!盎锇榭丶笨梢允荕apControl、PageLayoutControl、SceneControl或GlobeControl。TOCControl用“伙伴控件”來(lái)顯示其地圖、圖層和符號(hào)體系內(nèi)容的一個(gè)交互式樹視圖,并保持其內(nèi)容與“伙伴控件”同步。例如,如果
“伙伴控件”是一個(gè)MapControl,而且從該MapControl中刪除了一個(gè)圖層,則該圖層也會(huì)從TOCControl中刪除。同樣地,如果終端用戶與TOCControl交互并取消了某個(gè)圖層的Visibility復(fù)選框,則該圖層在MapControl中不再可見。精選課件pptTOCControl的“伙伴控件”可以在設(shè)計(jì)時(shí)通過(guò)TOCControl屬性頁(yè)設(shè)置或用SetBuddyControl方法通過(guò)編程設(shè)置。TOCControl的主要接口有:ITOCControl、ITOCControl
2、ITOCControlEvents精選課件pptITOCControl與ITOCControl2ITOCControl接口是任何與TOCControl有關(guān)的任務(wù)的出發(fā)點(diǎn),如設(shè)置控件的外觀,設(shè)置伙伴控件,管理圖層的可見性和標(biāo)簽的編輯。精選課件pptITOCControlLabelEdit、LayerVisibilityEdit:Label、Visibility
editingstate.esriTOCControlAutomaticesriTOCControlManual精選課件ppt在C#.NET環(huán)境中,當(dāng)查詢接口到ITOCControl
或ITOCControl2時(shí),必須使用Object屬性或者容器指定代碼。
ITOCControlpTOCControl; pTOCControl=axTOCControl1.ObjectasITOCControl; 或pTOCControl=axTOCControl1.
GetOcx()asITOCControl;精選課件pptpublicvoidHitTest
(int
X,
int
Y,
ref
esriTOCControlItem
ItemType,
ref
IBasicMap
BasicMap,
ref
ILayer
Layer,
ref
object
Unk,
ref
object
Data);用于獲取用戶在TOCControl中點(diǎn)擊的信相關(guān)息。ItemType:TOCControl中項(xiàng)的類型,如none、map、layer、heading或legendclass.BasicMap:指定地圖
對(duì)象。Layer:ILayer對(duì)象。Unk
:ILegendGroup(圖例組,一個(gè)圖層可以有多種符號(hào)化方案)對(duì)象。Data:用戶點(diǎn)擊的圖例組中某個(gè)圖例的索引號(hào)(長(zhǎng)整型);聯(lián)合使用圖例組Unk和這個(gè)索引號(hào),可以獲得用戶點(diǎn)擊的圖例(legendclass);如果這個(gè)索引號(hào)為-1,表明用戶點(diǎn)擊的是圖例中的標(biāo)題頭。精選課件ppt精選課件pptIBasicMapmap=newMapClass();ILayerlayer=newFeatureLayerClass();objectother=newobject();objectindex=newobject();esriTOCControlItemitem=newesriTOCControlItem();axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);if(e.button==1)
//判斷用戶是否按了鼠標(biāo)左鍵{if(layer==null)return;
IFeatureLayerfeatureLayer=layerasIFeatureLayer;if(featureLayer==null)return;
IGeoFeatureLayergeoFeatureLayer=(IGeoFeatureLayer)
featureLayer;
精選課件pptILegendClasslegendClass=newLegendClassClass();ISymbolsymbol=null;if(otherisILegendGroup&&(int)index!=-1){legendClass=((ILegendGroup)other).get_Class((int)index);symbol=legendClass.Symbol;}if(symbol==null)return;symbol=GetSymbolByControl(symbol);//彈出符號(hào)選擇對(duì)話框讓用戶選擇新的符號(hào)if(symbol==null)return;legendClass.Symbol=symbol;this.Activate();axMapControl1.ActiveView.ContentsChanged();axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);axTOCControl1.Update();}精選課件pptprivateISymbolGetSymbolByControl(
ISymbolsymbolType){ISymbolsymbol=null;
IStyleGalleryItemstyleGalleryItem=null;esriSymbologyStyleClassstyleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;if(symbolTypeisIMarkerSymbol){styleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;}if(symbolTypeisILineSymbol){styleClass=esriSymbologyStyleClass.esriStyleClassLineSymbols;}if(symbolTypeisIFillSymbol){styleClass=esriSymbologyStyleClass.esriStyleClassFillSymbols;}
GetSymbolByControlFormsymbolForm=newGetSymbolByControlForm(styleClass);symbolForm.ShowDialog();styleGalleryItem=symbolForm.m_styleGalleryItem;if(styleGalleryItem==null)returnnull;symbol=styleGalleryItem.ItemasISymbol;symbolForm.Dispose();
this.Activate();returnsymbol;
}精選課件pptITOCControl2(Newin9.2)與ITOCControl相比,ITOCControl2多了以下1個(gè)屬性和2個(gè)方法:publicboolEnableLayerDragDrop{get;set;}:指示圖層是否可以拖放,以改變圖層的順序。publicvoidGetSelectedItem
(refesriTOCControlItemItemType,
refIBasicMapBasicMap,refILayerLayer,refobjectUnk,refobjectData):返回TOCControl中被選擇項(xiàng)。publicvoidSelectItem(objectUnk,
objectData):用于設(shè)置TOCControl中的選擇項(xiàng),如:精選課件ppt//SelectingthefocusmapaxTOCControl1.SelectItem(
axTOCControl1.ActiveView.FocusMap);//SelectingalayerinthefocusmapaxTOCControl1.SelectItem
(axTOCControl1.ActiveView.FocusMap.get_Layer(0));//ToselectanitemwithinaLegendGroupILayerlayer=axTOCControl1.ActiveView.FocusMap.get_Layer(0);ILegendInfolegendInfo=(ILegendInfo)layer;ILegendGrouplegendGroup=legendInfo.get_LegendGroup(0);//SelectaheadingaxTOCControl1.SelectItem
(legendGroup);//SelectalegendclassaxTOCControl1.SelectItem
(legendGroup,2);精選課件pptITOCControlEventsITOCControlEvents是一個(gè)事件接口,它定義了TOCControl能夠處理的全部事件,如OnMouseDown、OnMouseMove、OnMouseUp、OnDoubleClick、OnBeginLabelEdit、OnEndLabelEdit、OnKeyDown、OnKeyUp。精選課件ppt
privatevoidaxTOCControl1_OnBeginLabelEdit
(objectsender,ITOCControlEvents_OnBeginLabelEditEvente){
…………m_TOCControl.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);//已在其它地方(如窗體的Load事件中)聲明為ITOCControl類型的變量,并已實(shí)例化if(item!=esriTOCControlItem.esriTOCControlItemLayer){e.canEdit=false;}}精選課件ppt
privatevoidaxTOCControl1_OnEndLabelEdit(objectsender,ITOCControlEvents_OnEndLabelEditEvente){//Preventemptylabelsif(e.newLabel.Trim()==""){e.canEdit=false;}}精選課件pptSamplesTOCControlContextMenuTOCControlLayerDragDropTOCControlMetadataViewer精選課件ppt3.3.2應(yīng)用開發(fā)實(shí)例TOC的右鍵菜單在ArcMap中,“TableofContents”中右鍵菜單功能非常豐厚,而TOCControl控件并沒有提供右鍵菜單功能。要實(shí)現(xiàn)右鍵菜單功能,需要開發(fā)人員自己編程實(shí)現(xiàn)。精選課件ppt當(dāng)右鍵點(diǎn)擊地圖時(shí),彈出當(dāng)右鍵點(diǎn)擊圖層時(shí),彈出精選課件ppt
首先要實(shí)現(xiàn)好右鍵菜單上的命令privatevoidMainForm_Load(objectsender,EventArgse)定義地圖右鍵菜單、圖層右鍵菜單privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)根據(jù)右鍵點(diǎn)擊的對(duì)象,彈出相應(yīng)的右鍵菜單精選課件ppt
IToolbarMenu
m_TocLayerMenu=newToolbarMenuClass();
IToolbarMenu
m_TocMapMenu=newToolbarMenuClass();privatevoidMainForm_Load(objectsender,EventArgse){……//TOCControl圖層右鍵菜單
m_TocLayerMenu.AddItem(newOpenAttributeTableCmd(),0,0,false,esriCommandStyles.esriCommandStyleIconAndText);m_TocLayerMenu.AddItem(newRemoveLayerCmd(),0,1,false,esriCommandStyles.esriCommandStyleIconAndText);
m_TocLayerMenu.AddItem(newScaleThresholds(),1,2,true,esriCommandStyles.esriCommandStyleTextOnly);m_TocLayerMenu.AddItem(newScaleThresholds(),2,3,false,esriCommandStyles.esriCommandStyleTextOnly);精選課件pptm_TocLayerMenu.AddItem(newScaleThresholds(),3,4,false,esriCommandStyles.esriCommandStyleTextOnly);
m_TocLayerMenu.AddItem(newLayerSelectable(),1,5,true,esriCommandStyles.esriCommandStyleTextOnly);m_TocLayerMenu.AddItem(newLayerSelectable(),2,6,false,esriCommandStyles.esriCommandStyleTextOnly);m_TocLayerMenu.AddItem(newZoomToLayerCmd(),0,7,true,esriCommandStyles.esriCommandStyleIconAndText);m_TocLayerMenu.AddItem(newLayerPropertiesCmd(),0,8,false,esriCommandStyles.esriCommandStyleIconAndText);m_TocLayerMenu.SetHook(axMapControl1);……}精選課件pptprivatevoidaxTOCControl1_OnMouseDown
(objectsender,ITOCControlEvents_OnMouseDownEvente){……axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);if(e.button==2){if(item==esriTOCControlItem.esriTOCControlItemMap){m_mapControl.CustomProperty=mapasIMap;
m_TocMapMenu.PopupMenu(e.x,e.y,axTOCControl1.hWnd);}elseif(layerisIFeatureLayer){m_mapControl.CustomProperty=layer;
m_TocLayerMenu.PopupMenu(e.x,e.y,axTOCControl1.hWnd);}}精選課件pptpublicsealedclassOpenAttributeTableCmd:BaseCommand{……publicoverridevoidOnClick(){IMapmap=null;if(m_hookHelper.HookisIMapControl3){m_mapcontrol=m_hookHelper.HookasIMapControl3;
currentLayer=m_mapcontrol.CustomPropertyasIFeatureLayer;if(currentLayer==null)return;map=m_mapcontrol.Map;}if(map==null)return;
LayerAttributeslayerAttributeTable=newLayerAttributes(map,currentLayer);layerAttributeTable.Show(m_hookHelperasSystem.Windows.Forms.IWin32Window);}
}精選課件pptpublicpartialclassLayerAttributes:Form{……
DataSetm_layerDataSet=newDataSet(m_dataSetName);privateSystem.Windows.Forms.DataGridViewdataGridView1;publicLayerAttributes(IMapmap,IFeatureLayerfeatureLayer){InitializeComponent();m_map=map;m_activeView=mapasIActiveView;currentLayer=featureLayer;}精選課件pptprivatevoidAttributesForm_Load(objectsender,EventArgse){this.Text=currentLayer.Name+"屬性表";introwCount=ConstructDataSet(currentLayer);
dataGridView1.DataSource=m_layerDataSet;dataGridView1.DataMember=currentLayer.Name;toolStripStatusLabel1.Text="選擇記錄數(shù):";toolStripStatusLabel2.Text="總記錄數(shù):"+currentLayer.FeatureClass.FeatureCount(null).ToString();}精選課件pptprivateintConstructDataSet(
IFeatureLayerpFeatLyr){ILayerFieldspFeatlyrFields=pFeatLyrasILayerFields;
IFeatureClasspFeatCls=pFeatLyr.FeatureClass;introws=0;if(m_layerDataSet.Tables[pFeatLyr.Name]==null){DataTablepTable=newDataTable(pFeatLyr.Name);DataColumnpTableCol;for(inti=0;i<=pFeatlyrFields.FieldCount-1;i++){pTableCol=newDataColumn(pFeatlyrFields.get_Field(i).AliasName);pTable.Columns.Add(pTableCol);pTableCol=null;}精選課件pptIFeatureCursorfeatures=pFeatLyr.Search(null,false);IFeaturefeature=features.NextFeature();while(feature!=null){DataRowpTableRow=pTable.NewRow();
for(inti=0;i<=pFeatlyrFields.FieldCount-1;i++){if(pFeatlyrFields.FindField(pFeatCls.ShapeFieldName)==i){pTableRow[i]=pFeatCls.ShapeType;}else{pTableRow[i]=feature.get_Value(i);}}pTable.Rows.Add(pTableRow);feature=features.NextFeature();}rows=pTable.Rows.Count;m_layerDataSet.Tables.Add(pTable);}returnrows;}精選課件ppt3.4ToolbarControl及相關(guān)對(duì)象ToolbarControl控件ToolbarControl上的命令ToolbarItem更新命令ToolbarMenu組件類ToolbarPaletteCommandPool操作棧(OperationStack)定制精選課件ppt
3.4.1ToolbarControl控件ToolbarControl使用鉤子(hook)來(lái)聯(lián)系命令對(duì)象與MapControl
或PageLayoutControl
等控件,并提供屬性、方法、事件用于:管理控件的外觀;設(shè)置伙伴控件;添加、刪除命令項(xiàng);設(shè)置當(dāng)前工具;定制工具。ToolbarControl要與一個(gè)“伙伴控件”協(xié)同工作?!盎锇榭丶笨梢允荕apControl、PageLayoutControl、SceneControl或GlobeControl。“伙伴控件”可以在設(shè)計(jì)時(shí)通過(guò)ToolbarControl屬性頁(yè)設(shè)置或用SetBuddyControl方法通過(guò)編程設(shè)置。精選課件pptToolbarControl主要接口有:IToolbarControlIToolbarControl2(Newin9.2)IToolbarControlDefaultIToolbarControlEvents(default)
精選課件pptIToolbarControl與IToolbarControl2IToolbarControl2接口是任何與ToolbarControl有關(guān)的任務(wù)的出發(fā)點(diǎn),如設(shè)置控件的外觀,設(shè)置伙伴控件,添加或去除命令、工具、菜單,定制ToolbarControl的內(nèi)容。IToolbarControl接口提供的主要屬性Buddy、CommandPool、CurrentTool、Customize、CustomProperty、Enabled、Object、OperationStack
、ToolTips、TextAlignment、UpdateInterval等。IToolbarControl接口提供的主要方法
AddItem、AddMenuItem、AddToolbarDef、Find、GetItem、GetItemRect、HitTest、MoveItem、Remove、RemoveAll、SetBuddyControl、Update等。精選課件pptIToolbarControl2(Newin9.2)與IToolbarControl相比,IToolbarControl2增加了以下:publicboolAlignLeft{get;set;}publicuintBackColor{get;set;}publicuintFadeColor{get;set;}publicesriToolbarFillDirectionFillDirection{get;set;}publicintIconSize{get;set;}publicvoidLoadItems(IStreampStream);publicesriToolbarOrientationOrientation{get;set;}publicvoidSaveItems(IStreampStream);publicboolShowHiddenItems{get;set;}publicboolThemedDrawing{get;set;}:是否有后面的圓角矩形。publicboolTransparent{get;set;}精選課件pptThemedDrawing為trueThemedDrawing為false精選課件ppt
IToolbarControlDefault在絕大多數(shù)開發(fā)環(huán)境中,在容器(窗體)中放置ToolbarControl控件,將產(chǎn)生一個(gè)名叫axToolbarControl1的對(duì)象,這個(gè)對(duì)象上直接可用的屬性和方法對(duì)應(yīng)于IToolbarControlDefault接口上的屬性和方法,加上容器特有的屬性和方法。IToolbarControlDefault接口的屬性和方法,與ToolbarCont
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 玩具設(shè)計(jì)師節(jié)假日后復(fù)工安全考核試卷含答案
- 電信運(yùn)營(yíng)商服務(wù)流程與規(guī)范(標(biāo)準(zhǔn)版)
- 炭素成型工春節(jié)假期安全告知書
- 藥品研發(fā)與生產(chǎn)管理指南
- 金融審計(jì)與風(fēng)險(xiǎn)評(píng)估操作手冊(cè)
- 2025年企業(yè)環(huán)境保護(hù)與可持續(xù)發(fā)展手冊(cè)
- 化妝培訓(xùn)課件制作app
- 2025年教師資格證考試試題真題及答案
- 婦幼保健院兒童疫苗接種指南與操作規(guī)范管理制度
- 生產(chǎn)法及相關(guān)法律知識(shí)能力提升試題D卷 附答案
- DBJT45-007-2012 廣西壯族自治區(qū)先張法預(yù)應(yīng)力混凝土管樁基礎(chǔ)技術(shù)規(guī)程
- 2024-2025學(xué)年肇慶市高一語(yǔ)文第一學(xué)期期末統(tǒng)考試卷附答案解析
- 《鹽山縣城市污水處理廠BOT項(xiàng)目》項(xiàng)下特許經(jīng)營(yíng)權(quán)等資產(chǎn)評(píng)估報(bào)告書
- 北師大版八年級(jí)上冊(cè)數(shù)學(xué)期末考試試卷及答案
- 電力設(shè)施圍欄施工方案
- 學(xué)習(xí)《教師法》和《嚴(yán)禁教師違規(guī)收受學(xué)生及家長(zhǎng)禮品禮金等行為的規(guī)定》心得體會(huì)
- 2023年廣西區(qū)考公務(wù)員錄用考試《行測(cè)》真題及答案解析
- GB/T 23444-2024金屬及金屬?gòu)?fù)合材料吊頂板
- 應(yīng)用麻醉鎮(zhèn)痛技術(shù)施行負(fù)壓吸宮術(shù)技術(shù)規(guī)范
- 國(guó)家電網(wǎng)公司招聘高校畢業(yè)生應(yīng)聘登記表
- 見證取樣手冊(cè)(智能建筑分部)
評(píng)論
0/150
提交評(píng)論