Is there a replacement for GraphicsOverlay.HitTestAsync Method (ViewBase, Rect, Int32) in runtime 100.1?
Solved! Go to Solution.
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);
}
}
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.
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.
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);
}
}
Jennifer,
Thank you very much. I'll give that a try.
Jennifer,
Your suggestion worked well. Thank you.