Xamarin: Handling graphic click events

1083
1
Jump to solution
04-25-2017 06:39 PM
brianbullas
New Contributor III

I want to be able to run some code when a graphic or feature is clicked on.

On the mapview, I can see a tap handler(OnGeoViewDoubleTapped and OnGeoViewTapped), but it returns the MapView and a point in the event.

I can't find in the FeatureTable or the GraphicsOverlay a way to handle a click event...IE run some code when a Feature or Graphic is clicked on.

The only solution i can see is to use the GeoViewInputEventArgs e, find the point they clicked on, then do a query to see what they clicked on.

Is anyone able to tell me how to properly handle a click event on a feature or graphic?

0 Kudos
1 Solution

Accepted Solutions
brianbullas
New Contributor III

OK, I found the following in the samples. It's mostly doing what i thought....

var tolerance = 10d; // Use larger tolerance for touch
             var maximumResults = 1; // Only return one graphic  
             var onlyReturnPopups = false; // Don't return only popups

             // Use the following method to identify graphics in a specific graphics overlay
             IdentifyGraphicsOverlayResult identifyResults = await TreeMapView.IdentifyGraphicsOverlayAsync(
                 _workingLayer,
                 e.Position,
                 tolerance,
                 onlyReturnPopups,
                 maximumResults);

             // Check if we got results
             if (identifyResults.Graphics.Count > 0)
             {
                 // Make sure that the UI changes are done in the UI thread
                 Device.BeginInvokeOnMainThread(async () => {
                     await DisplayAlert("", "Tapped on graphic", "OK");
                 });
             }

View solution in original post

1 Reply
brianbullas
New Contributor III

OK, I found the following in the samples. It's mostly doing what i thought....

var tolerance = 10d; // Use larger tolerance for touch
             var maximumResults = 1; // Only return one graphic  
             var onlyReturnPopups = false; // Don't return only popups

             // Use the following method to identify graphics in a specific graphics overlay
             IdentifyGraphicsOverlayResult identifyResults = await TreeMapView.IdentifyGraphicsOverlayAsync(
                 _workingLayer,
                 e.Position,
                 tolerance,
                 onlyReturnPopups,
                 maximumResults);

             // Check if we got results
             if (identifyResults.Graphics.Count > 0)
             {
                 // Make sure that the UI changes are done in the UI thread
                 Device.BeginInvokeOnMainThread(async () => {
                     await DisplayAlert("", "Tapped on graphic", "OK");
                 });
             }