I use vb.net arcobjects create a buffer around a polyline feature once it is selected. The problem is the buffer has a obvious colour. Since I have other functions on the selected feature, I cannot clear the buffer because user may still need the feature selected.
When I select another feature, the new buffer will created and old buffer cleared. But there always a buffer which makes the polyline there looks different from other features in the same layer.
So I am thinking whether can make the buffer transparent so that it wouldn't affect the overview of the map.
My code is from an ESRI web sample:
Public Sub CreateGraphicBuffersAroundSelectedFeatures(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal distance As System.Double)
'parameter check
If activeView Is Nothing OrElse distance < 0 Then
Return
End If
Dim map As ESRI.ArcGIS.Carto.IMap = activeView.FocusMap
' Clear any previous buffers from the screen
Dim graphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer = CType(map, ESRI.ArcGIS.Carto.IGraphicsContainer) ' Explicit Cast
graphicsContainer.DeleteAllElements()
' Verify there is a feature(s) selected
If map.SelectionCount = 0 Then
Return
End If
' Reset to the first selected feature
Dim enumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature = CType(map.FeatureSelection, ESRI.ArcGIS.Geodatabase.IEnumFeature) ' Explicit Cast
enumFeature.Reset()
Dim feature As ESRI.ArcGIS.Geodatabase.IFeature = enumFeature.Next()
' Buffer all the selected features by the buffer distance and create a new polygon element from each result
Dim topologicalOperator As ESRI.ArcGIS.Geometry.ITopologicalOperator
Dim element As ESRI.ArcGIS.Carto.IElement
Do While Not (feature Is Nothing)
topologicalOperator = CType(feature.Shape, ESRI.ArcGIS.Geometry.ITopologicalOperator) ' Explicit Cast
element = New ESRI.ArcGIS.Carto.PolygonElementClass()
element.Geometry = topologicalOperator.Buffer(distance)
graphicsContainer.AddElement(element, 0)
feature = enumFeature.Next()
Loop
activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
End Sub
I am using vb.net arcobjects and arcmap 10.2. Any advice on it?
Answer
The following VBA code grabs the first polygon graphic on the Map and sets the transparency. The problem is that graphics don't appear to support true transparency. In the Help for IColor.Transparency
is states:
...For graphic elements, 0 for transparent and 255 for opaque are the only supported values...
Public Sub MakeTransparent()
' Get map document
Dim pMXDoc As IMxDocument
Set pMXDoc = ThisDocument
' Get Map
Dim pMap As IMap
Set pMap = pMXDoc.FocusMap
' Get Graphics Container for map
Dim pGC As IGraphicsContainer
Set pGC = pMap
pGC.Reset
' Get first graphic, assumed to be polygon
Dim pElement As IElement
Set pElement = pGC.Next
' Get symbol of graphic and its colour
Dim pFillShapeElement As IFillShapeElement
Set pFillShapeElement = pElement
Dim pFillSymbol As IFillSymbol
Set pFillSymbol = pFillShapeElement.Symbol
Dim pColour As IColor
Set pColour = pFillSymbol.Color
' Set transparency
pColour.Transparency = 0 ' Only 0 or 255 is support
pFillSymbol.Color = pColour
pFillShapeElement.Symbol = pFillSymbol
' Refresh map
pMXDoc.ActiveView.Refresh
End Sub
No comments:
Post a Comment