Customizing graphic selection in 100.x

1292
5
04-05-2019 07:04 PM
AndrewLeung
New Contributor II

In 100.x, graphic selection does not seem to be customizable. When graphic overlay's selectGraphics() is called, the map always highlights the graphics with a cyan outline.

In 10.2.x, selection was easily customizable by setting a selectionSymbol on the graphic. Is there an equivalent or similar way in 100.x?

From an earlier discussion (https://community.esri.com/thread/195355-selecting-a-graphic-in-agsgraphicsoverlay#comment-688706), it was suggested to manually assign a different symbol upon selection and revert back upon deselection. The problem with this approach is the default cyan outline is still applied to the graphic. Is there a way to disable that cyan outline while still using selectGraphics()? I don't want to skip selectGraphics() because then I will lose the ability to use selectedGraphics() and clearSelection().

0 Kudos
5 Replies
RyanOlson1
Esri Contributor

You can change selection color like so in swift:

            // set selection color
            let sp = AGSSelectionProperties(color: Color.green)
            mapView.selectionProperties = sp
Nicholas-Furness
Esri Regular Contributor

Note that if you're just using the AGSGraphicsOverlay's selection to track/flag certain graphics, you could set the mapView.selectionProperties.color property to UIColor.clear.

However, if that's the case, I would probably keep a separate Set<AGSGraphic> variable that I used to track those graphics. Granted, you might need to do some additional logic when graphics are removed from the AGSGraphicsOverlay, and it depends on what you're trying to do, but that could be a cleaner solution.

AndrewLeung
New Contributor II

Thank you both for your replies. Setting selectionProperties.color to UIColor.clear worked; it lets me hide the halo so I can apply a different symbol (thicker outlines and darker fill color) to a selected graphic manually.

However, managing selection is still much more involved than 10.2.x where I could have set each graphic's selectionSymbol ahead of time and not have to manually change the graphic's symbol at every selection/deselection. The same goes for AGSFeatureLayer; the selectionSymbol property is gone in 100.x.

Do you know what the rationale was for removing those properties in the new SDK and not having a similar alternative?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

As it happens, we just wrote a blog post discussing this: Selection behavior changes in Runtime 100.5 

At 10.2, you could set a selection symbol on the Graphics Layer or the Feature Layer, not the graphic itself. But yes, the behavior is changed at 100.x, for two primary reasons: performance, and consistency with the rest of the platform.

Our "halo" approach works well as selection feedback for a GIS but I can see it's not necessarily the best UX for a custom location app. I'll bring it up with the team.

If you're working with graphics overlays, one approach I've used in the past is to use a UniqueValueRenderer on a "highlighted" or "focused" attribute on the graphic. Rather than manipulating the graphics selection, you would set the attribute to "true" and let the renderer handle the rest. But that would get tricky once you started working with Feature Layers.

0 Kudos
AndrewLeung
New Contributor II

I will give UniqueValueRenderer a try. Thanks for bringing this up with your team!

0 Kudos