GIS二次開發(fā)03_第1頁(yè)
GIS二次開發(fā)03_第2頁(yè)
GIS二次開發(fā)03_第3頁(yè)
GIS二次開發(fā)03_第4頁(yè)
GIS二次開發(fā)03_第5頁(yè)
已閱讀5頁(yè),還剩35頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、第三講第三講 Application Framework 03主要內(nèi)容主要內(nèi)容pArcGIS Base Classp自定義自定義Command,Tool的方法的方法p自定義自定義Toolbar,Menu的方法的方法p簡(jiǎn)單的簡(jiǎn)單的MapControl Applicationp添加右鍵菜單添加右鍵菜單p創(chuàng)建動(dòng)態(tài)菜單創(chuàng)建動(dòng)態(tài)菜單p自定義地圖瀏覽程序自定義地圖瀏覽程序ArcGIS Base Classp程序集程序集ESRI.ArcGIS.ADFn包含包含Base Class,都是抽象類,只能用于繼承,而,都是抽象類,只能用于繼承,而不能實(shí)例化不能實(shí)例化n用戶通過繼承用戶通過繼承Base Class創(chuàng)建

2、自己的組件創(chuàng)建自己的組件n只能繼承于其中一個(gè)類只能繼承于其中一個(gè)類ArcGIS Base Classp可以被繼承的類可以被繼承的類ArcGIS item templates自定義自定義Command,Tool的方法的方法p實(shí)現(xiàn)實(shí)現(xiàn)ICommand接口接口n必須重寫必須重寫OnCreate,OnClick方法方法p實(shí)現(xiàn)實(shí)現(xiàn)ITool接口接口n重寫重寫OnCreate,OnMouseDown,OnMouseMove,OnMouseUp方法方法p繼承繼承BaseCommand,BaseTool類類n這兩個(gè)基類提供了這兩個(gè)基類提供了ICommand或或ITool接口所有方接口所有方法的通用實(shí)現(xiàn)代碼,根

3、據(jù)需要重寫其中的方法法的通用實(shí)現(xiàn)代碼,根據(jù)需要重寫其中的方法nBaseCommand的的OnCreate方法必須重寫方法必須重寫n屬性根據(jù)自己需要重新賦值屬性根據(jù)自己需要重新賦值自定義自定義Command,Tool的方法的方法p基類各屬性值基類各屬性值自定義自定義Command,Tool的方法的方法p使用使用ArcGIS Item Templates添加添加nArcGIS Base Command和和Base Tool templates繼承于抽象類繼承于抽象類BaseCommand和和BaseTooln自動(dòng)添加資源文件,如圖標(biāo)文件自動(dòng)添加資源文件,如圖標(biāo)文件n自動(dòng)重寫自動(dòng)重寫OnCreate

4、方法,將傳進(jìn)來的方法,將傳進(jìn)來的Hook賦值給賦值給相應(yīng)屬性相應(yīng)屬性p通過通過IHookHelper類型的對(duì)象與類型的對(duì)象與“鉤子鉤子”對(duì)象相關(guān)聯(lián)對(duì)象相關(guān)聯(lián)n自動(dòng)添加自定義自動(dòng)添加自定義Command和和Tool的的GUID自定義自定義Command,Tool的方法的方法自定義自定義Toolbar,Menu的方法的方法p實(shí)現(xiàn)實(shí)現(xiàn)IToolbarDef接口接口n用用IToolbarControl.AddToolbarDef方法將自定方法將自定義的工具添加到已有的工具條上義的工具添加到已有的工具條上p實(shí)現(xiàn)實(shí)現(xiàn)IMenuDef接口接口nDesktopp右鍵菜單,實(shí)現(xiàn)右鍵菜單,實(shí)現(xiàn)IMenuDef,I

5、ShortcutMenu接口接口p一般菜單,實(shí)現(xiàn)一般菜單,實(shí)現(xiàn)IMenuDef,IRootLevelMenu接口接口nEnginep實(shí)現(xiàn)實(shí)現(xiàn)IToolbarMenu接口接口自定義自定義Toolbar,Menu的方法的方法p繼承繼承BaseToolbar,BaseMenu類類n重載的重載的AddItem方法,可以根據(jù)方法,可以根據(jù)UID,ProgID,CLSID,System.Guid,System.Type添加項(xiàng)目添加項(xiàng)目n若添加項(xiàng)目時(shí),若添加項(xiàng)目時(shí),ID出錯(cuò),則運(yùn)行時(shí)在出錯(cuò),則運(yùn)行時(shí)在CommandBar上顯示占位符上顯示占位符nBeginGroup方法用來添加分隔線方法用來添加分隔線自定義

6、自定義Toolbar,Menu的方法的方法p使用使用ArcGIS Item Templates添加添加簡(jiǎn)單的簡(jiǎn)單的MapControl Appplicationp運(yùn)用運(yùn)用ArcGIS集成開發(fā)環(huán)境創(chuàng)建集成開發(fā)環(huán)境創(chuàng)建p已有的已有的Command對(duì)象的用法對(duì)象的用法p基于基于BaseCommand類創(chuàng)建自定義類創(chuàng)建自定義Command類類nIHookHelper添加右鍵菜單添加右鍵菜單p向已有項(xiàng)目中添加向已有項(xiàng)目中添加ContextMenup向自定義向自定義ContextMenu中加中加Command對(duì)象對(duì)象nSetHook()方法方法nAddItem()方法方法nUID對(duì)象對(duì)象nGuid結(jié)構(gòu):表

7、示全局唯一標(biāo)識(shí)符結(jié)構(gòu):表示全局唯一標(biāo)識(shí)符 public void SetHook(object hook) m_toolbarMenu = new ToolbarMenuClass(); m_toolbarMenu.SetHook(hook); / / TODO: Define context menu items here / AddItem(esriControls.ControlsMapZoomOutFixedCommand, -1); AddItem(esriControls.ControlsMapZoomInFixedCommand, -1); BeginGroup(); /Sepa

8、rator AddItem(380FB31E-6C24-4F5C-B1DF-47F33586B885, -1); /undo command AddItem(new Guid(B0675372-0271-4680-9A2C-269B3F0C01E8), -1); /redo command /BeginGroup(); /Separator /AddItem(MyCustomCommandCLSIDorProgID, -1);添加右鍵菜單添加右鍵菜單p實(shí)例化右鍵菜單(實(shí)例化右鍵菜單(ContextMenu)對(duì)象)對(duì)象nprivate EngineContextMenu1 m_contextMe

9、nu = new EngineContextMenu1();p將右鍵菜單對(duì)象將右鍵菜單對(duì)象“鉤鉤”到相應(yīng)的到相應(yīng)的AE控件上控件上n /get the MapControlnm_mapControl = (IMapControl3)axMapControl1.Object;nm_contextMenu.SetHook(m_mapControl);添加右鍵菜單添加右鍵菜單p當(dāng)窗體上已經(jīng)存在當(dāng)窗體上已經(jīng)存在ToolBarControl時(shí),應(yīng)將時(shí),應(yīng)將IToolBarMenu的的CommandPool屬性設(shè)置屬性設(shè)置為為ToolBarControl的的CommandPool屬性值,屬性值,以保證添加

10、到工具條控件和右鍵菜單的以保證添加到工具條控件和右鍵菜單的Command對(duì)象的唯一性對(duì)象的唯一性添加右鍵菜單添加右鍵菜單 /get the MapControlm_mapControl = (IMapControl3)axMapControl1.Object;IToolbarControl toolBarControl = (IToolbarControl)axToolbarControl1.Object;m_contextMenu.SetHook(toolBarControl.Buddy);IToolbarMenu2 toolBarMenu = m_contextMenu.ContextMe

11、nu;toolBarMenu.CommandPool = toolBarControl.CommandPool;添加右鍵菜單添加右鍵菜單p在右鍵菜單的關(guān)聯(lián)在右鍵菜單的關(guān)聯(lián)AE控件右鍵單擊事件中添加代控件右鍵單擊事件中添加代碼,顯示菜單碼,顯示菜單 if (e.button = 2) m_contextMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);UIDClasspCOM組件中的接口(組件中的接口(interface)與)與coclass(類)用(類)用全局唯一標(biāo)識(shí)(全局唯一標(biāo)識(shí)(Globally Unique Identifier)進(jìn)行)進(jìn)行區(qū)分區(qū)分

12、p接口的接口的GUID稱為接口稱為接口ID,即,即IIDpcoclass的的GUID稱為類稱為類ID,即,即CLSIDpProgID為為CLSID的別名,由項(xiàng)目名與類名組成的別名,由項(xiàng)目名與類名組成p已有的已有的Command,Menu等對(duì)象的等對(duì)象的GUID/ProgID對(duì)照表:對(duì)照表:nEngine Developer Help-Building solutions with ArcGIS Engine using .NET-General reference-Commands in ArcGIS EngineUIDClass補(bǔ)充補(bǔ)充pGUID,ProgID ,CLSID和和UIDnGUI

13、D(全局統(tǒng)一標(biāo)識(shí)符全局統(tǒng)一標(biāo)識(shí)符)是用來標(biāo)識(shí)識(shí)別是用來標(biāo)識(shí)識(shí)別COM接口和組件,保證它們的接口和組件,保證它們的唯一性,避免出現(xiàn)版本不一致而導(dǎo)致的組件沖突唯一性,避免出現(xiàn)版本不一致而導(dǎo)致的組件沖突.IID就是接口的就是接口的GUID表示,表示,CLSID則是組件類的則是組件類的GUID表示。表示。ProgID是程序員給某個(gè)是程序員給某個(gè)CLSID指定一個(gè)易記的名字指定一個(gè)易記的名字.UID則是則是對(duì)對(duì)象(象(Object)的的GUID.nESRI接口存放在注冊(cè)表中的接口存放在注冊(cè)表中的 HKEY_CLASSES_ROOT下面,如果想下面,如果想查詢它們的查詢它們的UID,可以通過查找它們的名字

14、,從而找到對(duì)應(yīng)的,可以通過查找它們的名字,從而找到對(duì)應(yīng)的UID。以。以下是一些下是一些ILayer接口的接口的UID:6CA416B1-E160-11D2-9F4E-00C04F6BC78E IDataLayer40A9E885-5533-11d0-98BE-00805F7CED21 IFeatureLayerE156D7E5-22AF-11D3-9F99-00C04F6BC78E IGeoFeatureLayer34B2EF81-F4AC-11D1-A245-080009B6F22B IGraphicsLayer5CEAE408-4C0A-437F-9DB3-054D83919850 IFD

15、OGraphicsLayerEDAD6644-1810-11D1-86AE-0000F8751720 IGroupLayerD02371C7-35F7-11D2-B1F2-00C04F8EDEFF IRasterLayer創(chuàng)建動(dòng)態(tài)菜單創(chuàng)建動(dòng)態(tài)菜單p實(shí)現(xiàn)實(shí)現(xiàn)IMultiItem,IMulitItemEx(可選)接(可選)接口口p不需要實(shí)現(xiàn)不需要實(shí)現(xiàn)ICommand接口,不能添加到接口,不能添加到Customize Dialog Box的的Command List中,只能在菜單上出現(xiàn),擁有不確定數(shù)目的菜單中,只能在菜單上出現(xiàn),擁有不確定數(shù)目的菜單項(xiàng)項(xiàng)創(chuàng)建動(dòng)態(tài)菜單創(chuàng)建動(dòng)態(tài)菜單p步驟步驟n用用ArcG

16、IS Item Templates添加添加ArcGIS Class創(chuàng)建動(dòng)態(tài)菜單創(chuàng)建動(dòng)態(tài)菜單p步驟步驟n添加添加IHookHelper類型的私有成員類型的私有成員pprivate ESRI.ArcGIS.Controls.IHookHelper m_hookHelper;n實(shí)現(xiàn)實(shí)現(xiàn)Caption, Name, Message, HelpContextID, HelpFile等屬性等屬性n實(shí)現(xiàn)實(shí)現(xiàn)OnPopUp方法,該方法在包含方法,該方法在包含MultiItem的菜單出現(xiàn)之的菜單出現(xiàn)之前被調(diào)用,實(shí)現(xiàn)兩個(gè)功能,獲取鉤子對(duì)象,返回前被調(diào)用,實(shí)現(xiàn)兩個(gè)功能,獲取鉤子對(duì)象,返回MultiItem包含包含的

17、子項(xiàng)目數(shù)的子項(xiàng)目數(shù)n在在OnPopUp方法被調(diào)用之后,方法被調(diào)用之后,framework為每個(gè)子項(xiàng)創(chuàng)建一為每個(gè)子項(xiàng)創(chuàng)建一個(gè)個(gè)CommandItem,并且指定每個(gè)子項(xiàng)的,并且指定每個(gè)子項(xiàng)的ItemBitmap,ItemCaption,ItemChecked,ItemEnabled屬性屬性創(chuàng)建動(dòng)態(tài)菜單創(chuàng)建動(dòng)態(tài)菜單p步驟步驟n添加該添加該OnItemClick方法的實(shí)現(xiàn)代碼,當(dāng)包含的菜方法的實(shí)現(xiàn)代碼,當(dāng)包含的菜單項(xiàng)都顯示出來以后,用戶點(diǎn)擊后則調(diào)用該方法單項(xiàng)都顯示出來以后,用戶點(diǎn)擊后則調(diào)用該方法n實(shí)現(xiàn)實(shí)現(xiàn)IMulitItemEx接口(可選)接口(可選)n將該類注冊(cè)到相關(guān)的目錄下,使用將該類注冊(cè)到相關(guān)的

18、目錄下,使用“Add Component Category”工具工具n顯示動(dòng)態(tài)菜單顯示動(dòng)態(tài)菜單自定義地圖瀏覽程序自定義地圖瀏覽程序p加載加載ArcGIS Engine Controlp添加引用添加引用nProject-Add ArcGIS Referencep將控件拖放到窗口上將控件拖放到窗口上n修改窗體名稱修改窗體名稱nMapControl, PageLayoutControl, ToolbarControl, TOCControl, LicenseControlp添加命名空間添加命名空間nusing ESRI.ArcGIS.Carto; nusing ESRI.ArcGIS.Control

19、s; nusing ESRI.ArcGIS.Display; nusing ESRI.ArcGIS.Geometry; nusing ESRI.ArcGIS.SystemUI; nusing ESRI.ArcGIS.esriSystem;自定義地圖瀏覽程序自定義地圖瀏覽程序p配置配置Licensep加載地圖文件到加載地圖文件到MapControl,TOCControlstring fileName = .dataGulf_of_St._Lawrence.mxd;if (axPageLayoutControl1.CheckMxFile(fileName) axPageLayoutControl1

20、.LoadMxFile(fileName, ); 自定義地圖瀏覽程序自定義地圖瀏覽程序p當(dāng)當(dāng)PageLayoutControl中的地圖文件發(fā)生變中的地圖文件發(fā)生變化時(shí),更新化時(shí),更新MapControl的顯示內(nèi)容的顯示內(nèi)容private void axPageLayoutControl1_OnPageLayoutReplaced(object sender, IPageLayoutControlEvents_OnPageLayoutReplacedEvent e) /Load the same pre-authored map document into the MapControl. axM

21、apControl1.LoadMxFile(axPageLayoutControl1.DocumentFilename, null, null); /Set the extent of the MapControl to the full extent of the data. axMapControl1.Extent = axMapControl1.FullExtent; 自定義地圖瀏覽程序自定義地圖瀏覽程序p設(shè)置伙伴控件設(shè)置伙伴控件p錨定控件錨定控件n設(shè)置各控件的設(shè)置各控件的anchor屬性屬性private void MapViewer_Load(object sender, Syste

22、m.EventArgs e) /Set buddy controls. axTOCControl1.SetBuddyControl(axPageLayoutControl1); axToolbarControl1.SetBuddyControl(axPageLayoutControl1); 自定義地圖瀏覽程序自定義地圖瀏覽程序p當(dāng)窗體大小改變時(shí),阻止當(dāng)窗體大小改變時(shí),阻止MapControl,PageLayoutControl中的地圖不斷自動(dòng)重繪中的地圖不斷自動(dòng)重繪private void MapViewer_ResizeBegin(object sender, EventArgs e) /S

23、uppress data redraw and draw bitmap instead. axMapControl1.SuppressResizeDrawing(true, 0); axPageLayoutControl1.SuppressResizeDrawing(true, 0); private void MapViewer_ResizeEnd(object sender, EventArgs e) /Stop bitmap draw and draw data. axMapControl1.SuppressResizeDrawing(false, 0); axPageLayoutCon

24、trol1.SuppressResizeDrawing(false, 0); 自定義地圖瀏覽程序自定義地圖瀏覽程序p添加工具條命令添加工具條命令private void MapViewer_Load(object sender, EventArgs e) /Add generic commands. axToolbarControl1.AddItem(esriControls.ControlsOpenDocCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.Add

25、Item(esriControls.ControlsAddDataCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); /Add page layout navigation commands. axToolbarControl1.AddItem(esriControls.ControlsPageZoomInTool, - 1, - 1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(es

26、riControls.ControlsPageZoomOutTool, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsPagePanTool, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsPageZoomWholePageCommand, -

27、 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);/Add map navigation commands. axToolbarControl1.AddItem(esriControls.ControlsMapZoomInTool, - 1, - 1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsMapZoomOutTool, - 1, - 1, false, 0

28、, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsMapPanTool, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsMapFullExtentCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOn

29、ly); axToolbarControl1.AddItem(esriControls.ControlsMapZoomToLastExtentBackCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem( esriControls.ControlsMapZoomToLastExtentForwardCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);/Add

30、 map inquiry commands. axToolbarControl1.AddItem(esriControls.ControlsMapIdentifyTool, - 1, - 1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem(esriControls.ControlsMapFindCommand, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.Add

31、Item(esriControls.ControlsMapMeasureTool, - 1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); /Set buddy controls.自定義地圖瀏覽程序自定義地圖瀏覽程序p為為PageLayoutControl添加右鍵菜單添加右鍵菜單public partial class MapViewer: Form /The pop-up menu. private IToolbarMenu m_ToolbarMenu;private void MapViewer_Load(objec

32、t sender, EventArgs e) /Create a new ToolbarMenu. m_ToolbarMenu = new ToolbarMenuClass(); /Share the ToolbarControls command pool. m_ToolbarMenu.CommandPool = axToolbarControl1.CommandPool; /Set the hook to the PageLayoutControl. m_ToolbarMenu.SetHook(axPageLayoutControl1); /Add commands to the Tool

33、barMenu. m_ToolbarMenu.AddItem(esriControls.ControlsPageZoomInFixedCommand, - 1, - 1, false, esriCommandStyles.esriCommandStyleIconAndText); m_ToolbarMenu.AddItem(esriControls.ControlsPageZoomOutFixedCommand, - 1, - 1, false, esriCommandStyles.esriCommandStyleIconAndText); m_ToolbarMenu.AddItem(esri

34、Controls.ControlsPageZoomWholePageCommand, - 1, -1, false, esriCommandStyles.esriCommandStyleIconAndText); m_ToolbarMenu.AddItem(esriControls.ControlsPageZoomPageToLastExtentBackCommand, - 1, - 1, true, esriCommandStyles.esriCommandStyleIconAndText);m_ToolbarMenu.AddItem(esriControls.ControlsPageZoo

35、mPageToLastExtentForwardCommand, - 1, - 1, false, esriCommandStyles.esriCommandStyleIconAndText);private void axPageLayoutControl1_OnMouseDown(object sender, IPageLayoutControlEvents_OnMouseDownEvent e) /Pop-up the ToolbarMenu. if (e.button = 2) m_ToolbarMenu.PopupMenu(e.x, e.y, axPageLayoutControl1

36、.hWnd);顯示右鍵菜單顯示右鍵菜單private void MapViewer_Load(object sender, EventArgs e) /Create a new ToolbarPalette. IToolbarPalette toolbarPalette = new ToolbarPaletteClass(); /Add commands and tools to the ToolbarPalette. toolbarPalette.AddItem(esriControls.ControlsNewMarkerTool, - 1, - 1); toolbarPalette.AddItem(esriControls.ControlsNewLineTool, - 1, - 1); toolbarPalette.AddItem(esriControls.ControlsNewCircleTool, - 1, - 1); toolbarPalette.AddIt

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論