Select to view content in your preferred language

GeoViewTapped event stops working if a Graphic is Selected

271
5
07-29-2024 06:12 AM
Labels (1)
KarenRobine1
Regular Contributor

I've added a GeoViewTapped event to my MapView  (  MapView.GeoViewTapped += MapView_GeoViewTapped;) . It works for both GraphicOverlays as well as features. In some other code, I occasionally select the Graphic using graphic.IsSelected.  However, after selecting the graphic, if I click on the map at that location,  GeoViewTapped stops working on that location . I'm unable to identify features, that Graphic and any other GraphicOverlays at that location.  Any way to override this? Is this a bug?

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor

Knowing how this event is implemented, selection state shouldn't be able to affect the tapped event at all, so the behavior is very curious. Could you share a small sample app demonstrating this problem?

0 Kudos
KarenRobine1
Regular Contributor

Hi:
So I wrote a small MAUI app to show the error, but I can't get it to break in the code I wrote, which is strange.  But I did discover that the error has to do with zooming to the MapPoint that the user selected (from a model in a CollectionView (which is a view of Waypoints). It doesn't start working again till I pan the map (so the point isn't in the View), and then pan it back. Once I do that, I am able to click on the selected point and get my Identify popup to work.

Snippet of code follows (but not including the other methods as I think you should see what I'm doing without that).:

private async Task SelectGraphicAndZoomToGeom(Object obj)
{
try
{
if (obj != null && _waypointSettings != null && MapView != null && _waypointGraphOverlay != null && _waypointGraphOverlay?.Graphics != null && _waypointGraphOverlay?.Graphics.Count > 0)
{
if (obj is WaypointModel wm)
{

if (!string.IsNullOrEmpty(wm.Name) )
{
_waypointGraphOverlay?.ClearSelection();
Graphic? graph = Helpers.GeometryHelper.GetGraphicUsingKey("Name", wm.Name, _waypointGraphOverlay?.Graphics);
if (graph != null)
{
//I also tried graph.IsSelected = true
IEnumerable<Graphic>? graphs = (IEnumerable<Graphic>)[graph];
if (graphs != null)
_waypointGraphOverlay?.SelectGraphics(graphs);
}
}

Esri.ArcGISRuntime.Geometry.MapPoint? pt = Helpers.GeometryHelper.GetMapPointFromJson(wm.Wkid, wm.MapPoint);
Esri.ArcGISRuntime.Geometry.Polygon? poly = Helpers.GeometryHelper.GetBufferGeometry(pt, _waypointSettings.WaypointZoomScaleMi);
if (poly != null)
{
Viewpoint viewp = new Viewpoint(poly.Extent);
if (viewp != null)
{
//https://community.esri.com/t5/net-maps-sdk-questions/mapview-setviewpoint-changes-the-passed-paramet...
//https://community.esri.com/t5/net-maps-sdk-questions/viewpointchanged-event-raised-multiple-time/m-p...
await MapView.SetViewpointAsync(viewp);
var geom1 = MapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);

}

}
}
}

}
catch (Exception ex)
{
Debug.WriteLine($"MainViewModel.cs: SelectGraphicAndZoomToGeom(). Error Message: {ex.Message}. Stack Trace: {ex.StackTrace}");
}
}

0 Kudos
dotMorten_esri
Esri Notable Contributor

Have you tried setting a breakpoint in the very beginning of MapView_GeoViewTapped and making sure that gets hit, and the code isn't just bailing out because of some error or if-condition further down?

0 Kudos
KarenRobine1
Regular Contributor

Yes. I have set a breakpoint at the beginning of the MapView_GeoViewTapped event. Nothing happens till I move the map out of the points view, and then back in (although it has no problem with clicking anywhere other then the selected point). Other ideas?

0 Kudos
dotMorten_esri
Esri Notable Contributor

Sorry no. I looked over the code and can't see why this event wouldn't trigger in some cases.

You said it was maui... Are you seeing this behavior on iOS, Android, Catalyst or Windows? Or them all?

A reproducer would be very helpful, so we could debug this mystery.

Also if you can try v200.5 that shipped today that could be useful too, as we did make some tweaks to interaction to support the new GeometryEditor features, and could inadvertently have fixed this too, since it's much more robust now against different types of gestures.

0 Kudos