I want to select a feature by using a geometry in a map like in IMap interface in ArcObjects and get the feature object too.
// ArcObjects
void SelectByShape(IGeometry Shape, ISelectionEnvironment env, bool justOne);
Note: I know that I can use
var features = activeView.GetFeatures(geometry);
But this method exists in the MapView class not in the Map class.
Selection is on the MapView. Not the Map.
Okay, then how can I enforce it to select only one feature ? or I have to use QueryFilter after use GetFeatures method ?
Charlie is correct here are some examples:
MapView.Active.SelectFeatures(MapView.Active.Extent);
or
var selection = MapView.Active.SelectFeatures(clipPoly);
You have to run the SelectFeatures method on the MCT meaning you have to use QueuedTask.Run as in the MapTool sample below:
internal class MapTool1 : MapTool
{
public MapTool1()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Polygon;
SketchOutputMode = SketchOutputMode.Map;
}
protected override Task OnToolActivateAsync(bool active)
{
return base.OnToolActivateAsync(active);
}
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
// https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11992.html
bool result = await QueuedTask.Run(() =>
{
var selectionSet = MapView.Active.SelectFeatures(geometry);
return true;
});
return result;
}
}