GIS应用开发完整3PPT课件_第1页
GIS应用开发完整3PPT课件_第2页
GIS应用开发完整3PPT课件_第3页
GIS应用开发完整3PPT课件_第4页
GIS应用开发完整3PPT课件_第5页
已阅读5页,还剩149页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精选,GIS应用开发DevelopingGISApplicationswithArcObjectsusingC#.NET,精选,教学目标,GIS应用开发课程是GIS研究生重要的专业课程,通过课程的学习,了解ArcGIS软件体系结构及ArcObjects(ArcGISEngine)组件构成,并能熟练使用ArcObjects(ArcGISEngine)进行应用型GIS开发;掌握应用型GIS开发的基本思路、技术方法.,精选,Chap.3使用ArcObjects控件编程(6学时),为了能够快速建构一个具有GIS功能的独立应用程序,ArcGISEngine为开发者提供了多个可视化的组件即控件,如LicenseControl、MapControl、PageLayoutControl、TOCControl、ToolbarControl和SymbologyControl等。在VS.NET中使用ArcObjects,需要使用ESRIinterop程序集,这些程序集在托管的.NET代码和非托管的COM代码之间起了桥梁作用。ESRIinterop程序集为ArcGIS控件提供了能够位于.NET窗体上的控件(继承自AxHost类),这些控件名前缀为“Ax”,如AxMapControl、AxPageLayoutControl、AxTOCControl和AxToolbarControl等。,精选,UsingArcGISEnginecontrolsinWinformsUsingArcGISEngineControlsinWPF,精选,本章内容:,MapControl控件PageLayoutControl控件TOCControl控件ToolbarControl及相关对象ControlCommands(SymbologyControlinChapter6)在WPF程序中使用ArcGISEngine控件,精选,3.1MapControl控件,MapControl对应于ArcMap中的数据视图,其主要功能为空间数据浏览、空间数据可视化、空间查询、空间分析、空间数据编辑等。在可视化环境中,可以通过控件的“属性”页设置控件的相关属性,也可以通过编程来设置。,精选,精选,MapControl是对Map对象的封装,并提供了额外的属性、方法、事件用于:管理控件的外观、显示属性和地图属性;添加并管理控件中的数据层(datalayers);装载Map文档(mxd)到控件中;从其它应用程序拖放数据到控件中;使用鼠标拉绘几何形状并绘制到屏幕显示中。,精选,3.1.1MapControl的主要接口,MapControl实现的主要接口有:IMapControlDefaultIMapControl2IMapControl3IMapControl4(newin9.2)IMapControlEvents2事件接口ITOCBuddyIToolbarBuddy,精选,IMapControlDefault接口,IMapControlDefault接口是地图控件缺省接口,多数开发环境自动使用这个接口定义的属性、方法。由于MapControl是一个自动化控件,当它被放到一个容器-如窗体上后,它会自动产生一个被称为axMapControl1的对象,这个对象可以直接使用缺省接口定义的属性和方法。这个接口也代表了控件最新版本的接口,MapControl当前最新版本接口为IMapControl4.当需要使用这个接口的时候,可以使用下面的代码:IMapControlDefaultpMapControl=axMapControl1.ObjectasIMapControlDefault;,精选,IMapControl2.Extent:地图的可视范围;IMapControl2.FullExtent:地图中所有图层的覆盖范围.,精选,IMapControl4接口,IMapControl4是任何一个与MapControl相关的任务的出发点,如设置控件外观,设置Map对象或控件的显示属性,添加或者管理图层、地图文档,在控件上绘制图形和返回Geometry等。,精选,IMapControl2,精选,精选,IMapControl3与IMapControl4,IMapControl3接口继承IMapControl2,并增加了以下8个属性和一个方法:CustomProperty-object:使用该属性关联有用信息DocumentFilename-string):返回MapControl装入的地图文档的文件名DocumentMap-string:返回MapControl最后装入的地图(Map)名称KeyIntercept-int:返回或设置MapControl截取键盘按键信息,精选,Object-object:返回潜在的MapControl控件,当在VB.NET或C#.NET中使用IMapControl2时,一定要使用Object属性或者使用指定容器的代码。因为对于.NET,真正的控件是被包装于宿主对象里面的。ShowMapTips-bool:确定是否显示地图的MapTipsTipDelay-int:设置MapTips的延迟时间TipStyle-esriTipStyle:设置MapTips的显示样式SuppressResizeDrawing():在控件尺寸发生变化过程中,阻止数据实时重绘,精选,与IMapControl3相比,IMapControl4多了以下两个可读写属性:publicboolAutoKeyboardScrollingget;set;:确定是否使用键盘上的Home(keyCode36)键、End(keyCode35)键、PageDown(keyCode34)键、PageUp(keyCode33)键和箭头键(keyCode37-40)来平移控件中的地图,缺省情况下该属性为true.绝大多数开发环境使用箭头键来切换窗体或容器中的焦点控件;在这些开发环境中,缺省情况下MapControl不会接收箭头键来平移地图的显示。为确保箭头键能够被MapControl接收并平移地图的显示,KeyIntercept属性应设置为拦截箭头键(esriKeyInterceptArrowKeys),且AutoKeyboardScrolling设置为true。,精选,publicboolAutoMouseWheelget;set;:确定鼠标滚轮是否用于缩放地图的显示;缺省情况下该属性为true。,精选,引用控件本身,当使用IMapControl2接口时:IMapControl2pMapControl=axMapControl1.ObjectasIMapControl2;或IMapControl2pMapControl=axMapControl1.GetOcx()asIMapControl2;当使用IMapControl3接口时:IMapControl3pMapControl=axMapControl1.ObjectasIMapControl3;或IMapControl3pMapControl=axMapControl1.GetOcx()asIMapControl3;,精选,当使用IMapControl4接口时:IMapControl4pMapControl;pMapControl=axMapControl1.ObjectasIMapControl4;或pMapControl=axMapControl1.GetOcx()asIMapControl4;,精选,使用箭头键、鼠标滚轮实现地图导航,使用箭头键平移(Panning)地图axMapControl1.KeyIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;axMapControl1.AutoKeyboardScrolling=true;使用鼠标滚轮缩放地图axMapControl1.AutoMouseWheel=true;,精选,axMapControl1.KeyIntercept=(int)esriKeyIntercept.esriKeyInterceptArrowKeys;AutoKeyboardScrolling=true;,精选,IMapControlEvents2接口,IMapControlEvents2是一个事件接口,它定义了MapControl能够处理的全部事件,如OnExtentUpdated是地图的Extent(可视范围)属性发生变化时触发的事件,OnAfterscreenDraw是绘屏结束后触发的事件等。当地图的覆盖范围变化时,触发OnFullExtentUpdated事件,例如,往地图中新增加一个图层,其覆盖范围大于原图的范围。?,精选,在绝大多数开发环境中,没有必要手工编写代码进行事件的注册,而只需在控件的属性窗口中双击某事件自动进行事件与其处理方法的关联。,精选,ITOCBuddy,该接口定义了以下2个方法:GetActiveViewReturnstheunderlyingobjectimplementingbasicmapandActiveView.ThisisusedtopopulatetheTOC.GetScaleReturnsthescaleofthesuppliedBasicMap,thisallowsforobjectsthatdonotsupportIMap.,精选,IToolbarBuddy,ObjectsthatimplementtheIToolbarBuddyinterfacecanbepassedtotheIToolbarControl.SetBuddyControlmethod.TheCurrentToolisthetoolusedtointeractwiththedisplayareaoftheIToolbarControl.Buddy.,精选,Samples:MapAndPageLayoutSynchAppMapControlMapTipsMapControlGeoEventsMapControlDrawTextMapControlCADViewerMapControlSaveLayerFile,精选,Guid.ToString(stringformat)命名空间:System;程序集:mscorlibformat一个单格式说明符,它指示如何格式化此Guid的值。format参数可以是“N”、“D”、“B”或“P”。,精选,3.1.2MapControl控件与MXD文件,MapControl控件可以“链接”或“包含”地图文档。对于文档文件,MapControl控件可以直接使用LoadMxFile方法来载入,这是最简单的方法。除此之外,可以使用IMapDocument接口定义的属性和方法来加载一个MXD文件。,精选,下面是一个载入文档的例子-axMapControl1.LoadMxFile,privatevoidLoadMapDocument()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);elseMessageBox.Show(sFilePath+isnotavalidArcMapdocument);return;,精选,在ArcMap中使用的地图文档对象为MxDocument,其主要接口是IMxDocument;在使用控件开发的独立应用程序中,使用的地图文档对象为MapDocument,其主要接口是IMapDocument。IMapDocument接口定义了操作和管理文档对象的方法和属性。MapDocument类能够封装地图文档文件,如mxd、mxt和pmf等,它也可以封装一个图层文件(*.lyr)。使用这个对象可以获取和更新一个文档的内容,设置文档文件的读、写属性,保存一个文档文件(*.mxd)。,精选,IMxDocument与IMapDocument,精选,精选,IApplication的属性、方法,精选,IMxDocument.ActivatedView与ActiveView属性在ArcMap的布局视图(layoutview)状态下,图形元素可以添加到页面布局(PageLayout)或焦点地图(focusMap)的图形元素容器(graphicscontainer)中;这时,IMxDocument.ActiveView属性与IMxDocument.ActivatedView属性不同,ActiveView属性引用PageLayout对象,ActivatedView属性引用焦点地图对象(如果该地图对象处于活动状态)。在ArcMap的数据视图(dataview)状态下,ActiveView与ActivatedView属性都引用焦点地图对象。,精选,IMapDocumentm_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(stringsDocument,stringbsPassword);,publicboolget_IsMapDocument(stringsDocument);,精选,privatevoidSaveDocument()if(m_MapDocument.get_IsReadOnly(m_MapDocument.DocumentFilename)=true)MessageBox.Show(Thismapdocumentisreadonly!);return;m_MapDocument.Save(m_MapDocument.UsesRelativePaths,true);MessageBox.Show(Changessavedsuccessfully!);,publicvoidSave(boolbUseRelativePaths,boolbCreateThumnbail);,精选,3.1.3鼠标与控件的交互,用鼠标和地图控件进行交互是最常用的操作,例如改变地图显示范围、移动地图,在控件上绘制几何图形等。,精选,使用鼠标拖曳确定地图显示的范围(拉框放大),privatevoidaxMapControl1_OnMouseDown(objectsender,ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente)/改变地图控件显示范围为当前拖曳的区域axMapControl1.Extent=axMapControl1.TrackRectangle();/刷新地图axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);,publicvoidRefresh(esriViewDrawPhasephase,objectlayerOrElement,objectenvelope);,精选,移动、旋转地图,在MapControl中有一种更简单便利的方法pan()来移动其中的地图。下面的方法使用在MapControl控件的OnMoseDown事件中:axMapControl1.pan();axMapControl1.Rotation=45;,精选,在MapControl控件中绘制图形,MapControl控件提供了直接在控件上绘制图形和文字的方法DrawShape与DrawText,这两种绘制方法绘制的图形都是缓存(cache),而不能真正保存,一旦窗口重绘,这些图形就将消失。,精选,privatevoidaxMapControl1_OnMouseDown(objectsender,ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvente)/产生拖曳多边形,并绘制IGeometrypGeom=axMapControl1.TrackPolygon();DrawMapShape(pGeom);/刷新地图/axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography,null,null);,精选,privatevoidDrawMapShape(IGeometrypGeom)IRgbColorpColor;pColor=newRgbColorClass();pColor.Red=220;pColor.Green=112;pColor.Blue=60;/新建一个绘制图形的填充符号ISimpleFillSymbolpFillsyl;pFillsyl=newSimpleFillSymbolClass();pFillsyl.Color=pColor;objectoFillsyl=pFillsyl;axMapControl1.DrawShape(pGeom,refoFillsyl);,publicvoidDrawShape(IGeometryShape,refobjectsymbol);,精选,3.1.4数据选择,在MapControl控件中用户可以很方便地使用SelectByShape方法来构造一个基于Map的选择集。SelectByShape()方法选择控件中所有图层上处于选择范围内的要素,并将其设置为一个选择集。,精选,privatevoidaxMapControl1_OnMouseDown(objectsender,IMapControlEvents2_OnMouseDownEvente)/产生拖曳多边形IGeometrypGeom=axMapControl1.TrackPolygon();axMapControl1.Map.SelectByShape(pGeom,null,false);axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection,null,null);,精选,清除选择集的方法axMapControl1.Map.Clearselection();axMapControl1.ActiveView.Refresh();,精选,3.1.5实现鹰眼功能,精选,这个例子中有两个AxMapControl控件:主控件axMapControl1和鹰眼控件axMapControl2.要实现鹰眼功能,关键有两点:一是如何让两个控件显示的数据保持一致,另一点是如何绘制鹰眼控件中的显示方框。,精选,两个控件的数据共享,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);,精选,绘制鹰眼控件中的显示方框,主窗体视图的范围发生变化后,会触发控件的OnExtentUpdated事件,绘制方框的方法就在这个事件中进行:privatevoidaxMapControl1_OnExtentUpdated(objectsender,IMapControlEvents2_OnExtentUpdatedEvente).,精选,3.2PageLayoutControl控件,PageLayoutControl对应于ArcMap中的布局视图(LayoutView),它封装了PageLayout对象,提供了在布局视图中控制地图元素的属性和方法。PageLayoutControl控件用于制图,它可以方便地操作各种元素对象,以产生一幅制作精美的地图对象。与MapControl控件相似,PageLayoutControl控件并不仅仅只是包含了一个PageLayout对象,它也拥有许多附加的事件、属性和方法。,精选,页面布局(通常简称为布局)是在页面上编排和组织的地图元素的集合,旨在用于地图的排版设计、打印等。布局中排布的常见地图元素包括一个或多个数据框(每个数据框都含有一组有序的地图图层)、比例尺、指北针、地图标题、描述性文本和符号图例。打印机、页面布局、大小、单位,精选,精选,精选,数据驱动页面根据地图文档的某个要素图层或规则格网将地图分割为多个部分,然后为每个部分生成一个相应的页面。,精选,创建数据驱动页面,精选,PageLayoutControl控件同样实现了多个接口IPageLayoutControlDefaultIPageLayoutControlIPageLayoutControl2IPageLayoutControl3(Newin9.2)IPageLayoutControlEvents,精选,IPageLayoutControl3,精选,Samples:PageLayoutControlLoadMapDocumentPageLayoutControlCopyFocusMapPageLayoutControlOverviewPageLayoutControlPageAppearancePageLayoutControlPrintPreviewPageLayoutControlPrinting,精选,3.2.1PageLayoutControl操作MXD文件,在AxPageLayoutControl控件对MXD文件的操作,与MapControl类似。publicvoidLoadMxFile(stringfileName,objectpassword);,精选,下面是在PageLayout控件中打开一个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();,精选,privatevoidSaveDocument()/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!);,精选,privatevoidcmdSaveAs_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!);,精选,3.2.2PageLayout与MapControl联动,在ArcMap程序中,数据视图和布局视图中的数据改变是实时互动的。在使用ArcObjects控件开发的独立程序中实现这个功能,由于MapControl、PageLayoutControl两个控件本身并不能自动实时互动,用户只能够通过拷贝的方法来实时传递两个控件的内容。Sample:MapAndPageLayoutSynchApp,精选,3.3TOCControl控件,TOCControl控件概述ITOCControl与ITOCControl2ITOCControlEvents应用开发实例,精选,3.3.1TOCControl控件概述,TOCControl要与一个“伙伴控件”协同工作。“伙伴控件”可以是MapControl、PageLayoutControl、SceneControl或GlobeControl。TOCControl用“伙伴控件”来显示其地图、图层和符号体系内容的一个交互式树视图,并保持其内容与“伙伴控件”同步。例如,如果“伙伴控件”是一个MapControl,而且从该MapControl中删除了一个图层,则该图层也会从TOCControl中删除。同样地,如果终端用户与TOCControl交互并取消了某个图层的Visibility复选框,则该图层在MapControl中不再可见。,精选,TOCControl的“伙伴控件”可以在设计时通过TOCControl属性页设置或用SetBuddyControl方法通过编程设置。TOCControl的主要接口有:ITOCControl、ITOCControl2、ITOCControlEvents,精选,ITOCControl与ITOCControl2,ITOCControl接口是任何与TOCControl有关的任务的出发点,如设置控件的外观,设置伙伴控件,管理图层的可见性和标签的编辑。,精选,ITOCControl,LabelEdit、LayerVisibilityEdit:Label、Visibilityeditingstate.esriTOCControlAutomaticesriTOCControlManual,精选,在C#.NET环境中,当查询接口到ITOCControl或ITOCControl2时,必须使用Object属性或者容器指定代码。ITOCControlpTOCControl;pTOCControl=axTOCControl1.ObjectasITOCControl;或pTOCControl=axTOCControl1.GetOcx()asITOCControl;,精选,publicvoidHitTest(intX,intY,refesriTOCControlItemItemType,refIBasicMapBasicMap,refILayerLayer,refobjectUnk,refobjectData);用于获取用户在TOCControl中点击的信相关息。ItemType:TOCControl中项的类型,如none、map、layer、heading或legendclass.BasicMap:指定地图对象。Layer:ILayer对象。Unk:ILegendGroup(图例组,一个图层可以有多种符号化方案)对象。Data:用户点击的图例组中某个图例的索引号(长整型);联合使用图例组Unk和这个索引号,可以获得用户点击的图例(legendclass);如果这个索引号为-1,表明用户点击的是图例中的标题头。,精选,精选,IBasicMapmap=newMapClass();ILayerlayer=newFeatureLayerClass();objectother=newobject();objectindex=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;IGeoFeatureLayergeoFeatureLayer=(IGeoFeatureLayer)featureLayer;,精选,ILegendClasslegendClass=newLegendClassClass();ISymbolsymbol=null;if(otherisILegendGroup,精选,privateISymbolGetSymbolByControl(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;,精选,ITOCControl2(Newin9.2),与ITOCControl相比,ITOCControl2多了以下1个属性和2个方法:publicboolEnableLayerDragDropget;set;:指示图层是否可以拖放,以改变图层的顺序。publicvoidGetSelectedItem(refesriTOCControlItemItemType,refIBasicMapBasicMap,refILayerLayer,refobjectUnk,refobjectData):返回TOCControl中被选择项。publicvoidSelectItem(objectUnk,objectData):用于设置TOCControl中的选择项,如:,精选,/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);,精选,ITOCControlEvents,ITOCControlEvents是一个事件接口,它定义了TOCControl能够处理的全部事件,如OnMouseDown、OnMouseMove、OnMouseUp、OnDoubleClick、OnBeginLabelEdit、OnEndLabelEdit、OnKeyDown、OnKeyUp。,精选,privatevoidaxTOCControl1_OnBeginLabelEdit(objectsender,ITOCControlEvents_OnBeginLabelEditEvente)m_TOCControl.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);/已在其它地方(如窗体的Load事件中)声明为ITOCControl类型的变量,并已实例化if(item!=esriTOCControlItem.esriTOCControlItemLayer)e.canEdit=false;,精选,privatevoidaxTOCControl1_OnEndLabelEdit(objectsender,ITOCControlEvents_OnEndLabelEditEvente)/Preventemptylabelsif(e.newLabel.Trim()=)e.canEdit=false;,精选,SamplesTOCControlContextMenuTOCControlLayerDragDropTOCControlMetadataViewer,精选,3.3.2应用开发实例,TOC的右键菜单在ArcMap中,“TableofContents”中右键菜单功能非常丰厚,而TOCControl控件并没有提供右键菜单功能。要实现右键菜单功能,需要开发人员自己编程实现。,精选,当右键点击地图时,弹出当右键点击图层时,弹出,精选,首先要实现好右键菜单上的命令privatevoidMainForm_Load(objectsender,EventArgse)定义地图右键菜单、图层右键菜单privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)根据右键点击的对象,弹出相应的右键菜单,精选,IToolbarMenum_TocLayerMenu=newToolbarMenuClass();IToolbarMenum_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);,精选,m_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);,精选,privatevoidaxTOCControl1_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);,精选,publicsealedclassOpenAttributeTableCmd: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=newLayerAttributes(map,currentLayer);layerAttributeTa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论