xuyunhe

如何画Polygon Buffers

本例要实现的是如何利用Polygon Buffer自定义记录选中时的显示方式。

l   要点

首先通过IRgbColor接口和ISimpleFillSymbol接口设置Polygon Buffer的填充方式。然后在发生SelectionChanged事件时,设置选中记录被显示时的边界并将选中的Polygon通过ITopologicalOperator.ConstructUnion方法,联合成一个临时的Polygon Buffer,使用IActiveView.PartialRefresh方法刷新这个Polygon Buffer区域,最后在发生AfterItemDraw事件时将这个Polygon Buffer画在Map上。

主要用到IPolygon接口,IEnvelope接口,ISimpleFillSymbol接口,IActiveView接口,IEnumFeature接口,IGeometryCollection接口和ITopologicalOperator接口。

l   程序说明

函数InitEvents是初始化变量并设置Polygon Buffer的填充方式。

AfterItemDraw事件实现的是画出Polygon Buffer。

SelectionChanged事件实现的是生成Polygon Buffer并设置边界。

l   代码

Private WithEvents ActiveViewEvents     As Map         
Private pMxDocument                     As IMxDocument
Private pBufferPolygon                  As IPolygon
Private pEnvelope                       As IEnvelope
Private pSimpleFillS                    As ISimpleFillSymbol 

Public Sub InitEvents()
    Dim pViewManager                    As IViewManager
    Dim pRgbColor                       As IRgbColor
    Set pMxDocument = Application.Document
    Set pViewManager = pMxDocument.FocusMap
    pViewManager.VerboseEvents = True
    Set ActiveViewEvents = pMxDocument.FocusMap
    \'Create a fill symbol
    Set pSimpleFillS = New SimpleFillSymbol
    Set pRgbColor = New RgbColor
    pRgbColor.Red = 255
    pSimpleFillS.Style = esriSFSForwardDiagonal
    pSimpleFillS.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 pBufferPolygon Is Nothing Then Exit Sub
    With Display
        .SetSymbol pSimpleFillS
        .DrawPolygon pBufferPolygon
    End With
End Sub 

Private Sub ActiveViewEvents_SelectionChanged()
    Dim pActiveView                     As IActiveView
    Dim pEnumFeature                    As IEnumFeature
    Dim pFeature                        As IFeature
    Dim pSelectionPolygon               As IPolygon
    Dim pTopologicalOperator            As ITopologicalOperator
    Dim pGeometryCollection             As IGeometryCollection
      Set pActiveView = pMxDocument.FocusMap
    Set pGeometryCollection = New GeometryBag
    \'Flag last buffered region for invalidation
    If Not pEnvelope Is Nothing Then
        pActiveView.PartialRefresh esriViewGeography, Nothing, pEnvelope
    End If
    If pMxDocument.FocusMap.SelectionCount = 0 Then
        \'Nothing selected; don\'t draw anything; bail
        Set pBufferPolygon = Nothing
        Exit Sub
    End If
    \'Buffer each selected feature
    Set pEnumFeature = pMxDocument.FocusMap.FeatureSelection
    pEnumFeature.Reset
    Set pFeature = pEnumFeature.Next
    Do While Not pFeature Is Nothing
        Set pTopologicalOperator = pFeature.Shape
        Set pSelectionPolygon = pTopologicalOperator.Buffer(0.1)
        pGeometryCollection.AddGeometry pSelectionPolygon
        \'Get next feature
        Set pFeature = pEnumFeature.Next
    Loop
    \'Union all the buffers into one polygon
    Set pBufferPolygon = New Polygon
    Set pTopologicalOperator = pBufferPolygon \'QI
    pTopologicalOperator.ConstructUnion pGeometryCollection
    Set pEnvelope = pBufferPolygon.Envelope
    \'Flag new buffered region for invalidation
    pActiveView.PartialRefresh esriViewGeography, Nothing, pBufferPolygon.Envelope
End Sub 

Private Sub UIButtonControl1_Click()
    InitEvents
End Sub

分类:

技术点:

相关文章:

  • 2021-07-25
  • 2021-10-31
  • 2021-06-24
  • 2021-12-13
  • 2021-07-26
  • 2021-05-30
  • 2022-01-04
  • 2021-07-24
猜你喜欢
  • 2021-06-29
  • 2021-12-31
  • 2022-01-07
  • 2021-07-30
  • 2021-04-28
  • 2021-08-09
相关资源
相似解决方案