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.
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
}
}
}