『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

浩淼的天空:AO里面的MapGrid对象模型

浩淼的天空:AO里面的MapGrid对象模型
mapgrid也就是所谓的地图网格,它必须存在layout视图而不会在map视图中出现,在mapgrid模型里面,主要有四个内容:

       mapgrid也就是所谓的地图网格,它必须存在layout视图而不会在map视图中出现,在mapgrid模型里面,主要有四个内容:

       1.mapgrid及其子类,其子类都是coclass,可以创建

       2.mapgridborder类,创建网格的边缘

       3.mapgridlabel类,创建边缘的标签

       4.mapgridfactory,它可以依据默认的属性快速创建一个mapgrid

 

       在arcmap里面,看起来mappagelayout都是视图的一种,map管理layer,而pagelayout管理layout,但是实际上,mappagelayout都实现了iactiveviewigraphicscontainer接口,但是实际上是pagelayout管理mapframe,mapsurroundframeelementframe,其中mapframe管理了mapmapgrid对象。

mapsurroundframe管理了指北针,legend,mapinset等对象 

       下面是一个mapgrid的例子:

 

Sub MapGrid()

 

    '找到当前所使用的MapFrame

    Dim pMxDoc As

IMxDocument

    Dim pMap As IMap

    Dim pGrahpicsContainer As

IGraphicsContainer

    Dim pMapFrame As IMapFrame

   

    Set pMxDoc =

ThisDocument

    Set pMap = pMxDoc.FocusMap

    Set pGrahpicsContainer =

pMxDoc.PageLayout

    Set pMapFrame =

pGrahpicsContainer.FindFrame(pMap)

   

   

'生成一个Mapgrid对象,生成最简单的graticule网格

    Dim pMapGrid As IMapGrid

    Dim

pMeasuredGrid As IMeasuredGrid

    Set pMeasuredGrid = New Graticule

   

Set pMapGrid = pMeasuredGrid

   

    pMeasuredGrid.FixedOrigin =

True

    pMeasuredGrid.XIntervalSize = 10

    pMeasuredGrid.XOrigin =

-180

    pMeasuredGrid.YIntervalSize = 10

    pMeasuredGrid.YOrigin =

-90

   

    '生成mapgridborder

    Dim pCalibrateBorder As

ICalibratedMapGridBorder

    Set pCalibrateBorder = New

CalibratedMapGridBorder

    Dim pBackColor As IColor

    Dim pForeColor As

IColor

    Set pBackColor = New RgbColor

    Set pForeColor = New

RgbColor

    pBackColor.RGB = RGB(255, 255, 0)

    pForeColor.RGB = RGB(0,

255, 0)

    pCalibrateBorder.BackgroundColor = pBackColor

   

pCalibrateBorder.ForegroundColor = pForeColor

   

pCalibrateBorder.Alternating = True

    pCalibrateBorder.BorderWidth =

10

    pCalibrateBorder.Interval = 72

   

    '生成mapgridlabel

   

Dim pFormattedGridLabel As IFormattedGridLabel

    Set pFormattedGridLabel =

New FormattedGridLabel

    Dim pNumericFormat As INumericFormat

    Set

pNumericFormat = New NumericFormat

    pNumericFormat.AlignmentOption =

esriAlignLeft

    pNumericFormat.RoundingOption =

esriRoundNumberOfDecimals

    pNumericFormat.RoundingValue = 2

   

pNumericFormat.ShowPlusSign = False

    pNumericFormat.UseSeparator =

True

    pNumericFormat.ZeroPad = True

    pFormattedGridLabel.Format =

pNumericFormat

   

    '添加属性到mapgrid里面

    pMapGrid.Border =

pCalibrateBorder

    pMapGrid.LabelFormat = pFormattedGridLabel

   

'把这个Grid添加进地图里面,注意是MAPframe在管理

    Dim pMapGrids As IMapGrids

    Set

pMapGrids = pMapFrame

   

    Dim pActiveView As IActiveView

    Set

pActiveView = pMxDoc.PageLayout

   

    pMapGrids.AddMapGrid

pMapGrid

    pActiveView.PartialRefresh esriViewBackground, Nothing,

Nothing

   

End Sub

这段代码是VBA的,还没有转到控件上使用。

      京ICP备2025132830号-1 京公网安备 号