FeatureLayer.SelectFeature() - Polygon fill symbol (Colorize the area of a polygon)

2212
4
Jump to solution
01-21-2016 11:49 AM
OliverBrandt2
New Contributor II

Hi all,

how can I fill the whole polygone after selecting it on a featureLayer? FeatureLayer supports only to highlight the lines of the polygon by default. In ArcMap it is possible to set a selection symbol, which allows to color the included area.

Do anybody have an idea to solve this?

Thank you guys!

0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus1
Regular Contributor II

Hi Oliver,

I think that you need to copy the feature as a graphic to GraphicsOverlay and define your custom selection symbol as a symbol for that one. Also you might want to hide the selected feature from the FeatureLayer using featureLayer.SetVisibility method. There is a bit more code involved with this approach but it gives you full control what is shown with what symbols and when.

View solution in original post

4 Replies
AnttiKajanus1
Regular Contributor II

Hi Oliver,

I think that you need to copy the feature as a graphic to GraphicsOverlay and define your custom selection symbol as a symbol for that one. Also you might want to hide the selected feature from the FeatureLayer using featureLayer.SetVisibility method. There is a bit more code involved with this approach but it gives you full control what is shown with what symbols and when.

OliverBrandt2
New Contributor II

Hi Antti,

thanks for your response. Taking the geometry and creating a graphic out of it, is an good approach. I'll try this.

0 Kudos
HanhanSun1
Esri Contributor

Hi Oliver,

The following VBA sample is able to set the selection symbol to be solid green:

Public Sub SetSeleSymbol()

    Dim pMxDoc As IMxDocument

    Set pMxDoc = ThisDocument

    Dim pMap As IMap

    Set pMap = pMxDoc.FocusMap

    Dim pFeatLayer As IFeatureLayer

    Set pFeatLayer = pMap.Layer(0)

    Dim featSel As IFeatureSelection

    Set featSel = pFeatLayer

    Dim polySym As ISimpleFillSymbol

    Set polySym = New SimpleFillSymbol

    Dim pColor1 As IRgbColor

    Set pColor1 = New RgbColor

    pColor1.Red = 0

    pColor1.Green = 250

    pColor1.Blue = 0

    Dim pcolor2 As IRgbColor

    Set pcolor2 = New RgbColor

    pcolor2.Red = 0

    pcolor2.Green = 0

    pcolor2.Blue = 250

    Dim pLineSym As ILineSymbol

    Set pLineSym = New SimpleLineSymbol

    pLineSym.Color = pcolor2

    pLineSym.Width = 2

    polySym.Color = pColor1

    polySym.Outline = pLineSym

    featSel.SetSelectionSymbol = True

    Set featSel.SelectionSymbol = polySym

End Sub

Results will be like this:

0 Kudos
OliverBrandt2
New Contributor II

Thank you! This is an very interesting example, but we are using ArcGIS runtime for .NET.

I worked with Antti's approach.

My Code is:

var color = Color.FromArgb(150,140,235,240);

var selectionColor = new SimpleFillSymbol

            {

                Color = color

            };

var selectedPolygon = GeodatabaseFeature.AsGraphic();

selectedPolygon.Symbol = selectionColor;

_MapView.GraphicsOverlays[PolygonGraphicsOverlayKey].Graphics.Add(selectedPolygon);

At my clearSelection method I clear the PolygonGraphicsOverlay as well. This works very good for me.

0 Kudos