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
一時的な描画を AfterItemDraw イベントで描画し続ける方法
2016/9/1 (木)