Select to view content in your preferred language

Programatically selecting features in Pro 3 API

1010
2
Jump to solution
07-08-2022 10:51 AM
StuartBricker
New Contributor III

In the 2.x API, I was able to set the map selection via the below code.

 

MapView.Active.Map.SetSelection(new Dictionary<MapMember, List<long>> { { bFl, oidList } });

 

 in 3.0, this code errors out, but the intellisense says that the SetSelection method takes a SelectionSet object as a parameter.

selset.png

However, I cannot figure out how to instantiate a SelectionSet object. There is no useful information in the API reference for SelectionSet, and the only snippet for the .SetSelection()  method is how to clear the selection with .SetSelection(null).

So I am at a loss. How does one programatically select features on the map with the new 3.0 API, given a BasicFeatureLayer object and a list of objectIDs?

 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If you have the dictionary as in:

var selectionDictionary = new Dictionary<MapMember, List<long>>();

 You can then use the static 'FromDictionary' method to create a selection set like this sample (from community samples) that uses a selection set to flash a set of corresponding features:

await QueuedTask.Run(() =>
{
	//Flash the collection of features.
	var selectionSet = SelectionSet.FromDictionary(selectionDictionary);
	mapView.FlashFeature(selectionSet);
});

Also there is a sample in the 3.0-Migration-Guide that you can find if you search for "SelectionSet" or "FromDictionary".

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If you have the dictionary as in:

var selectionDictionary = new Dictionary<MapMember, List<long>>();

 You can then use the static 'FromDictionary' method to create a selection set like this sample (from community samples) that uses a selection set to flash a set of corresponding features:

await QueuedTask.Run(() =>
{
	//Flash the collection of features.
	var selectionSet = SelectionSet.FromDictionary(selectionDictionary);
	mapView.FlashFeature(selectionSet);
});

Also there is a sample in the 3.0-Migration-Guide that you can find if you search for "SelectionSet" or "FromDictionary".

0 Kudos
StuartBricker
New Contributor III

Thank you so much, @Wolf. I appreciate your reply, and so does my blood pressure & sanity 🙂

0 Kudos