Mapsui: MapControl.TouchEnded is not always triggered
Mapsui Version 4.0.0-rc.2
Mapsui Platform Xamarin.Forms
Device Android & iOS
Background
I want to implement a custom behavior for single-finger dragging in a MapView. To achieve this, I enable MapView.PanLock (and possibly MapView.ZoomLock) and implement handlers for the events MapControl.TouchStarted, MapControl.TouchMove and MapControl.TouchEnded.
Describe the bug
TouchStarted and TouchMoved are basically triggered as expected, but I noticed that sometimes the TouchEnded event seems to be missing at the end of a single-finger dragging gesture.
At first I was completely puzzled about when the problem occurs, but after playing around for a while I noticed:
- When keeping the finger steady for a moment, before lifting it off the screen,
TouchEndedis triggered quite reliably. - When performing a fast dragging gesture and lifting the finger right during the movement (without stopping),
TouchEndedis omitted.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 31 (31 by maintainers)
Actually I don’t think this would be a good idea for my use case, since I also have other objects on the map control (like widgets, pins, callouts, etc) that need to intercept tap events (which requires Mapsui’s hit detection). The custom handling of touch events on the map should only kick in, if no other object has been tapped. (In fact this doesn’t always seem to work, in particular on Android. I will possibly open another issue for that.)
With the standard Xamarin/Maui touch events I won’t be able to do proper hit detection with objects on the map, I guess, because they occur before all the Mapsui event handling, right?
Perhaps I could answer this.
If you want to have a MAUI or Forms version, that runs on all platforms, you should use the touch handling that SkiaSharp offers with their MAUI or Forms implementation. This is only a subset of the capabilities of the used platform (see for example the Android implementation). If you want improve this, you should change it in SkiaSharp and not in Mapsui for Forms or MAUI.
What could be moved to shared code is the handling of this events, e.g. what happens if you touch or fling and how it is handled.
The most important part of MapView is, that the coordinates look like the users expect them. So the right way is to implement correct handling of projections to convert coordinates on the fly between Features in the layer and Mapsui. If they have a layer which converts all the coordinates of their various Features from lat/lon to Mapsui format (which they don’t know), then they don’t need MapView anymore, and you could get ride off.
Regarding the MyLocationLayer: This shouldn’t be very complicated to transfer it from MapView to MapControl. The most complicated part is the coordinate transformation.