Public SubAddMapSurrounds()
DimpMxDocAsIMxDocument
DimpActiveViewAsIActiveView
DimpEnvAsIEnvelope
DimpIDAs NewUID
DimpMapSurroundAsIMapSurround
DimpMarkerNorthArrowAsIMarkerNorthArrow
DimpCharacterMarkerSymbolAsICharacterMarkerSymbol
SetpMxDoc = Application.Document
SetpActiveView = pMxDoc.PageLayout
SetpEnv =NewEnvelope
'Add a north arrow
pEnv.PutCoords 0.2, 0.2, 1, 1
pID.Value = "esriCarto.MarkerNorthArrow"
SetpMapSurround = CreateSurround(pID, pEnv, "North Arrow", pMxDoc.FocusMap, pMxDoc.PageLayout)
'Change out the default north arrow
SetpMarkerNorthArrow = pMapSurround'QI
SetpCharacterMarkerSymbol = pMarkerNorthArrow.MarkerSymbol'clones the symbol
pCharacterMarkerSymbol.CharacterIndex = 200'change the symbol
pMarkerNorthArrow.MarkerSymbol = pCharacterMarkerSymbol'set it back
'Add a legend
'In this case just use the default legend
pEnv.PutCoords 1, 1, 3.4, 2.4
pID.Value = "esriCarto.Legend"
SetpMapSurround = CreateSurround(pID, pEnv, "Legend", pMxDoc.FocusMap, pMxDoc.PageLayout)
'Refresh the graphics
pActiveView.PartialRefresh esriViewGraphics,Nothing,NothingCreateSurround(pID
End Sub
Private FunctionAsUID, pEnvAsIEnvelope, strNameAs String, _
pMapAsIMap, pPageLayoutAsIPageLayout)AsIMapSurround
DimpGraphicsContainerAsIGraphicsContainer
DimpActiveViewAsIActiveView
DimpMapSurroundFrameAsIMapSurroundFrame
DimpMapSurroundAsIMapSurround
DimpMapFrameAsIMapFrame
DimpElementAsIElement
'MapSurrounds are held in a MapSurroundFrame
'MapSurroundFrames are related to MapFrames
'MapFrames hold Maps
SetpGraphicsContainer = pPageLayout
SetpMapFrame = pGraphicsContainer.FindFrame(pMap)
SetpMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID,Nothing)
pMapSurroundFrame.MapSurround.Name = strName
'Set the geometry of the MapSurroundFrame to give it a location
'Activate it and add it to the PageLayout's graphics container
SetpElement = pMapSurroundFrame
SetpActiveView = pPageLayout
pElement.Geometry = pEnv
pElement.Activate pActiveView.ScreenDisplay
'Allow the legend frame size to be altered after the legend has been
'added to the GraphicsContainer
DimPTrackAsITrackCancel
SetPTrack =NewCancelTracker
pElement.Draw pActiveView.ScreenDisplay, PTrack
pGraphicsContainer.AddElement pElement, 0
'Re-apply the change to the Legend MapSurroundFrame Geometry
pElement.Geometry = pEnv
SetCreateSurround = pMapSurroundFrame.MapSurroundEnd Function
实现在PageLayout控件中添加了图例、指北针或比例
最新推荐文章于 2020-02-24 15:41:10 发布
本文介绍如何使用 ArcGIS 的 VBA 编程接口自定义地图布局元素,如北向箭头和图例的位置及样式。通过创建 MapSurround 对象并调整其属性,可以实现地图布局的个性化设置。
1万+





