Select to view content in your preferred language

Getting Selection Area

425
2
04-17-2023 08:14 AM
RussellSuter
Occasional Contributor

I think I know the answer to this but here goes.  What I need (beyond the selected features) is the geometry of the selection area in map coordinates.  What I'd like is to simply use what is already provided since that works great:

RussellSuter_0-1681743420953.png

I see where I can use:

 

MapSelectionChangedEvent.Subscribe(OnSelectionChanged);

 

to be notified when the selection is made and I get the features selected:

 

private void OnSelectionChanged(MapSelectionChangedEventArgs args)
{
    if (args.Map != _activeMap)
        return;

    UpdateForActiveMap(false, args.Selection.ToDictionary());
}

 

With this, I'm not seeing how to get the geometry of the selection area.  Is there a way to get the selection area without writing a whole new selection tool ala: FeatureSelectionTool?

Thanks! 

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

The input geometry is not passed through to the event handler.  You can easily write your own tool by creating a MapTool, then changing the SketchType (Rectangle, Line, Polygon etc.), and adding these lines to the OnSketchCompleteAsync method:

protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
  QueuedTask.Run(() =>
  {
    var selectionSet = MapView.Active.SelectFeatures(geometry);
    OnMySelectionEvent(geometry, selectionSet);
  });
  return base.OnSketchCompleteAsync(geometry);
}

Now you call your own event handler passing in the selection and the geometry.

 

0 Kudos
RussellSuter
Occasional Contributor

Yes. That's what I expected.  It is unfortunate that I need to replicate what is already there and working.

0 Kudos