GIS应用开发课件3

上传人:壹****1 文档编号:588083083 上传时间:2024-09-07 格式:PPT 页数:154 大小:1.37MB
返回 下载 相关 举报
GIS应用开发课件3_第1页
第1页 / 共154页
GIS应用开发课件3_第2页
第2页 / 共154页
GIS应用开发课件3_第3页
第3页 / 共154页
GIS应用开发课件3_第4页
第4页 / 共154页
GIS应用开发课件3_第5页
第5页 / 共154页
点击查看更多>>
资源描述

《GIS应用开发课件3》由会员分享,可在线阅读,更多相关《GIS应用开发课件3(154页珍藏版)》请在金锄头文库上搜索。

1、江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETGIS GIS 应应 用用 开开 发发Developing GIS Applications with ArcObjects using Developing GIS Applications with ArcObjects using C#.NETC#.NET 江西理工大学Developing GIS Applications with ArcObjects

2、using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET教学目教学目标lGIS应用开用开发课程是程是GIS研究生重要的研究生重要的专业课程,通程,通过课程的学程的学习,了解了解ArcGIS软件体系件体系结构及构及ArcObjects (ArcGIS Engine)组件构成,并能熟件构成,并能熟练使用使用ArcObjects(ArcGIS Engine)进行行应用用型型GIS开开发;掌握掌握应用型用型GIS开开发的基本思的基本思路、技路、技术方法方法.江西理工大学Developing GIS Applications

3、 with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETChap. 3 使用使用ArcObjects控件控件编程程(6学学时) l为了能了能够快速建构一个具有快速建构一个具有GIS功能的独立功能的独立应用程序,用程序,ArcGISEngine为开开发者提供了者提供了多个可多个可视化的化的组件即件即控控件件,如,如 LicenseControl、MapControl、PageLayoutControl、TOCControl、ToolbarControl和和SymbologyContr

4、ol等。等。 l在在VS.NET中使用中使用ArcObjects,需要使用,需要使用ESRIinterop程程序集,序集,这些程序集在托管的些程序集在托管的.NET代代码和非托管的和非托管的COM代代码之之间起了起了桥梁作用。梁作用。lESRIinterop程序集程序集为ArcGIS控件提供了能控件提供了能够位于位于.NET窗体上的控件窗体上的控件(继承自承自AxHost类),这些控件名前些控件名前缀为“Ax”,如,如AxMapControl、AxPageLayoutControl、AxTOCControl和和AxToolbarControl等。等。江西理工大学Developing GIS A

5、pplications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETUsingArcGISEnginecontrols in WinformsUsingArcGISEngineControlsinWPF江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET本章内容:本章内容:1.MapCont

6、rol控件控件 2.PageLayoutControl控件控件3.TOCControl控件控件4.ToolbarControl及相关及相关对象象5.ControlCommands(SymbologyControlinChapter6)6.6.在在WPF程序中使用程序中使用ArcGISEngine控控件件江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1 MapControl控件控件lMapControl对

7、应于于ArcMap中的数据中的数据视图,其主要功能其主要功能为空空间数据数据浏览、空、空间数据可数据可视化、空化、空间查询、空、空间分析、空分析、空间数据数据编辑等。等。l在可在可视化化环境中,可以通境中,可以通过控件的控件的“属性属性”页设置控件的相关属性,也可以通置控件的相关属性,也可以通过编程程来来设置。置。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS App

8、lications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlMapControl是是对Map对象象的封装的封装,并提供,并提供了了额外的属性、方法、事件用于:外的属性、方法、事件用于:1.1.管理控件的外管理控件的外观、显示属性和地示属性和地图属性;属性;2.2.添加并管理控件中的数据添加并管理控件中的数据层(datalayers););3.3.装装载Map文档(文档(mxd)到控件中;)到控件中;4.4.从其它从其它应用程序拖放数据到控件中;用程序拖放数据到控件中

9、;5.5.使用鼠使用鼠标拉拉绘几何形状并几何形状并绘制到屏幕制到屏幕显示中。示中。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.1 MapControl的的主要接口主要接口lMapControl实现的主要接口有:的主要接口有:IMapControlDefaultIMapControl2IMapControl3IMapControl4(newin9.2)IMapControlEvents2事件接口事件

10、接口ITOCBuddyIToolbarBuddy江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.1.1 IMapControlDefault接口接口lIMapControlDefault接口是地接口是地图控件缺省接口,多数控件缺省接口,多数开开发环境自境自动使用使用这个接口定个接口定义的属性、方法。的属性、方法。l由于由于MapControl是一个自是一个自动化控件,当它被放到一化控件,当它被放到一个

11、容器个容器-如窗体上后,它会自如窗体上后,它会自动产生一个被称生一个被称为axMapControl1的的对象,象,这个个对象可以直接使用缺省象可以直接使用缺省接口定接口定义的属性和方法的属性和方法。这个接口也代表了控件最新个接口也代表了控件最新版本的接口版本的接口,MapControl当前最新版本接口当前最新版本接口为IMapControl4.l当需要使用当需要使用这个接口的个接口的时候,可以使用下面的代候,可以使用下面的代码:IMapControlDefaultpMapControl=axMapControl1.ObjectasIMapControlDefault;江西理工大学Develop

12、ing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlIMapControl2.Extent:地地图图的可的可视视范范围围;lIMapControl2.FullExtent:地地图图中所有中所有图层图层的覆盖范的覆盖范围围.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects usi

13、ng C#.NET3.1.1.2 IMapControl4IMapControl4接口接口lIMapControl4是任何一个与是任何一个与MapControl相相关的任关的任务的出的出发点点,如,如设置控件外置控件外观,设置置Map对象或控件的象或控件的显示属性,添加或者管理示属性,添加或者管理图层、地、地图文档,在控件上文档,在控件上绘制制图形和返回形和返回Geometry等。等。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects

14、using C#.NETIMapControl2江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.1.3 IMapControl3与与IMapControl4lIMapC

15、ontrol3接口接口继承承IMapControl2,并,并增加了以下增加了以下8个个属性和一个方法属性和一个方法:CustomProperty-object:使用:使用该属性关属性关联有用信息有用信息DocumentFilename-string):返回:返回MapControl装入装入的地的地图文档的文件名文档的文件名DocumentMap-string:返回:返回MapControl最后装入的最后装入的地地图(Map)名称)名称KeyIntercept-int:返回或:返回或设置置MapControl截取截取键盘按按键信息信息江西理工大学Developing GIS Applicatio

16、ns with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETObject-object:返回潜在的返回潜在的MapControl控件,控件,当在当在VB.NET或或C#.NET中使用中使用IMapControl2时,一定要使,一定要使用用Object属性或者使用指定容器的代属性或者使用指定容器的代码。因因为对于于.NET,真正的控件是被包装于宿主,真正的控件是被包装于宿主对象里面的。象里面的。ShowMapTips-bool:确定是否确定是否显示地示地图的的MapTipsTipDe

17、lay-int:设置置MapTips的延的延迟时间TipStyle-esriTipStyle:设置置MapTips的的显示示样式式SuppressResizeDrawing():在控件尺寸在控件尺寸发生生变化化过程中,阻止数据程中,阻止数据实时重重绘江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl与与IMapControl3相比,相比,IMapControl4多了以下多了以下两两个可个可读写属性写属性:pu

18、blicboolAutoKeyboardScrollingget;set;:确确定是否使用定是否使用键盘上的上的Home(keyCode36)键、End(keyCode35)键、PageDown(keyCode34)键、PageUp(keyCode33)键和和箭箭头键(keyCode37-40)来平移控件中的地来平移控件中的地图,缺省情况下缺省情况下该属性属性为true.绝大多数开大多数开发环境使用箭境使用箭头键来切来切换窗体或容器中的焦窗体或容器中的焦点控件;在点控件;在这些开些开发环境中,缺省情况下境中,缺省情况下MapControl不会接收箭不会接收箭头键来平移地来平移地图的的显示。示。

19、为确保箭确保箭头键能能够被被MapControl接收并平移地接收并平移地图的的显示,示,KeyIntercept属性属性应设置置为拦截箭截箭头键(esriKeyInterceptArrowKeys),且且AutoKeyboardScrolling设置置为true。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETpublicboolAutoMouseWheelget;set;:确定鼠确定鼠标滚轮是否用于是否用于

20、缩放地放地图的的显示;示;缺省缺省情况下情况下该属性属性为true。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET引用控件本身引用控件本身l当使用当使用IMapControl2接口接口时:IMapControl2pMapControl=axMapControl1.ObjectasIMapControl2;或或IMapControl2pMapControl=axMapControl1.GetOcx()asIM

21、apControl2;l当使用当使用IMapControl3接口接口时:IMapControl3pMapControl=axMapControl1.ObjectasIMapControl3;或或IMapControl3pMapControl=axMapControl1.GetOcx()asIMapControl3;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl当使用当使用IMapControl4接口接口时

22、:IMapControl4pMapControl;pMapControl=axMapControl1.ObjectasIMapControl4;或或pMapControl=axMapControl1.GetOcx()asIMapControl4;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET使用箭使用箭头键头键、鼠、鼠标滚轮实现标滚轮实现地地图导图导航航l使用箭使用箭头键平移(平移(Panning)地)地图

23、axMapControl1.KeyIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;axMapControl1.AutoKeyboardScrolling=true;l使用鼠使用鼠标滚轮缩放地放地图axMapControl1.AutoMouseWheel=true;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETaxMapControl1.Ke

24、yIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;AutoKeyboardScrolling=true;ConstantValueDescriptionesriKeyInterceptNone0Nokeysareintercepted.esriKeyInterceptArrowKeys1Interceptsthearrowkeys,normallyhandledbythecontainer to change controlfocus.esriKeyInterceptAlt2InterceptstheAltkey,normal

25、lyhandled by a container tochangefocus.esriKeyInterceptTab4InterceptstheTabkey,normallyhandledbythecontainer to change controlfocus.esriKeyInterceptEnter8InterceptstheEnterkey,normallyhandledbythecontainer to click the defaultbutton.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDevel

26、oping GIS Applications with ArcObjects using C#.NET3.1.1.4 IMapControlEvents2接接口口lIMapControlEvents2是一个事件接是一个事件接口,它定口,它定义了了 MapControl能能够处理的全部事件,如理的全部事件,如 OnExtentUpdated是地是地图的的 Extent(可可视范范围)属性属性发生生变化化时触触发的事件的事件, OnAfterscreenDraw是是绘屏屏结束后束后触触发的事件等。的事件等。当地当地图的覆盖范的覆盖范围变化化时,触,触发OnFullExtentUpdated事件,事

27、件,例如,例如,往地往地图中新增加一个中新增加一个图层,其覆盖,其覆盖范范围大于原大于原图的范的范围。?江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl在在绝大多数开大多数开发环境中,没有必要手工境中,没有必要手工编写写代代码进行事件的注册,而行事件的注册,而只需在控件的属性只需在控件的属性窗口中双窗口中双击某事件自某事件自动进行事件与其行事件与其处理方理方法的关法的关联。江西理工大学Developing

28、GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.1.5ITOCBuddyl该接口定接口定义了以下了以下2个方法个方法:GetActiveViewReturnstheunderlyingobjectimplementingbasicmapandActiveView.ThisisusedtopopulatetheTOC.GetScaleReturnsthescaleofthesuppliedBasicMap,thisallowsforob

29、jectsthatdonotsupportIMap.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.1.6 IToolbarBuddy lObjectsthatimplementtheIToolbarBuddyinterfacecanbepassedtotheIToolbarControl.SetBuddyControlmethod.lTheCurrentToolisthetoolusedtointe

30、ractwiththedisplayareaoftheIToolbarControl.Buddy.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlSamples:1.MapAndPageLayoutSynchApp2.MapControlMapTips3.MapControlGeoEvents4.MapControlDrawText5.MapControlCADViewer6.MapControlSaveL

31、ayerFile江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlGuid.ToString(stringformat)命名空命名空间:System;程序集;程序集:mscorlibformat一个一个单格式格式说明符,它指示如何格式化此明符,它指示如何格式化此 Guid的的值。format参数可以是参数可以是“N”、“D”、“B”或或“P”。说明符明符 返回返回值的格式的格式 N32 位:位: xxxxxx

32、xxxxxxxxxxxxxxxxxxxxxxxxxx D由连字符分隔的由连字符分隔的 32 位数字:位数字: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx B括在大括号中、由连字符分隔的括在大括号中、由连字符分隔的 32 位数字:位数字: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx P括在圆括号中、由连字符分隔的括在圆括号中、由连字符分隔的 32 位数字:位数字: (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) 江西理工大学Developing GIS Applications with ArcObject

33、s using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.2 MapControl控件与控件与MXD文件文件lMapControl控件可以控件可以“链接接”或或“包含包含”地地图文档。文档。l对于文档文件,于文档文件,MapControl控件可以直控件可以直接使用接使用LoadMxFile方法来方法来载入,入,这是最是最简单的方法。的方法。除此之外,可以使用除此之外,可以使用IMapDocument接口定接口定义的属性和方法来的属性和方法来加加载一个一个MXD文件。文件。江西理工大学Developing

34、GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET下面是一个下面是一个载入文档的例子入文档的例子-axMapControl1.LoadMxFileprivatevoidLoadMapDocument() System.Windows.Forms.OpenFileDialogopenFileDialog2;openFileDialog2=newOpenFileDialog();openFileDialog2.Title=OpenMapDocume

35、nt;openFileDialog2.Filter=MapDocuments(*.mxd)|*.mxd;openFileDialog2.ShowDialog();stringsFilePath=openFileDialog2.FileName;if(axMapControl1.CheckMxFile(sFilePath)axMapControl1.LoadMxFile(sFilePath,0,Type.Missing);elseMessageBox.Show(sFilePath+isnotavalidArcMapdocument);return;江西理工大学Developing GIS App

36、lications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl在在ArcMap中使用的地中使用的地图文档文档对象象为MxDocument,其主要接口是,其主要接口是IMxDocument;在使用控件开在使用控件开发的独立的独立应用程序中,使用的地用程序中,使用的地图文档文档对象象为MapDocument,其主要接口是其主要接口是IMapDocument。lIMapDocument接口定接口定义了操作和管理文档了操作和管理文档对象象的方法和属性。的方法和属性。MapDo

37、cument类能能够封装地封装地图文文档文件,如档文件,如mxd、mxt和和pmf等,它也可以封装等,它也可以封装 一个一个图层文件(文件(* *.lyr)。)。使用使用这个个对象可以象可以获取取和更新一个文档的内容,和更新一个文档的内容,设置文档文件的置文档文件的读、写属、写属性,保存一个文档文件(性,保存一个文档文件(* *.mxd)。)。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIMxDocume

38、nt 与与IMapDocument江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIApplication的属性、方法的属性、方法江西理工大学Developing GIS Ap

39、plications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlIMxDocument.ActivatedView与与ActiveView属属性性在在ArcMap的布局的布局视图(layoutview)状状态下,下,图形元素形元素可以添加到可以添加到页面布局面布局(PageLayout)或焦点地或焦点地图(focusMap)的的图形元素容器形元素容器(graphicscontainer)中;中;这时,IMxDocument.ActiveView属性与属性与IMxDoc

40、ument.ActivatedView属性不同,属性不同,ActiveView属性引用属性引用PageLayout对象,象,ActivatedView属性引用属性引用焦点地焦点地图对象象(如果如果该地地图对象象处于活于活动状状态) 。在在ArcMap的数据的数据视图(dataview)状状态下,下, ActiveView与与ActivatedView属性都引用属性都引用焦点地焦点地图对象象。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjec

41、ts using C#.NETIMapDocumentm_MapDocument=newMapDocumentClass();privatevoidLoadMapDoc()OpenFileDialogopenFileDialog2=newOpenFileDialog();openFileDialog2.Title=OpenMapDocument;openFileDialog2.Filter=MapDocuments(*.mxd)|*.mxd;openFileDialog2.ShowDialog();stringsFilePath=openFileDialog2.FileName;If(m_Ma

42、pDocument.get_IsMapDocument(sFilePath))m_MapDocument.Open(sFilePath,);axMapControl1.Map=m_MapDocument.get_Map(0);axMapControl1.Refresh();public void public void OpenOpen ( ( stringstring sDocument, sDocument, stringstring bsPassword);bsPassword);public bool public bool get_IsMapDocumentget_IsMapDocu

43、ment ( (stringstring sDocument);sDocument);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETprivatevoidSaveDocument()if(m_MapDocument.get_IsReadOnly(m_MapDocument.DocumentFilename)=true)MessageBox.Show(Thismapdocumentisreadonly!);r

44、eturn;m_MapDocument.Save(m_MapDocument.UsesRelativePaths,true);MessageBox.Show(Changessavedsuccessfully!);public void public void SaveSave ( ( boolbool bUseRelativePaths, bUseRelativePaths, boolbool bCreateThumnbail);bCreateThumnbail);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDev

45、eloping GIS Applications with ArcObjects using C#.NET3.1.3 鼠鼠标与控件的交互与控件的交互l用鼠用鼠标和地和地图控件控件进行交互是最常用的操行交互是最常用的操作,例如作,例如改改变地地图显示范示范围、移移动地地图,在控件上在控件上绘制几何制几何图形形等。等。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET使用鼠使用鼠标拖曳确定地拖曳确定地图显示的范示的

46、范围(拉框放大拉框放大)privatevoidaxMapControl1_OnMouseDown (objectsender,ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente)/改改变地地图控件控件显示范示范围为当前拖曳的区域当前拖曳的区域 axMapControl1.Extent=axMapControl1.TrackRectangle();/刷新地刷新地图axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);public void pub

47、lic void RefreshRefresh ( ( esriViewDrawPhaseesriViewDrawPhase phase,phase, objectobject layerOrElement,layerOrElement, objectobject envelopeenvelope ); );江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET移移动、旋、旋转地地图l在在 MapControl中有

48、一种更中有一种更简单便利的方法便利的方法pan()来移来移动其中的地其中的地图。l下面的方法使用在下面的方法使用在MapControl控件的控件的OnMoseDown事件中:事件中:axMapControl1.pan();axMapControl1.Rotation=45;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET在在 MapControl控件中控件中绘制制图形形lMapControl控件提供了直接控件

49、提供了直接在控件上在控件上绘制制图形形和文字的方法和文字的方法DrawShape与与DrawText,这两种两种绘制方法制方法绘制的制的图形都是形都是缓存存(cache),而不能真正保存,一旦窗口重,而不能真正保存,一旦窗口重绘,这些些图形就将消失。形就将消失。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETprivatevoidaxMapControl1_OnMouseDown (objectsender,

50、ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente)/产生拖曳多生拖曳多边形,并形,并绘制制IGeometrypGeom=axMapControl1.TrackPolygon();DrawMapShape(pGeom);/刷新地刷新地图/axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS A

51、pplications with ArcObjects using C#.NETprivatevoidDrawMapShape (IGeometrypGeom)IRgbColorpColor;pColor=newRgbColorClass();pColor.Red=220;pColor.Green=112;pColor.Blue=60;/新建一个新建一个绘制制图形的填充符号形的填充符号ISimpleFillSymbolpFillsyl;pFillsyl=newSimpleFillSymbolClass();pFillsyl.Color=pColor;objectoFillsyl=pFillsy

52、l;axMapControl1.DrawShape(pGeom,refoFillsyl);public public void DrawShape ( DrawShape ( IGeometry Shape, ref object symbol ););江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.1.4 数据数据选择l在在MapControl控件中用控件中用户可以很方便地使可以很方便地使用用Selec

53、tByShape方法来构造一个基于方法来构造一个基于Map的的选择集。集。lSelectByShape()方法方法选择控件中所有控件中所有图层上上处于于选择范范围内的要素,内的要素,并将其并将其设置置为一个一个选择集。集。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETprivatevoidaxMapControl1_OnMouseDown(objectsender,IMapControlEvents2_On

54、MouseDownEvente)/产生拖曳多生拖曳多边形形IGeometrypGeom=axMapControl1.TrackPolygon();axMapControl1.Map.SelectByShape(pGeom,null,false);axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection,null,null);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects

55、 using C#.NETl清除清除选择集的方法集的方法axMapControl1.Map.Clearselection();axMapControl1.ActiveView.Refresh();江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET 3.1.5 实现鹰眼功能眼功能江西理工大学Developing GIS Applications with ArcObjects using C#.NETDevelo

56、ping GIS Applications with ArcObjects using C#.NETl这个例子中有两个个例子中有两个AxMapControl控件:主控件:主控件控件axMapControl1和和鹰眼控件眼控件axMapControl2.要要实现鹰眼功能,关眼功能,关键有有两点:两点:一是一是如何如何让两个控件两个控件显示的数据保持示的数据保持一致一致,另一点是,另一点是如何如何绘制制鹰眼控件中的眼控件中的显示示方框方框。 江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Ap

57、plications with ArcObjects using C#.NET两个控件的数据共享两个控件的数据共享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);江西理工大学Developing GIS Applications with

58、 ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET绘制制鹰眼控件中的眼控件中的显示方框示方框l主窗体主窗体视图的范的范围发生生变化后,会触化后,会触发控件的控件的OnExtentUpdated事件,事件,绘制方框的方法就在制方框的方法就在这个事件中个事件中进行:行:privatevoidaxMapControl1_OnExtentUpdated(objectsender,IMapControlEvents2_OnExtentUpdatedEvente).江西理工大学Developing

59、 GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.2 PageLayoutControl控件控件lPageLayoutControl对应于于ArcMap中的布局中的布局视图(LayoutView),它封装了,它封装了PageLayout对象,提象,提供了在布局供了在布局视图中控制地中控制地图元素的属性和方法。元素的属性和方法。 PageLayoutControl控件用于制控件用于制图,它可以方便,它可以方便地操作各种元素地操作各种元素对象

60、,以象,以产生一幅制作精美的地生一幅制作精美的地图对象象。l与与MapControl控件相似,控件相似,PageLayoutControl控控件并不件并不仅仅只是包含了一个只是包含了一个PageLayout对象,它象,它也也拥有有许多附加的事件、属性和方法。多附加的事件、属性和方法。 江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl页面布局(通常面布局(通常简称称为布局)是在布局)是在页面上面上编排和排和组

61、织的地的地图元素的集合,旨在用于地元素的集合,旨在用于地图的排版的排版设计、打印等。、打印等。布局中排布的常布局中排布的常见地地图元素元素包括包括一个或多个数据框一个或多个数据框(每个数据框(每个数据框都含有一都含有一组有序的地有序的地图图层)、)、比例尺比例尺、指指北北针、地地图标题、描述性文本描述性文本和和符号符号图例例。l打印机、打印机、页面布局、大小、面布局、大小、单位位江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects usi

62、ng C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl数据数据驱动页面面根据地根据地图文档的某个要素文档的某个要素图层或或规则格网将地格网将地图分割分割为多个部分

63、,然后多个部分,然后为每个部分生成一个相每个部分生成一个相应的的页面。面。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET创创建数据建数据驱动页驱动页面面江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlPageLayout

64、Control控件同控件同样实现了多个接口了多个接口IPageLayoutControlDefaultIPageLayoutControlIPageLayoutControl2IPageLayoutControl3(Newin9.2)IPageLayoutControlEvents江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIPageLayoutControlIPageLayoutControl3 3 江

65、西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlSamples:1.PageLayoutControlLoadMapDocument2.PageLayoutControlCopyFocusMap3.PageLayoutControlOverview4.PageLayoutControlPageAppearance5.PageLayoutControlPrintPreview6.PageLayoutContro

66、lPrinting江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.2.1 PageLayoutControl操作操作 MXD文文件件l在在AxPageLayoutControl控件控件对MXD文件的文件的操作,与操作,与MapControl类似。似。publicvoidLoadMxFile(stringfileName,objectpassword);江西理工大学Developing GIS Applic

67、ations with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET下面是在下面是在PageLayout控件中打开一个控件中打开一个MXD文件的方法:文件的方法:privatevoidOpenMapDocument()IMapDocumentm_MapDocument=newMapDocumentClass();OpenFileDialogopenFileDialog1;openFileDialog1=newOpenFileDialog();openFileDialog1.Titl

68、e=OpenMapDocument;openFileDialog1.Filter=MapDocuments(*.mxd)|*.mxd;openFileDialog1.ShowDialog();stringsFilePath=openFileDialog1.FileName;m_MapDocument.Open(sFilePath,);axPageLayoutControl1.PageLayout=m_MapDocument.PageLayout;axPageLayoutControl1.Refresh();江西理工大学Developing GIS Applications with ArcOb

69、jects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETprivatevoidSaveDocument() /Checkthatthedocumentisnotreadonly.if(m_MapDocument.get_IsReadOnly(m_MapDocument.DocumentFilename)=true)MessageBox.Show(Thismapdocumentisreadonly!);return;/Savewiththecurrentrelativepathsetting.m_MapD

70、ocument.Save(m_MapDocument.UsesRelativePaths,true);MessageBox.Show(Changessavedsuccessfully!); 江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETprivatevoidcmdSaveAs_Click(objectsender,System.EventArgse)/Openafiledialogforsavingmapd

71、ocuments.saveFileDialog1.Title=SaveMapDocumentAs; saveFileDialog1.Filter=MapDocuments(*.mxd)|*.mxd;saveFileDialog1.ShowDialog(); stringsFilePath=saveFileDialog1.FileName;if(sFilePath=“”) return;if(sFilePath=m_MapDocument.DocumentFilename)/Savechangestothecurrentdocument.SaveDocument();else/SaveAsane

72、wdocumentwithrelativepaths.m_MapDocument.SaveAs (sFilePath,true,true);/Openthedocument.OpenDocument(sFilePath);MessageBox.Show(Documentsavedsuccessfully!); 江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.2.2 PageLayout与与MapContr

73、ol联动l在在ArcMap程序中,数据程序中,数据视图和布局和布局视图中的数中的数据改据改变是是实时互互动的。的。l在使用在使用ArcObjects控件开控件开发的独立程序中的独立程序中实现这个功能,个功能,由于由于MapControl、 PageLayoutControl两个控件本身并不能自两个控件本身并不能自动实时互互动,用,用户只能只能够通通过拷拷贝的方法来的方法来实时传递两个控件的内容。两个控件的内容。lSample: MapAndPageLayoutSynchApp江西理工大学Developing GIS Applications with ArcObjects using C#.N

74、ETDeveloping GIS Applications with ArcObjects using C#.NET3.3 TOCControl控件控件1.TOCControl控件概述控件概述ITOCControl与与ITOCControl2ITOCControlEvents2.2.应用开用开发实例例江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.3.1 TOCControl控件概述控件概述 lTOCCo

75、ntrol要与一个要与一个“伙伴控件伙伴控件” 协同工作。同工作。“伙伴控件伙伴控件”可以是可以是MapControl、PageLayoutControl、SceneControl或或GlobeControl。TOCControl用用“伙伴控件伙伴控件”来来显示其地示其地图、图层和和符号体系内容的一个交互式符号体系内容的一个交互式树视图,并保持其内容与,并保持其内容与“伙伴控件伙伴控件”同步。同步。例如,如果例如,如果“伙伴控件伙伴控件”是一个是一个MapControl,而且从,而且从该MapControl中中删除了一个除了一个图层,则该图层也会从也会从TOCControl中中删除。除。同同样

76、地,地,如果如果终端用端用户与与TOCControl交互并取消了某个交互并取消了某个图层的的Visibility复复选框,框,则该图层在在MapControl中不再中不再可可见。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlTOCControl的的“伙伴控件伙伴控件”可以在可以在设计时通通过TOCControl属性属性页设置置或或用用SetBuddyControl方法通方法通过编程程设置置。lTOCCon

77、trol的主要接口有:的主要接口有:ITOCControl、 ITOCControl 2、ITOCControlEvents江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.3.1.1 ITOCControl与与ITOCControl2 lITOCControl接口是任何与接口是任何与TOCControl有关的任有关的任务的出的出发点,如点,如设置控件的外置控件的外观,设置伙伴控件,管理置伙伴控件,管理图层

78、的可的可见性和性和标签的的编辑。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETITOCControllLabelEdit、LayerVisibilityEdit:Label、Visibility editingstate.esriTOCControlAutomaticesriTOCControlManual江西理工大学Developing GIS Applications with ArcObjects u

79、sing C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl在在C#.NET环境中,当境中,当查询接口到接口到ITOCControl 或或ITOCControl2时,必,必须使用使用Object属性属性或者容器或者容器指定代指定代码。 ITOCControl pTOCControl;pTOCControl = axTOCControl1.Object as ITOCControl; 或或pTOCControl = axTOCControl1. GetOcx() as ITOCControl;江西理工大学Developi

80、ng GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlpublicvoidHitTest(intX,intY,refesriTOCControlItemItemType,refIBasicMapBasicMap,refILayerLayer,refobjectUnk,refobjectData);用于用于获取用取用户在在TOCControl中点中点击的信相关息的信相关息。ItemType:TOCControl中中项的的类型,如型,如none

81、、map、layer、heading或或legendclass.BasicMap:指定地指定地图对象。象。Layer:ILayer对象。象。Unk:ILegendGroup(图例例组,一个,一个图层可以有多种符号化可以有多种符号化方案方案)对象。象。Data:用:用户点点击的的图例例组中某个中某个图例的索引号例的索引号(长整型整型);联合合使用使用图例例组Unk和和这个索引号,可以个索引号,可以获得用得用户点点击的的图例例(legendclass);如果如果这个索引号个索引号为-1,表明用,表明用户点点击的是的是图例中的例中的标题头。 江西理工大学Developing GIS Applicat

82、ions with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIBasicMapmap=newMapClass();ILayerlayer=newFeatureLayerClass();objectother=newobject();objecti

83、ndex=newobject();esriTOCControlItemitem=newesriTOCControlItem();axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);if(e.button=1)/判断用判断用户户是否按了鼠是否按了鼠标标左左键键if(layer=null)return;IFeatureLayerfeatureLayer=layerasIFeatureLayer;if(featureLayer=null)return;IGeoFeatureLayergeoFeatureLa

84、yer=(IGeoFeatureLayer)featureLayer;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETILegendClasslegendClass=newLegendClassClass();ISymbolsymbol=null;if(otherisILegendGroup&(int)index!=-1)legendClass=(ILegendGroup)other).get_Class(i

85、nt)index);symbol=legendClass.Symbol;if(symbol=null)return;symbol=GetSymbolByControl(symbol);/弹弹出符号出符号选择对话选择对话框框让让用用户选择户选择新的符号新的符号if(symbol=null)return;legendClass.Symbol=symbol;this.Activate();axMapControl1.ActiveView.ContentsChanged();axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,n

86、ull);axTOCControl1.Update();江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlprivateISymbolGetSymbolByControl( ISymbolsymbolType)ISymbolsymbol=null;IStyleGalleryItemstyleGalleryItem=null;esriSymbologyStyleClassstyleClass=esriSymbo

87、logyStyleClass.esriStyleClassMarkerSymbols;if(symbolTypeisIMarkerSymbol)styleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;if(symbolTypeisILineSymbol)styleClass=esriSymbologyStyleClass.esriStyleClassLineSymbols;if(symbolTypeisIFillSymbol)styleClass=esriSymbologyStyleClass.esriStyleClassF

88、illSymbols;GetSymbolByControlFormsymbolForm=newGetSymbolByControlForm(styleClass);symbolForm.ShowDialog();styleGalleryItem=symbolForm.m_styleGalleryItem;if(styleGalleryItem=null)returnnull;symbol=styleGalleryItem.ItemasISymbol;symbolForm.Dispose(); this.Activate();returnsymbol;江西理工大学Developing GIS A

89、pplications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETITOCControl2 (New in 9.2)l与与ITOCControl相比,相比,ITOCControl2多了以下多了以下1个个属性和属性和2个方法:个方法:publicboolEnableLayerDragDropget;set;:指示指示图层是否可以拖放,以改是否可以拖放,以改变图层的的顺序。序。publicvoidGetSelectedItem(refesriTOCControlItemIt

90、emType,refIBasicMapBasicMap,refILayerLayer,refobjectUnk,refobjectData):返回返回TOCControl中被中被选择项。publicvoidSelectItem(objectUnk,objectData):用于用于设置置TOCControl中的中的选择项,如:如:江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl/Selectingthefoc

91、usmapaxTOCControl1.SelectItem( axTOCControl1.ActiveView.FocusMap);l/SelectingalayerinthefocusmapaxTOCControl1.SelectItem (axTOCControl1.ActiveView.FocusMap.get_Layer(0);l/ToselectanitemwithinaLegendGroupILayerlayer=axTOCControl1.ActiveView.FocusMap.get_Layer(0);ILegendInfolegendInfo=(ILegendInfo)lay

92、er;ILegendGrouplegendGroup=legendInfo.get_LegendGroup(0);/SelectaheadingaxTOCControl1.SelectItem (legendGroup);/SelectalegendclassaxTOCControl1.SelectItem (legendGroup,2);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.3.1.2 ITO

93、CControlEventslITOCControlEvents是一个事件接口,它是一个事件接口,它定定义了了 TOCControl能能够处理的全部事件,理的全部事件,如如OnMouseDown、OnMouseMove、OnMouseUp、OnDoubleClick、OnBeginLabelEdit、OnEndLabelEdit、OnKeyDown、OnKeyUp。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.N

94、ETl privatevoidaxTOCControl1_OnBeginLabelEdit (objectsender,ITOCControlEvents_OnBeginLabelEditEvente)m_TOCControl.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);/已在其它地方(如窗体已在其它地方(如窗体的的Load事件中)声明事件中)声明为ITOCControl类型的型的变量,并量,并已已实例化例化if(item!=esriTOCControlItem.esriTOCControlItemLayer)e.can

95、Edit=false;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl privatevoidaxTOCControl1_OnEndLabelEdit(objectsender,ITOCControlEvents_OnEndLabelEditEvente)/Preventemptylabelsif(e.newLabel.Trim()=)e.canEdit=false;江西理工大学Developing GIS

96、 Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlSamples1.TOCControlContextMenu2.TOCControlLayerDragDrop3.TOCControlMetadataViewer江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.

97、3.2 应用开用开发实例例lTOC的右的右键菜菜单在在ArcMap中,中,“TableofContents”中右中右键菜菜单功能非常丰厚,功能非常丰厚,而而TOCControl控件并没控件并没有提供右有提供右键菜菜单功能。功能。要要实现右右键菜菜单功能,功能,需要开需要开发人人员自己自己编程程实现。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl当右当右键键点点击击地地图时图时,弹弹出出l当右当右键键点点击

98、图层时击图层时,弹弹出出江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET 首先要首先要实现实现好右好右键键菜菜单单上的命令上的命令privatevoidMainForm_Load(objectsender,EventArgse)定定义义地地图图右右键键菜菜单单、图层图层右右键键菜菜单单privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEv

99、ents_OnMouseDownEvente)根据右根据右键键点点击击的的对对象,象,弹弹出相出相应应的右的右键键菜菜单单江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIToolbarMenum_TocLayerMenu=newToolbarMenuClass();IToolbarMenum_TocMapMenu=newToolbarMenuClass();privatevoidMainForm_Load(

100、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,

101、2,true,esriCommandStyles.esriCommandStyleTextOnly);m_TocLayerMenu.AddItem(newScaleThresholds(),2,3,false,esriCommandStyles.esriCommandStyleTextOnly);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETm_TocLayerMenu.AddItem(newScaleTh

102、resholds(),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

103、(),0,7,true,esriCommandStyles.esriCommandStyleIconAndText);m_TocLayerMenu.AddItem(newLayerPropertiesCmd(),0,8,false,esriCommandStyles.esriCommandStyleIconAndText);m_TocLayerMenu.SetHook(axMapControl1);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcO

104、bjects using C#.NETlprivatevoidaxTOCControl1_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.PopupMe

105、nu(e.x,e.y,axTOCControl1.hWnd);elseif(layerisIFeatureLayer)m_mapControl.CustomProperty=layer;m_TocLayerMenu.PopupMenu(e.x,e.y,axTOCControl1.hWnd);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlpublicsealedclassOpenAttributeTable

106、Cmd:BaseCommandpublicoverridevoidOnClick()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=newLay

107、erAttributes(map,currentLayer);layerAttributeTable.Show(m_hookHelperasSystem.Windows.Forms.IWin32Window);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlpublicpartialclassLayerAttributes:FormDataSetm_layerDataSet=newDataSet(m_dat

108、aSetName);privateSystem.Windows.Forms.DataGridViewdataGridView1;publicLayerAttributes(IMapmap,IFeatureLayerfeatureLayer)InitializeComponent();m_map=map;m_activeView=mapasIActiveView;currentLayer=featureLayer;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications wi

109、th ArcObjects using C#.NETlprivatevoidAttributesForm_Load(objectsender,EventArgse)this.Text=currentLayer.Name+属性表属性表;introwCount=ConstructDataSet(currentLayer);dataGridView1.DataSource=m_layerDataSet;dataGridView1.DataMember=currentLayer.Name;toolStripStatusLabel1.Text=选择记录选择记录数:数:;toolStripStatusLa

110、bel2.Text=总记录总记录数:数:+currentLayer.FeatureClass.FeatureCount(null).ToString();江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlprivateintConstructDataSet(IFeatureLayerpFeatLyr)ILayerFieldspFeatlyrFields=pFeatLyrasILayerFields;IFeat

111、ureClasspFeatCls=pFeatLyr.FeatureClass;introws=0;if(m_layerDataSet.TablespFeatLyr.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);pTableC

112、ol=null;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETIFeatureCursorfeatures=pFeatLyr.Search(null,false);IFeaturefeature=features.NextFeature();while(feature!=null)DataRowpTableRow=pTable.NewRow();for(inti=0;iLearningArcObjectsG

113、eneralArcObjectsreferencesNamesandIDs自定自定义命令、工具等的命令、工具等的CLSID、ProgID,命令,命令类、工具、工具类中可以找到。中可以找到。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.4.3ToolbarItemlToolbarItem就是就是驻留在留在ToolbarControl或或菜菜单上的上的单个个Command,Tool,ToolControl,

114、ToolbarMenu,ToolbarPaletteorMultiItem对象。象。lToolbarItem的主要接口有:的主要接口有:IToolbarItem。lIToolbarltemIToolbarltem接口的属性接口的属性决定工具条命令项的外观决定工具条命令项的外观。例如,。例如,工具条命令项是否在其左侧有一条垂直线表示是否开始一个工具条命令项是否在其左侧有一条垂直线表示是否开始一个命令组命令组( (GroupGroup) ),及命令项的样式,及命令项的样式( (StyleStyle) )是否有一个位图、是否有一个位图、标题或两者都有。标题或两者都有。CommandCommand和和

115、MenuMenu属性返回工具条命令项代表属性返回工具条命令项代表的实际的实际命令命令或或菜单菜单。lToolbarItemToolbarItem是一个不可创建的对象是一个不可创建的对象。引用不可创建的对象必。引用不可创建的对象必须通过其它对象获得,可以使用须通过其它对象获得,可以使用IToolbarControl.GetItemIToolbarControl.GetItem 方法获得方法获得ToolbarItemToolbarItem。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS App

116、lications with ArcObjects using C#.NETlNote:theIToolbarIteminterfacehasbeensupersededbyIToolbarItem2.lType属性:属性:esriToolbarItemTypeesriToolbarItemUnknownesriToolbarItemCommandesriToolbarItemToolesriToolbarItemToolControlesriToolbarItemMenuesriToolbarItemPaletteesriToolbarItemMultiItem江西理工大学Developin

117、g GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET 3.4.4 更新命令更新命令l默默认情况下,情况下,ToolbarControl每半秒每半秒钟自自动更新其自身一更新其自身一次次,以确保,以确保驻留在留在ToolbarControl上的每个工具条命令上的每个工具条命令项的外的外观与其底与其底层命令的命令的Enabled、Bitmap和和Caption等属等属性同步。性同步。l改改变UpdateInterval属性可以更改更新的属性可以更改

118、更新的频率。率。UpdateInterval为0会停止任何自会停止任何自动发生的更新,开生的更新,开发人人员必必须编程程调用用Update方法以刷新每个工具条命令方法以刷新每个工具条命令项的状的状态。l在在应用程序中首次用程序中首次调用用Update方法方法时,ToolbarControl会会检测每个工具条命令每个工具条命令项的的ICommand.OnCreate方法是否方法是否已已经被被调用用过。如果。如果还没有没有调用用过该方法,方法,则该ToolbarControl作作为“钩子子(hook)”被自被自动传递给ICommand.OnCreate方法。方法。江西理工大学Developing

119、GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.4.5 ToolbarMenu 组件件类l工具条菜工具条菜单(ToolbarMenu)提供了菜提供了菜单项的的实现,其上可其上可以以驻留命令留命令(Command)、工具、工具(Tool)、工具控件、工具控件(ToolControl)、动态菜菜单(MultiItem)和工具条面板和工具条面板(ToolbarPalette)。ArcGIS10版本之前,版本之前,ToolbarMenu上上只能只

120、能驻留留单击命令命令,不能,不能驻留其他留其他对象。象。l工具条菜工具条菜单(ToolbarMenu)可以可以驻留在留在ToolbarControl上上或作或作为“子菜子菜单”驻留在另一个工具条菜留在另一个工具条菜单上上或作或作为右右键菜菜单出出现。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlToolbarMenu的主要接口的主要接口有:有:IToolbarMenu、IToolbarMenu2。江西理工

121、大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlIToolbarMenu2江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlToolbarMenu的构建有两种方式:的构建有两种方式:1.1.先先实现IMenuDef,创建菜建菜单对

122、象,假象,假设为MenuDefA;再;再实例化一个例化一个ToolbarMenu对象,假象,假设为ToolbarMenuA;然后使用;然后使用IToolbarMenu2.AddItem方法,将方法,将MenuDefA对象象添加到添加到ToolbarMenuA对象;最后,使用象;最后,使用IToolbarControl.AddItem或或IToolbarControl.AddMenuItem方法将方法将ToolbarMenuA添加到工具条控件上。添加到工具条控件上。2.2.使用使用IToolbarMenu2接口中的属性、方法将已有的接口中的属性、方法将已有的命令添加到命令添加到ToolbarMe

123、nu对象上来构建菜象上来构建菜单;ToolbarMenu上的子菜上的子菜单又可以使另一个又可以使另一个ToolbarMenu的的实例。例。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.4.6 ToolbarPalettelToolbarPalette(工具条面板工具条面板)提供了面板提供了面板项的的实现,其其上可以上可以驻留命令和工具,留命令和工具,但不能但不能驻留留ToolControl、Toolba

124、rMenu以及以及MultiItem对象。象。ToolbarPalette可可以以驻留在留在ToolbarControl上或作上或作为弹出面板出面板出出现。lIToolbarPalette是是ToolbarPalette的主要接口。的主要接口。该接口接口定定义的属性有:的属性有:ActiveItem、AlignLeft、Caption、CommandPool、Count、Customize、Hook、IconSize、MouseIcon、MousePointer、ThemedDrawing、ToolTips;定定义的方法有:的方法有:AddItem、Find、GetItem、MoveItem、

125、PopupPalette、Remove、RemoveAll、SetHook.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlToolbarPalette的构建有两种方式:的构建有两种方式:1.1.先先实现IPaletteDef,创建面板建面板对象,假象,假设为PaletteDefA;再;再实例化一个例化一个ToolbarPalette对象,象,假假设为ToolbarPaletteA;然后使用;然后使用ITo

126、olbarPalette.AddItem方法,将方法,将PaletteDefA对象添加到象添加到ToolbarPaletteA对象;最后,使用象;最后,使用IToolbarControl.AddItem方法将方法将ToolbarPaletteA添加到工具条控件上。添加到工具条控件上。2.2.使用使用IToolbarPalette接口中的属性、方法将已有接口中的属性、方法将已有的命令、工具添加到的命令、工具添加到ToolbarPalette对象上来构象上来构建面板。建面板。江西理工大学Developing GIS Applications with ArcObjects using C#.NET

127、Developing GIS Applications with ArcObjects using C#.NET/CreateaToolbarPalettem_ToolbarPalette=newToolbarPaletteClass();/AddnewitemstotheToolbarPalettem_ToolbarPalette.AddItem(esriControls.ControlsSelectTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewCircleTool,0,-1);m_ToolbarPalette.Add

128、Item(esriControls.ControlsNewCurveTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewEllipseTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewLineTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewPolygonTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewRectangl

129、eTool,0,-1);m_ToolbarPalette.AddItem(esriControls.ControlsNewFreeHandTool,0,-1);/AddtheToolbarPalettetotheToolbarControlaxToolbarControl1.AddItem(m_ToolbarPalette,0,-1,true,0,esriCommandStyles.esriCommandStyleIconAndText);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS A

130、pplications with ArcObjects using C#.NET3.4.7 CommandPooll每个每个ToolbarControl、ToolbarMenu和和ToolbarPalette都有一个都有一个命令池命令池(CommandPool),用于管理其使用的命令,用于管理其使用的命令对象象的的集集合合。一般来一般来说,开开发人人员不会与命令池不会与命令池进行交互。行交互。当通当通过ToolbarControl属性属性页或或编程将命令添加到程将命令添加到ToolbarControl中中时,该命令自命令自动添加到命令池添加到命令池中。中。命令命令对象要么作象要么作为唯一唯一识

131、别该命令的一个命令的一个UID对象象(使用使用GUID)、要么作、要么作为命令命令对象的一个象的一个现有有实例例被添加到命令池中。被添加到命令池中。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl如果命令如果命令对象的一个象的一个现有有实例被添加,并且例被添加,并且该命命令没有一个令没有一个UID,则命令池中可以有同一命令的多命令池中可以有同一命令的多个个实例存在。例存在。如果提供了一个如果提供了一个UID

132、对象,命令池可象,命令池可以确定以确定该命令是否已命令是否已经存在于命令池中,而且如存在于命令池中,而且如果存在的果存在的话就可以重用就可以重用该命令之前的命令之前的实例。例。命令命令池通池通过追踪是否已追踪是否已经调用用过命令的命令的OnCreate方法方法来完成来完成这个工作。如果已个工作。如果已经调用用过OnCreate方法,方法,则将重用将重用该命令并增加其使用次数命令并增加其使用次数(UsageCount)。 江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Application

133、s with ArcObjects using C#.NETl例如,如果向某个例如,如果向某个ToolbarControl中添加中添加两次两次“ZoomIn”工具并提供工具并提供UID,则当当ToolbarControl上的一个上的一个“ZoomIn”工具被工具被选择并并显示示“按下按下(pressed)”时,另一个,另一个“ZoomIn”工具也会工具也会显示示“按下按下(pressed)”状状态,因,因为它它们使用同一个命使用同一个命令令对象。象。当当应用程序包含多个用程序包含多个ToolbarControl或或工具条菜工具条菜单时,开,开发人人员应确保每个确保每个ToolbarContro

134、l和工具条菜和工具条菜单使用相同的命令池,使用相同的命令池,以保以保证在在应用程序中只用程序中只创建了命令的一个建了命令的一个实例。例。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETICommandPool m_CommandPool=newCommandPoolClass();axToolbarControl1.CommandPool=m_CommandPool;axToolbarControl2.Com

135、mandPool=m_CommandPool;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.4.8 操作操作栈(OperationStack)lToolbarControl有一个操作有一个操作栈(OperationStack),用于管理,用于管理“撤撤销(undo)”和和“重做重做(redo)”功能。功能。由每个工具条命令由每个工具条命令项的底的底层命令将操作添加到操命令将操作添加到操作作栈中,以便可以

136、根据需要将操作前中,以便可以根据需要将操作前滚或后或后滚。例如,由于例如,由于误操作,操作,删除了某个地理要素,可以除了某个地理要素,可以点点击ToolbarControl上的上的“undo”命令,撤消命令,撤消该操作。操作。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl命令是否可以利用操作命令是否可以利用操作栈取决于取决于该命令的命令的实现。典典型情况下,开型情况下,开发人人员为应用程序用程序创建一个建

137、一个单个的控个的控件操作件操作栈(ControlsOperationStack),并将其,并将其设置置给每个每个ToolbarControl。撤消和重做命令可以添加。撤消和重做命令可以添加到到使用了操作使用了操作栈的的ToolbarControl上。上。l说明:活明:活动视图(ActiveView)中的范中的范围变化化(Extentchanges)是保存在是保存在IActiveView.ExtentStack中,中,而不是在而不是在OperationStack中。中。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDe

138、veloping GIS Applications with ArcObjects using C#.NETIOperationStackoperationStack=newControlsOperationStackClass();axToolbarControl1.OperationStack=operationStack;axToolbarControl2.OperationStack=operationStack;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applicatio

139、ns with ArcObjects using C#.NET3.4.9 定制定制lToolbarControl有一个有一个Customize属性属性(true/false),可以,可以设置置该属性以使属性以使ToolbarControl处于定制模式。于定制模式。允允许终端用端用户重重新安排、新安排、删除和添加命令除和添加命令项以及改以及改变这些命令些命令项的外的外观。l当当ToolbarControl处于定制模式于定制模式时,开,开发人人员可可以以编程程启启动非模非模态定制定制对话框框(CustomizeDialog)。定制。定制对话框列出了所有的框列出了所有的控件命令以及任何自定控件命令以

140、及任何自定义命令、工具集和菜命令、工具集和菜单。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETCustomizeDialoglCustomizeDialog包含一个无模包含一

141、个无模态对话框,允框,允许程序运行程序运行时将将 commands,toolbardefinitions(toolsets)和和 menudefinitions等等添加到添加到 ToolbarControl上,当上,当IToolbarControl.Customize设置置为true时。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlCustomizeDialog的主要接口的主要接口为:ICustomize

142、Dialog和事件接口和事件接口ICustomizeDialogEvents。lICustomizeDialog接口的属性接口的属性 DialogTitle、IsDialogActive、DoubleClickDestination、CommandsCategory、MenusCategory、ToolbarsCategory、ShowAddFromFile。lICustomizeDialog接口的方法接口的方法StartDialog、CloseDialog、SetDoubleClickDestination。lICustomizeDialogEvents接口成接口成员:OnStartDial

143、og、OnCloseDialog.江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET开开发实例例l首先声明一个首先声明一个ICustomizeDialog类型的全局型的全局变量量m_CustomizeDialog,并,并实例化,代例化,代码如下:如下:privateICustomizeDialogm_CustomizeDialog=newCustomizeDialogClass();l接着,声明如下两个事件接着

144、,声明如下两个事件变量:量:privateICustomizeDialogEvents_OnStartDialogEventHandlerstartDialogE;privateICustomizeDialogEvents_OnCloseDialogEventHandlercloseDialogE;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlCOM事件事件转换为.NET 事件:事件: 为每个事件每个事件

145、产生一个代理(生一个代理( delegate)命名:命名:事件接口事件接口+_+事件名事件名+EventHandler例如:例如:IActiveViewEvents_SelectionChangedEventHandler创建一个建一个.NET事件接口事件接口命名:命名:事件接口事件接口+_+Event例如:例如: IActiveViewEvents_Event江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET

146、l创建一个名建一个名为CreateCustomizeDialog的方法,在的方法,在该方法中方法中添加代添加代码,对两个事件两个事件变量和定制量和定制对话框框进行有关行有关设置:置:privatevoidCreateCustomizeDialog()ICustomizeDialogEvents_EventpCustomizeDialogEvent=m_CustomizeDialogasICustomizeDialogEvents_Event;startDialogE=newICustomizeDialogEvents_OnStartDialogEventHandler(OnStartDialo

147、gHandler);pCustomizeDialogEvent.OnStartDialog+=startDialogE;closeDialogE=newICustomizeDialogEvents_OnCloseDialogEventHandler(OnCloseDialogHandler);pCustomizeDialogEvent.OnCloseDialog+=closeDialogE;m_CustomizeDialog.DialogTitle=CustomizeToolbarControlItems;m_CustomizeDialog.SetDoubleClickDestination(

148、axToolbarControl1);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl在窗体在窗体Form1的的Load调用用CreateCustomizeDialog方法:方法:lprivatevoidForm1_Load(objectsender,System.EventArgse)/CreateCustomizeDialog();/江西理工大学Developing GIS Applications w

149、ith ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl向窗体向窗体Form1中添加一个复中添加一个复选框并将其命名框并将其命名为chkCustomize,标题为“Customize”。l在复在复选框框chkCustomize的的CheckedChanged事事件件处理方法中添加如下代理方法中添加如下代码:lprivatevoidchkCustomize_CheckedChanged(objectsender,System.EventArgse)/ShoworhidetheCusto

150、mizedialogbox.if(chkCustomize.Checked=false)m_CustomizeDialog.CloseDialog();elsem_CustomizeDialog.StartDialog(axToolbarControl1.hWnd);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl添加下面的添加下面的OnStartDialog和和OnCloseDialog事件事件处理器,理

151、器,在打开或关在打开或关闭定制定制对话框框时会触会触发这两个方法。两个方法。lprivatevoidOnStartDialogHandler() axToolbarControl1.Customize=true;lprivatevoidOnCloseDialogHandler()axToolbarControl1.Customize=false;chkCustomize.Checked=false;按以上步按以上步骤就能就能实现ToolbarControl的定制。的定制。江西理工大学Developing GIS Applications with ArcObjects using C#.NET

152、Developing GIS Applications with ArcObjects using C#.NET3.5 内置的命令内置的命令lArcObjects开开发包包提供了大量内置的命令、工具提供了大量内置的命令、工具条及工具、工具控件和菜条及工具、工具控件和菜单等,开等,开发人人员在自己在自己的的GIS应用开用开发中可以直接使用中可以直接使用这些些对象。象。l这些内置的些内置的命令、工具等的命令、工具等的名称、名称、GUID(CLSID/ProgID)、子命令、子命令/子工具序号子工具序号等信息可以等信息可以查阅开开发文档。文档。DevelopingwithArcGISLearning

153、ArcObjectsGeneralArcObjectsreferencesNamesandIDs江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETlNamesandIDsArcCatalogcommandsArcGlobecommandsArcMapcommandsArcScenecommandsArcGISEnginecommandsExtensions江西理工大学Developing GIS Applica

154、tions with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.5.1 ArcGIS Engine commands概述概述lESRI.ArcGIS.Controls类库中提供了大量的命令、工具条中提供了大量的命令、工具条及工具、工具控件和菜及工具、工具控件和菜单等,开等,开发人人员在自己的在自己的GIS应用用开开发中可以直接使用中可以直接使用这些些对象。象。使用使用这些些对象有两种方式:象有两种方式:一是通一是通过ToolbarControl控件使用控件使用二是不通二是不通

155、过ToolbarControl控件使用控件使用l开开发人人员也可以通也可以通过创建自己的自定建自己的自定义命令、工具和菜命令、工具和菜单来来扩展展ArcGIS提供的命令集。提供的命令集。HookHelper、GlobeHookHelper和和SceneHookHelper对象可用于象可用于简化化这种开种开发。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.5.2 与与 ToolbarControl一起使用

156、一起使用l通通过ToolbarControl控件使用控件使用ControlCommands有三条途径:有三条途径:在程序在程序设计阶段,通段,通过ToolbarControl控件的控件的属性属性页添添加加在程序代在程序代码中,使用中,使用AddItem,AddMenuItem或或AddToolbarDef方法将要用到的方法将要用到的ControlCommands的的实例例对象添加到象添加到ToolbarControl控件中,控件中, 使用使用AddItem或或AddSubMenu方法添加到方法添加到 ToolbarMenu上;上;最最终用用户可以通可以通过Customize对话框框进行行设置置

157、(当当ToolbarControl控件的控件的Customize设置置为true时有效有效)。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET 3.5.3 独立使用(独立使用(without the ToolbarControl)l有的有的时候候应用程序可能并不需要用程序可能并不需要ToolbarControl:ToolbarControl的可的可视化外化外观可能不符合可能不符合应用程序的需用程序的需要。要。

158、为ToolbarControl创建命令的开建命令的开销并不需要。并不需要。应用程序中已用程序中已经有一个有一个现有的有的应用程序框架。用程序框架。ToolbarControl及其及其驻留的命令不易于跨多个留的命令不易于跨多个“伙伴控伙伴控件件”使用。使用。l在在这些情况下,开些情况下,开发人人员必必须直接操作直接操作MapControl、PageLayoutControl等控件。等控件。应用程序需要其他用用程序需要其他用户界面界面组件,如命令按件,如命令按钮、菜、菜单和列表框等,可能要和列表框等,可能要由开由开发环境提供。境提供。江西理工大学Developing GIS Application

159、s with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET使用方法:使用方法:l通通过编程程创建命令的一个新例程,并建命令的一个新例程,并将将单个个ArcGIS控件控件传递给OnCreate方法方法。l如果命令只如果命令只实现了了ICommand接口,开接口,开发人人员可可以在适当的以在适当的时候候调用用OnClick方法以方法以执行特定行行特定行动。l如果命令如果命令为实现了了ICommand接口和接口和ITool接口的接口的工具,开工具,开发人人员必必须将将该工具工具设置置为A

160、rcGIS控件控件中的中的CurrentTool。 ArcGIS控件会将任何控件会将任何键盘和和鼠鼠标事件事件传送送给该工具。工具。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl例如:例如:ICommandcmd=newSymbology.UniqueValueRenderer();cmd.OnCreate(axMapControl1.Object);if(cmd.Enabled)cmd.OnClick(

161、);ICommandpCommand=newControlsSelectFeaturesToolClass();pCommand.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool=pCommandasITool;BaseTooltool=newSelectAdjacentFeatures();tool.OnCreate(axMapControl1.Object);axMapControl1.CurrentTool=tool;江西理工大学Developing GIS Applications with ArcObjects usin

162、g C#.NETDeveloping GIS Applications with ArcObjects using C#.NET 3.6 在在WPF程序中使用程序中使用ArcGIS Engine控件控件1.WPF简介介2.2.如何在如何在WPF中使用中使用ArcGISEngine控件控件3.3.在在WPF里使用里使用ArcGISEngine控件的局限性控件的局限性江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NE

163、T3.6.1 WPF简简介介l WindowsPresentationFoundation(WPF)是是.NETFramework3.0提供的新的提供的新的图形形显示系示系统,为用用户界面、界面、2D/3D图形形、文档文档和和媒体媒体提供了提供了统一的描述和操作方法。一的描述和操作方法。l基于基于DirectX9/10技技术的的WPF不不仅带来了前所未有的来了前所未有的3D界界面,而且其面,而且其图形向量渲染引擎形向量渲染引擎也大大改也大大改进了了传统的的2D界面,界面,比如比如Vista中的中的半透明效果的窗体半透明效果的窗体等都得益于等都得益于WPF。l.NETFramework3.0同同

164、时新增了四个大新增了四个大组件:件:WindowsPresentationFoundation (WPF),WindowsWorkflowFoundation (WWF)、WindowsCommunicationFoundation (WCF)和和WindowsCardSpace,而,而这些恰是些恰是NETFramework3.0最具价最具价值的部分。的部分。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl

165、WPF使用一种新的使用一种新的XAML语言言(eXtensibleApplicationMarkupLanguage,可,可扩展展应用程用程序序标记语言)言)来开来开发界面,界面,这将把将把界面界面设计以及以及后台后台逻辑开开发很好的分开,降低了耦合度,使很好的分开,降低了耦合度,使用用户界面界面设计师与与程序开程序开发者者能更好的合作,降低能更好的合作,降低维护和更新的成本。和更新的成本。lXAML描述界面描述界面江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications

166、with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.6.2如何在如何在WPFWPF中使用中使用ArcGISEngineArcGISEngine控件控件江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjec

167、ts using C#.NET3.6.2.1 WPF和和Windows Forms集成集成l将将WPF与与WindowsForms集成可以有在同一窗集成可以有在同一窗体和在不同窗体两种方式。体和在不同窗体两种方式。要把要把ArcGISEngine的的WindowsForms控件控件集成到集成到WPF环境里去,境里去,有两个有两个选项可供可供选择:在在WPF应用程序中添加一个用程序中添加一个WindowsForm,然后在此然后在此Form上添加使用上添加使用ArcGISEngine控件。控件。将将ArcGISEngine控件直接加到控件直接加到WPF窗体中。窗体中。江西理工大学Developin

168、g GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.6.2.2在在WPFWPF窗体中添加窗体中添加ArcGISEngineArcGISEngine控件控件lWindowsFormsHost控件提供了一个容器,可以控件提供了一个容器,可以容容纳WindowsForms控件,由此就可以达到在控件,由此就可以达到在WPF窗体中添加窗体中添加WindowsForms控件控件的的目的。目的。这样一来,一来,WPF元素和元素和ArcGISEngine

169、控件就可控件就可以方便地互相以方便地互相访问、互相操作。、互相操作。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET示例:在示例:在WPF中添加一个中添加一个MapControl。l步步骤一:一:启启动VisualStudiol步步骤二:二:新建新建项目里目里选WPF应用程序,命名用程序,命名为MapHostedInWPFl步步骤三:三:添加引用添加引用ESRI.ArcGIS.AxControls、ESRI.

170、ArcGIS.System、ESRI.ArcGIS.Version,其中其中ESRI.ArcGIS.Version为ArcGIS新增的程序集,它提供了新增的程序集,它提供了绑定运行定运行时的的API,它的,它的RuntimeManager类可用以列可用以列举目前所安装的目前所安装的ArcGIS产品以品以及其安装目及其安装目录。l步步骤四:四:将将WindowsFormsHost控件拖入窗体控件拖入窗体l步步骤五:五:将窗体的将窗体的标题改改为“MapControlHostedinWPF”,将,将WindowsFormsHost控件的控件的Name属性属性设为“mapHost”,添加一个,添加一

171、个WindowsLoad事件,取其默事件,取其默认名名Window_Loaded。江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl步步骤六:六:绑定定产品及初始化品及初始化l

172、icensepublicpartialclassApp:ApplicationprotectedoverridevoidOnStartup(StartupEventArgse)base.OnStartup(e);ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);InitializeEngineLicense();privatevoidInitializeEngineLicense()AoInitializeaoi=newAoInitializeClass();esriLicenseProductCodeproduct

173、Code=esriLicenseProductCode.esriLicenseProductCodeEngine;if(aoi.IsProductCodeAvailable(productCode)=esriLicenseStatus.esriLicenseAvailable)aoi.Initialize(productCode);江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl步步骤七:七:定定义MapC

174、ontrolpublicpartialclassWindow1:WindowAxMapControlmapControl;publicWindow1()InitializeComponent();CreateMapControl();privatevoidCreateMapControl()mapControl=newAxMapControl();mapHost.Child=mapControl;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcOb

175、jects using C#.NETl步步骤八:八:为MapControl添加属性事件添加属性事件privatevoidWireMapEvents()mapControl.OnMouseMove+=newIMapControlEvents2_Ax_OnMouseMoveEventHandler(mapControl_OnMouseMove);mapControl.OnMouseDown+=newIMapControlEvents2_Ax_OnMouseDownEventHandler(mapControl_OnMouseDown);privatevoidmapControl_OnMouseDo

176、wn(objectsender,IMapControlEvents2_OnMouseDownEvente)mapControl.Extent=mapControl.TrackRectangle();mapControl.Refresh();privatevoidmapControl_OnMouseMove(objectsender,IMapControlEvents2_OnMouseMoveEvente)System.Console.WriteLine(e.mapX.ToString();江西理工大学Developing GIS Applications with ArcObjects usi

177、ng C#.NETDeveloping GIS Applications with ArcObjects using C#.NETl步步骤九:九:编写窗体加写窗体加载事件代事件代码privatevoidWindow_Loaded(objectsender,RoutedEventArgse)WireMapEvents();/Specifyyour.mxdfilehere.mapControl.LoadMxFile(C:ProgramFilesArcGISDeveloperKit10.0SamplesdataGulfOfStLawrenceGulf_of_St._Lawrence.mxd);步步骤

178、十:十:运行程序运行程序江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NET3.6.3在在WPFWPF里使用里使用ArcGISEngineArcGISEngine控件的局限控件的局限性性l由于由于ArcGISEngine控件是控件是WindowsForms控件,因此控件,因此在在WPF应用程序中使用用程序中使用ArcGISEngine控件前,控件前,应先考先考虑一下几点局限:一下几点局限:ArcGISEngine

179、LicenseControl不能在不能在WPF窗体中使窗体中使用,必用,必须用用编程的方式将程的方式将ArcGISEnginelicense初始初始化;化;ArcGISEngine控件的属性和事件不能通控件的属性和事件不能通过XAML来来访问,而必,而必须通通过代代码来来访问;ArcGISEngine控件没有独立的属性,且只支持控件没有独立的属性,且只支持单向数向数据据绑定,只能将控件属性定,只能将控件属性绑定到定到WPF元素,反元素,反过来来则不不行;行;江西理工大学Developing GIS Applications with ArcObjects using C#.NETDeveloping GIS Applications with ArcObjects using C#.NETArcGISEngine控件和控件和WPF是是单独提交的,独提交的,这样一来,一来,WPF宿主容器里所有与宿主容器里所有与显示有关的属性如示有关的属性如Transform、Clip以及以及Opacity对控件不起作用;控件不起作用;WindowsForms控件的描控件的描绘不属于不属于WPF描描绘框架且框架且总是第一个被提交,因此是第一个被提交,因此如果如果WindowsForms控件和控件和WPF元素有重叠的元素有重叠的话,WPF元素将会被覆盖。元素将会被覆盖。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号