Select to view content in your preferred language

GraphicsOverlay HitTestAsync replacement in 100.1

1452
5
Jump to solution
09-08-2017 09:25 AM
ChrisSmith10
Emerging Contributor
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

I think you can use GeometryEngine methods then to see if your selection rectangle intersects with the graphic geometries.

        private async void OnSelect(object sender, RoutedEventArgs e)
        {
            try
            {
                var rectangle = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
                foreach (var overlay in MyMapView.GraphicsOverlays)
                {
                    foreach (var graphic in overlay.Graphics)
                        graphic.IsSelected = GeometryEngine.Intersects(graphic.Geometry, rectangle);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }
        }

View solution in original post

0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor

The v100.x equivalent for this method is IdentifyGraphicsOverlayAsync providing a tolerance parameter will create the rectangle with this height and width, you can also provide the number of maximum results you want returned. There's also an overload for identifying all graphics overlays versus this one where hit test (or identify) will be done on specified graphics overlay only.

0 Kudos
ChrisSmith10
Emerging Contributor

Jennifer,

   The IdentifyGraphicsOverlayAsync method only allows for a square to be specified where  GraphicsOverlay.HitTestAsync Method (ViewBase, Rect, Int32) allows a rectangle.

Our use case is allowing the user to drag a selection rectangle on the map to select objects.

0 Kudos
JenniferNery
Esri Regular Contributor

I think you can use GeometryEngine methods then to see if your selection rectangle intersects with the graphic geometries.

        private async void OnSelect(object sender, RoutedEventArgs e)
        {
            try
            {
                var rectangle = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
                foreach (var overlay in MyMapView.GraphicsOverlays)
                {
                    foreach (var graphic in overlay.Graphics)
                        graphic.IsSelected = GeometryEngine.Intersects(graphic.Geometry, rectangle);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }
        }
0 Kudos
ChrisSmith10
Emerging Contributor

Jennifer,

   Thank you very much. I'll give that a try.

0 Kudos
ChrisSmith10
Emerging Contributor

Jennifer,

  Your suggestion worked well. Thank you.

0 Kudos