Select to view content in your preferred language

LocationDisplay Events

114
1
a month ago
Labels (1)
pinisolomon1
Emerging Contributor

Hi,

I started using the location display feature for my WinUI application and I'm not sure about something, I want to be able to catch an event of click or right click on the self-location symbol and it seems that there is no such an event.
In case I wasn't missing the obvious What would be the recommended way for me to catch this kind of event?

(trying to be clear I want click mouse of self-location) 

thank you.

0 Kudos
1 Reply
dotMorten_esri
Esri Notable Contributor

You are correct there's no event like this currently.


You could use the GeoViewTapped event and compare the location of the tapped event to the location of the location display. I'd recommend using the screen location of the click event and convert the locationdisplay location to screen coordinates using MapView.LocationToScreen(location), so you can calculate in pixels how far away from the location the click was, and you can just set a threshold of the size of the symbol. This is all a pretty cheap calculation to make so shouldn't cause any overhead.

Something along the lines of( (not tested):

 


private void MapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
{
    if ((sender as MapView)?.LocationDisplay?.Location?.Position is MapPoint location)
    {
        var screenLocation = mapView.LocationToScreen(location);
        var distance = Math.Sqrt(Math.Pow(e.Position.X - screenLocation.X, 2) + Math.Pow(e.Position.Y - screenLocation.Y, 2));
        if (distance < 12)
        {
            // You clicked location
        }
    }
}

 




0 Kudos