gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:2059回复:1

添加指北针和图例[讨论代码]

楼主#
更多 发布于:2003-11-17 11:02
Description:

This sample adds a north arrow and a legend to the page layout. North arrows and legends are types of map surrounds. Map surrounds are objects which are related to a map. All map surrounds are held inside a MapSurroundFrame container, an element object, and this frame is related to a MapFrame. This relationship enables, for example, north arrows to automatically rotate when their related map is rotated and it tells legends what layers and symbology a map has.

How to use:
1。Paste the code into VBA.
2。From the Macros dialog, run the AddMapSurrounds routine.

Public Sub AddMapSurrounds()
  Dim pMxDoc As IMxDocument
  Dim pActiveView As IActiveView
  Dim pEnv As IEnvelope
  Dim pID As New UID
  Dim pMapSurround As IMapSurround
  Dim pMarkerNorthArrow As IMarkerNorthArrow
  Dim pCharacterMarkerSymbol As ICharacterMarkerSymbol
  
  Set pMxDoc = Application.Document
  Set pActiveView = pMxDoc.PageLayout
  Set pEnv = New Envelope
  
  'Add a north arrow
  pEnv.PutCoords 0.2, 0.2, 1, 1
  pID.Value = "esriCore.MarkerNorthArrow"
  Set pMapSurround = CreateSurround(pID, pEnv, "North Arrow", pMxDoc.FocusMap, pMxDoc.PageLayout)
  'Change out the default north arrow
  Set pMarkerNorthArrow = pMapSurround 'QI
  Set pCharacterMarkerSymbol = 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 7.5, 0.2, 8.5, 4
  pID.Value = "esriCore.Legend"
  Set pMapSurround = CreateSurround(pID, pEnv, "Legend", pMxDoc.FocusMap, pMxDoc.PageLayout)
  
  'Refresh the graphics
  pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub


Private Function CreateSurround(pID As UID, pEnv As IEnvelope, strName As String, _
                           pMap As IMap, pPageLayout As IPageLayout) As IMapSurround
  
  Dim pGraphicsContainer As IGraphicsContainer
  Dim pActiveView As IActiveView
  Dim pMapSurroundFrame As IMapSurroundFrame
  Dim pMapSurround As IMapSurround
  Dim pMapFrame As IMapFrame
  Dim pElement As IElement
  
  'MapSurrounds are held in a MapSurroundFrame
  'MapSurroundFrames are related to MapFrames
  'MapFrames hold Maps
  Set pGraphicsContainer = pPageLayout
  Set pMapFrame = pGraphicsContainer.FindFrame(pMap)
  Set pMapSurroundFrame = 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
  Set pElement = pMapSurroundFrame
  Set pActiveView = pPageLayout
  pElement.Geometry = pEnv
  pElement.Activate pActiveView.ScreenDisplay
  pGraphicsContainer.AddElement pElement, 0
  
  Set CreateSurround = pMapSurroundFrame.MapSurround
End Function

喜欢0 评分0
Renon
路人甲
路人甲
  • 注册日期2003-08-01
  • 发帖数169
  • QQ6625162
  • 铜币66枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2003-11-21 14:21
不太明白,请详细说明
举报 回复(0) 喜欢(0)     评分
游客

返回顶部