Select to view content in your preferred language

Getting Selection Area

04-17-2023 08:14 AM
New Contributor II

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:


I see where I can use:




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


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

    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?


0 Kudos
2 Replies
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
New Contributor II

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

0 Kudos