2

Is there a way in ArcObjects 10.4 that I can highlight a specific feature from a selection set.

I'd like to give visual feedback to my users when they are highlighting a feature in my form. I want the currently selected feature in my selection set to be highlighted (Yellow).

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 3, 2016 at 19:59

1 Answer 1

2

Assuming you have some way of finding the features you're after you can draw them on the screen as a temporary graphic (once) which will disappear on the next refresh or wire the AfterDraw event and call refresh which will run every time the view is refreshed.

Private Sub UltraHighlight(FeatureLayer As ESRI.ArcGIS.Carto.IFeatureLayer, OIDList As List(Of Long))
 Dim pLineSymbol As ESRI.ArcGIS.Display.ISimpleLineSymbol = New ESRI.ArcGIS.Display.SimpleLineSymbolClass()
 Dim pPolySymbol As ESRI.ArcGIS.Display.ISimpleFillSymbol = New ESRI.ArcGIS.Display.SimpleFillSymbolClass()
 Dim pMarkSymbol As ESRI.ArcGIS.Display.ISimpleMarkerSymbol = New ESRI.ArcGIS.Display.SimpleMarkerSymbol()
 Dim pColour As ESRI.ArcGIS.Display.IColor = New ESRI.ArcGIS.Display.RgbColorClass()
 pColour.RGB = &HFFFF00 ' Hex for yellow'
 pLineSymbol.Width = 3 ' nice and wide'
 pLineSymbol.Color = pColour
 pLineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid
 pPolySymbol.Outline = pLineSymbol ' use the wide yellow line as an outline'
 pPolySymbol.Color = pColour ' and fill with yellow'
 pPolySymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid 
 pMarkSymbol.Size = 12
 pMarkSymbol.Color = pColour
 pMarkSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle
 ' tell ArcGis you want to use the symbols now created'
 ' you can specify 4 symbols (line, marker, fill and text)'
 ' but only one of each. Note gMXDocument is a global IMXDocument'
 gMXDocument.ActiveView.ScreenDisplay.SetSymbol(pLineSymbol)
 gMXDocument.ActiveView.ScreenDisplay.SetSymbol(pPolySymbol)
 gMXDocument.ActiveView.ScreenDisplay.SetSymbol(pMarkSymbol)
 ' you can only draw to the screen between calls to IActiveView.ScreenDisplay.StartDrawing'
 ' and IActiveView.ScreenDisplay.FinishDrawing unless you are responding to the IActiveViewEvents::AfterDraw'
 ' event. See http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001w000000vr000000'
 gMXDocument.ActiveView.ScreenDisplay.StartDrawing(0, ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)
 ' somehow identify the features you want to draw.. I'll call it an OID set as a list'
 ' because its easy to show what's happening. You need to customize it for your tool'
 Dim pFeat As IFeature
 Dim pGeom As IGeometry
 For Each ThisOID As Long In OIDList
 Try
 pFeat = FeatureLayer.FeatureClass.GetFeature(ThisOID)
 pGeom = pFeat.ShapeCopy
 If Not pGeom.IsEmpty Then
 If pGeom.GeometryType = esriGeometryType.esriGeometryLine Then
 gMXDocument.ActiveView.ScreenDisplay.DrawPolyline(pGeom)
 ElseIf pGeom.GeometryType = esriGeometryType.esriGeometryPolygon Then
 gMXDocument.ActiveView.ScreenDisplay.DrawPolygon(pGeom)
 ElseIf pGeom.GeometryType = esriGeometryType.esriGeometryPoint Then
 gMXDocument.ActiveView.ScreenDisplay.DrawPoint(pGeom)
 ElseIf pGeom.GeometryType = esriGeometryType.esriGeometryMultipoint Then
 gMXDocument.ActiveView.ScreenDisplay.DrawMultipoint(pGeom)
 End If
 End If
 Catch ex As Exception
 Debug.Print("Unable to select feature")
 End Try
 Next
 gMXDocument.ActiveView.ScreenDisplay.FinishDrawing()
End Sub

The workflow is:

  1. Create your symbols. Not knowing what features you're expecting create one for polygon, line and point; these all implement ISymbol which is what is required for SetSymbol.
  2. Set the symbols for your active view screen display.
  3. Start drawing, if you don't do this there may not be any errors shown but nothing will draw.
  4. Find your features, obtain the geometries then using the IGeometry.GeometryType enumeration draw your geometries with DrawPolyline, DrawPolygon, DrawPoint or DrawMultipoint, each one will draw a specific geometry type only.
  5. Finish drawing, same as start drawing, no errors may be generated but nothing will appear.

You can see another example in the Flash Geometry Snippet.

As the drawing will go away on the next refresh if you want to make this permanent then you will need call this during IActiveViewEvents::AfterDraw with esriViewDrawPhase.esriViewGeoSelection or esriViewGraphics; I'm not sure which phase will fire just after the selected features - if you operate on the earlier phase the drawing will appear and be masked by the features or selection! If you are responding to the AfterDraw event comment out gMXDocument...StartDrawing and gMXDocument..FinishDrawing()

answered Aug 9, 2016 at 3:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.