YouTube | Facebook | X(Twitter) | RSS

一時的な描画を AfterItemDraw イベントで描画し続ける方法

2016/9/1 (木)

Private WithEvents ActiveViewEvents As Map
 
Private m_pMxDoc As IMxDocument
Private m_pBufferPolygon As IPolygon
Private m_pLastBufferedExtent As IEnvelope
Private m_pFillSymbol As ISimpleFillSymbol
 
Public Sub InitEvents()
  Dim pViewManager As IViewManager
  Dim pRgbColor As IRgbColor
 
  Set m_pMxDoc = Application.Document
  Set pViewManager = m_pMxDoc.FocusMap
  pViewManager.VerboseEvents = True
  Set ActiveViewEvents = m_pMxDoc.FocusMap
 
'Create a fill symbol
  Set m_pFillSymbol = New SimpleFillSymbol
  Set pRgbColor = New RgbColor
  pRgbColor.Red = 255
  m_pFillSymbol.Style = esriSFSForwardDiagonal
  m_pFillSymbol.Color = pRgbColor
End Sub
 
Private Sub ActiveViewEvents_AfterItemDraw(ByVal Index As Integer, ByVal Display As IDisplay, ByVal phase As esriDrawPhase)
 
'Only draw in the geography phase
  If Not phase = esriDPGeography Then Exit Sub
'Draw the buffered polygon
  If m_pBufferPolygon Is Nothing Then Exit Sub
  With Display
    .SetSymbol m_pFillSymbol
    .DrawPolygon m_pBufferPolygon
  End With
 
End Sub
 
Private Sub ActiveViewEvents_SelectionChanged()
  Dim pActiveView As IActiveView
  Dim pEnumFeature As IEnumFeature
  Dim pFeature As IFeature
  Dim pPolygon As IPolygon
  Dim pTopoOperator As ITopologicalOperator
  Dim pGeometryBag As IGeometryCollection
 
  Set pActiveView = m_pMxDoc.FocusMap
  Set pGeometryBag = New GeometryBag
 
'Flag last buffered region for invalidation
  If Not m_pLastBufferedExtent Is Nothing Then
    pActiveView.PartialRefresh esriViewGeography, Nothing, m_pLastBufferedExtent
  End If
 
  If m_pMxDoc.FocusMap.SelectionCount = 0 Then
'Nothing selected; don't draw anything; bail
    Set m_pBufferPolygon = Nothing
    Exit Sub
  End If
 
'Buffer each selected feature
  Set pEnumFeature = m_pMxDoc.FocusMap.FeatureSelection
  pEnumFeature.Reset
  Set pFeature = pEnumFeature.Next
  Do While Not pFeature Is Nothing
    Set pTopoOperator = pFeature.Shape
    Set pPolygon = pTopoOperator.Buffer(10)
    pGeometryBag.AddGeometry pPolygon
'Get next feature
    Set pFeature = pEnumFeature.Next
  Loop
 
'Union all the buffers into one polygon
  Set m_pBufferPolygon = New Polygon
  Set pTopoOperator = m_pBufferPolygon 'QI
  pTopoOperator.ConstructUnion pGeometryBag
 
  Set m_pLastBufferedExtent = m_pBufferPolygon.Envelope
 
'Flag new buffered region for invalidation
  pActiveView.PartialRefresh esriViewGeography, Nothing, m_pBufferPolygon.Envelope
 
End Sub
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,