MapView.MouseMove Event

1104
8
06-19-2018 11:45 AM
AndyWright
Occasional Contributor

In our Runtime WPF app we have the ability to tap into MouseMove and TouchMove events on a MapView, so when our users are drawing things on the map and moving the mouse or finger around we can react accordingly.  Those events don't seem to be documented in the WPF API docs, but they are there and we are currently using them.

Those same events are not present in the Xamarin Forms MapView control so we cannot code the same functionality in our Xamarin Forms app that we have in our WPF app.  My question is, does anyone know of a slick workaround to track a user's finger (i.e. TouchMove)?  It must be possible because the FreehandLine and FreehandPolygon graphic types work that way.  

Thanks ...

0 Kudos
8 Replies
dotMorten_esri
Esri Frequent Contributor

Those events don't seem to be documented in the WPF API docs, but they are there and we are currently using them.

That's because they are part of WPF, and the MapView control merely inherits them. UIElement.MouseMove Event (System.Windows) 

> Those same events are not present in the Xamarin Forms MapView control

Right. Xamarin.Forms does this quite differently and relies on gesture recognizers, or going to the platform-specific events: Xamarin.Forms Gestures - Xamarin | Microsoft Docs 

So luckily the MapView control in Xamarin.Forms inherits the GestureRecognizer property just like the WPF version inherited the events. 

It must be possible because the FreehandLine and FreehandPolygon graphic types work that way.  

Our Xamarin.Forms control merely wraps the Android/iOS/UWP native controls, where this is all handled by the native platform's touch events. It does not rely on any Xamarin.Forms APIs to do this.

0 Kudos
AndyWright
Occasional Contributor

Thanks Morten.  So I've attempted to tap into the PanGestureRecognizer and attach that to the MapView both in the code behind and in XAML.  It's not firing the PanUpdated event no matter what I do.  I am testing on an Android device and I did see another post where someone was saying the map view events were getting swallowed on his Android.  No responses on that one though.  Based on what you said about how you are wrapping native functionality in your map control am I going to have to do the same thing here and go directly after the Android stuff or am I doing something fundamentally wrong?

<esriUI:MapView x:Name="efMapView" Map="{Binding Map}" Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="4" WrapAroundMode="EnabledWhenSupported">
<esriUI:MapView.GestureRecognizers>
<PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated" TouchPoints="1" />
</esriUI:MapView.GestureRecognizers>
</esriUI:MapView>

PanGestureRecognizer panGesture = new PanGestureRecognizer();
panGesture.TouchPoints = 1;
panGesture.PanUpdated += PanGesture_PanUpdated;
ApplicationManager.MainMapView.GestureRecognizers.Add(panGesture);

0 Kudos
dotMorten_esri
Esri Frequent Contributor

To be honest, I'm not completely sure. I haven't personally worked much with the Xamarin.Forms events directly (since we've only been using the native events).

But perhaps it's best to take a step back and try and understand why you need to do this in the first place. Maybe there's a better / more direct approach to accomplish what you want to do, without even having to deal with these events directly (and/or perhaps there's a scenario we overlooked that we should make easier). What's the user experience you're trying to build?

0 Kudos
AndyWright
Occasional Contributor

In our WPF app when the user digitizes a line they can see the next line segment as they move their mouse or finger around the screen.  That's custom code by us inside the MouseMove or TouchMove events that draws the polyline from the previous vertex to wherever the user's mouse or finger is on the map as they move it.  Works like a charm and our users love it.  So now they start to use our Xamarin Forms version and that functionality isn't there.  They have to click each vertex before the line starts to appear.  Like all good users they won't stand for that sort of inconsistency.  So that's the kind of experience we are after.

Any ideas on a potential workaround?

0 Kudos
dotMorten_esri
Esri Frequent Contributor

Thanks. We are looking at adding that functionality for mouse-move but I'm curious how you'd expect that to work with touch, where dragging your finger across the map will pan it, and vertices are digitized using taps.

0 Kudos
AndyWright
Occasional Contributor

Great question.  I asked the same to one of our users, but since they get that behavior in WPF with their finger they feel they should have it in iOS and Android as well.  I assume we would need to disable the pan map interaction during this line digitizing process and then reenable it when the line is completed.  I was actually surprised it worked that way with a finger in WPF. 

So if you come out and say that we flat out can't do it with the current Runtime API, and it sounds like you are, I will at least be able to go back to them with a definitive answer and keep the jackals at bay for a while longer.

0 Kudos
dotMorten_esri
Esri Frequent Contributor

I was actually surprised it worked that way with a finger in WPF. 

So am I. It shouldn't

So if you come out and say that we flat out can't do it with the current Runtime API

There's probably some tricky way it can be accomplished, but Xamarin.Forms sure doesn't make it easy. I personally wouldn't recommend disabling pan, because that forces the user to be zoomed rather far out when digitizing to see the entire area, and that reduces accuracy significantly.

0 Kudos
AndyWright
Occasional Contributor

Agreed, so it quickly becomes a awkward user experience.  I'm going to go back to them and tell them it can't be done right now.  Thanks for all your insight here Morten ...

0 Kudos