Mapsui / Mapsui

Mapsui is a .NET Map component for: MAUI, WPF, Avalonia, Uno, Blazor, WinUI, Xamarin and Eto
https://mapsui.com
MIT License
1.21k stars 316 forks source link

MAUI: Double click on map #2676

Open NovaKs68 opened 3 months ago

NovaKs68 commented 3 months ago

Mapsui Version 5.0.0-beta.1

Mapsui Platform MAUI

Device Windows 11, Android Emulator pixel 5 api 34

Describe the bug When I double-click on the map. The Map.Info event is triggered twice with Single click as TapType. It must return a Double TapType.

To Reproduce Steps to reproduce the behavior:

  1. Subscribe to Map.Info event
  2. On the device, double click in the map
  3. Two single click events are triggered instead of one with double click

Expected behavior Tested on the demo website (Blazor) https://mapsui.com/v5/samples see bellow : image It's works on widgets.

I want to have the same behavior as in the demo plateform when double clicking on the "tap me" button.

Additional context Here is my implementation :

var map = new Mapsui.Map
{
    CRS = "EPSG:3857",
    BackColor = Mapsui.Styles.Color.Gray
};
map.Info += Map_Info;

private void Map_Info(object? sender, MapInfoEventArgs e)
{
    if (e.TapType == TapType.Double)
        Debug.WriteLine("Double tap at " + e.MapInfo.WorldPosition);
}

The log is never triggered.

On the source code of the project the double click seems to be detected in the TapIfNeeded() function from TapGestureTracker.cs. But the TapType seems also be overrided just after that with a single click value at the OnMapTapped() function from MapControl.cs.

pauldendulk commented 3 months ago

When I added double click my intention was to keep the MapInfo event like it was. However, I added the TapType to all tap events and now this has become confusing. I guess this needs to be fixed.

An alternative is to remove MapInfo and add a GetMapInfo() method to the eventArgs of all the other events. so they can be used for MapInfo instead.

pauldendulk commented 3 months ago

And thanks for testing beta1!

NovaKs68 commented 3 months ago

Thank you for your quick reply. In the meantime we have implemented the same code defined in the library on our side :

private bool _waitingForDoubleTap = false;
private readonly int _millisecondsToWaitForDoubleTap = 300;
private void ZoomOnDoubleClick(MapInfo mapInfo, TapType tapType)
{
    if (_waitingForDoubleTap)
        MapCtl.Map.Navigator.CenterOnAndZoomTo(mapInfo.WorldPosition, mapInfo.Resolution * 0.5, 500, Mapsui.Animations.Easing.CubicOut);
    else
        _ = StartWaitingForSecondTapAsync();
}

private async Task StartWaitingForSecondTapAsync()
{
    _waitingForDoubleTap = true;
    await Task.Delay(_millisecondsToWaitForDoubleTap);
    _waitingForDoubleTap = false;
}