|
阅读:873回复:0
AO里面的MapGrid对象模型<P>mapgrid也就是所谓的地图网格,它必须存在layout视图而不会在map视图中出现,在mapgrid模型里面,主要有四个内容:<BR>1.mapgrid及其子类,其子类都是coclass,可以创建<BR>2.mapgrid的border类,创建网格的边缘<BR>3.mapgrid的label类,创建边缘的标签<BR>4.mapgridfactory,它可以依据默认的属性快速创建一个mapgrid</P><BR> <P>在arcmap里面,看起来map和pagelayout都是视图的一种,map管理layer,而pagelayout管理layout,但是实<BR>际上,map与pagelayout都实现了iactiveview和igraphicscontainer接口,但是实际上是pagelayout管理<BR>着mapframe,mapsurroundframe和elementframe,其中mapframe管理了map和mapgrid对象。<BR>mapsurroundframe管理了指北针,legend,mapinset等对象.</P><BR> <P>下面是一个mapgrid的例子:<BR><BR>Sub MapGrid()<BR><BR></P> <P> '找到当前所使用的MapFrame<BR> Dim pMxDoc As <BR>IMxDocument<BR> Dim pMap As IMap<BR> Dim pGrahpicsContainer As <BR>IGraphicsContainer<BR> Dim pMapFrame As IMapFrame<BR> <BR> Set pMxDoc = <BR>ThisDocument<BR> Set pMap = pMxDoc.FocusMap<BR> Set pGrahpicsContainer = <BR>pMxDoc.PageLayout<BR> Set pMapFrame = <BR>pGrahpicsContainer.FindFrame(pMap)<BR> <BR> <BR>'生成一个Mapgrid对象,生成最简单的graticule网格<BR> Dim pMapGrid As IMapGrid<BR> Dim <BR>pMeasuredGrid As IMeasuredGrid<BR> Set pMeasuredGrid = New Graticule<BR> <BR>Set pMapGrid = pMeasuredGrid<BR> <BR> pMeasuredGrid.FixedOrigin = <BR>True<BR> pMeasuredGrid.XIntervalSize = 10<BR> pMeasuredGrid.XOrigin = <BR>-180<BR> pMeasuredGrid.YIntervalSize = 10<BR> pMeasuredGrid.YOrigin = <BR>-90<BR> <BR> '生成mapgrid的border<BR> Dim pCalibrateBorder As <BR>ICalibratedMapGridBorder<BR> Set pCalibrateBorder = New <BR>CalibratedMapGridBorder<BR> Dim pBackColor As IColor<BR> Dim pForeColor As <BR>IColor<BR> Set pBackColor = New RgbColor<BR> Set pForeColor = New <BR>RgbColor<BR> pBackColor.RGB = RGB(255, 255, 0)<BR> pForeColor.RGB = RGB(0, <BR>255, 0)<BR> pCalibrateBorder.BackgroundColor = pBackColor<BR> <BR>pCalibrateBorder.ForegroundColor = pForeColor<BR> <BR>pCalibrateBorder.Alternating = True<BR> pCalibrateBorder.BorderWidth = <BR>10<BR> pCalibrateBorder.Interval = 72<BR> <BR> '生成mapgrid的label<BR> <BR>Dim pFormattedGridLabel As IFormattedGridLabel<BR> Set pFormattedGridLabel = <BR>New FormattedGridLabel<BR> Dim pNumericFormat As INumericFormat<BR> Set <BR>pNumericFormat = New NumericFormat<BR> pNumericFormat.AlignmentOption = <BR>esriAlignLeft<BR> pNumericFormat.RoundingOption = <BR>esriRoundNumberOfDecimals<BR> pNumericFormat.RoundingValue = 2<BR> <BR>pNumericFormat.ShowPlusSign = False<BR> pNumericFormat.UseSeparator = <BR>True<BR> pNumericFormat.ZeroPad = True<BR> pFormattedGridLabel.Format = <BR>pNumericFormat<BR> <BR> '添加属性到mapgrid里面<BR> pMapGrid.Border = <BR>pCalibrateBorder<BR> pMapGrid.LabelFormat = pFormattedGridLabel<BR> <BR>'把这个Grid添加进地图里面,注意是MAPframe在管理<BR> Dim pMapGrids As IMapGrids<BR> Set <BR>pMapGrids = pMapFrame<BR> <BR> Dim pActiveView As IActiveView<BR> Set <BR>pActiveView = pMxDoc.PageLayout<BR> <BR> pMapGrids.AddMapGrid <BR>pMapGrid<BR> pActiveView.PartialRefresh esriViewBackground, Nothing, <BR>Nothing<BR> <BR>End Sub</P> <P>这段代码是VBA的,还没有转到控件上使用。 </P> |
|
|