Select to view content in your preferred language

Map Touch Tap To Mouse Click?

9652
21
01-12-2011 09:33 AM
RyanCoodey
Frequent Contributor
I am new to working with touch screens but we have a few and the touch gesters work great such as pan and zoom.  We have a toolbar with a few tools such as an identify tool and a measure tool, etc... these are listening for the mouse click event on the map... 

What is the best way to handle both touch taps and mouse clicks?

1) For each tool we created do I need to handle both the MouseClick and the TouchUp events?
2) This wont work for the measure action though because that is an action (which has the clicking embedded), so how do we use the measure action with touch?

Thanks a lot for any info!

*EDIT*
So in I tried this in one of my tools:
        map.MapGesture += Identify_MapGesture;
        ...

        protected void Identify_MapGesture(Object sender, ESRI.ArcGIS.Client.Map.MapGestureEventArgs e)
        {
            if(e.Gesture == GestureType.Tap)
            {
                ESRI.ArcGIS.Client.Map.MouseEventArgs mouseEventArgs = new ESRI.ArcGIS.Client.Map.MouseEventArgs();
                mouseEventArgs.MapPoint = e.MapPoint; 
              Identify_MouseClick(sender, mouseEventArgs);
            }
        }

And it works pretty good...
0 Kudos
21 Replies
JenniferNery
Esri Regular Contributor
Are you saying that when you tap on the map, MouseClick does not fire?

Touch promotes mouse events as discussed here http://msdn.microsoft.com/en-us/library/dd894494(v=vs.95).aspx (see "Promotion to Mouse Events" section)

You can subscribe to both touch and mouse events but there is a risk of "Dualism". I don't think there is a need to raise MouseClick() inside MapGesture eventhandler.
0 Kudos
RyanCoodey
Frequent Contributor
Jennifer, thanks a lot for the reply.  I prefer not to have to subscribe to touch events if I can...

Yeah, no mouse click is fired when touching/tapping the map... I can touch to perform a click on buttons and such, but not the map.  So it seems that the "promotion to mouse events" is working for the WPF components, just not the map.  This is a WPF application by the way, not Silverlight.

Maybe I am missing a setting or flag somewhere?

*EDIT* I just checked the "Pen and Touch" settings again on the Windows 7 touch screen computer.  Under the "Pen" tab there is an entry that maps a single-touch to single-click, but on the "Touch" tab there is no entry for single-touch and no way to add it.  But single-touch seems to work as a single-click in Windows itself... so is this a fixed mapping of the single-touch that is always set?
0 Kudos
JenniferNery
Esri Regular Contributor
Oh I see why that is happening now. MouseClick is an event from our API, which we only raise when triggered by mouse.

Can you use MouseLeftButtonDown or MouseLeftButtonUp instead of MouseClick?

Alternatively, you can refactor the code you have inside MouseClick eventhandler to a method that you can call inside MapGesture eventhandler. Similar to what you have but I imagine that refactored code will only need MapPoint as parameter.
0 Kudos
RyanCoodey
Frequent Contributor
Awesome, thanks Jennifer... I can change from MouseClick to MouseLeftButtonUp, that is no problem. Thanks for that info...

What about the measure action though?  Any ideas why it is not detecting a click?  I am programatically invoking the measure action, would that cause any issues?

Thanks a ton!

*EDIT*  I take that back, I can't use MouseLeftButtonUp because I need the MapPoint, darn...
0 Kudos
JenniferNery
Esri Regular Contributor
I just tried this sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#UtilityActions on a touch-enabled device and it works fine for me. I'm able to draw the polyline by tapping the map to mark my vertices. Are you seeing something different when you use this sample?
0 Kudos
RyanCoodey
Frequent Contributor
That example does work for me... hmmmm, so why is mine different.

I have my own derived measure action so I can invoke it programatically:
    public class ExecutableMeasureAction : MeasureAction
    {
        public void Execute()
        {
            Invoke(null);
        }
    }


Then I setup the measure action property with this:
        protected void InitializeMeasureAction()
        {
            if (Maps.Count > 0)
            {
                if (MeasureAction != null)
                    MeasureAction.Detach();

                //Initialize
                MeasureAction = new ExecutableMeasureAction();
                MeasureAction.AreaUnit = ESRI.ArcGIS.Client.Actions.AreaUnit.Acres;
                MeasureAction.DisplayTotals = true;
                MeasureAction.DistanceUnit = ESRI.ArcGIS.Client.Actions.DistanceUnit.Feet;
                MeasureAction.MapUnits = MapUnit; //Dependency Property
                MeasureAction.MeasureMode = ESRI.ArcGIS.Client.Actions.MeasureAction.Mode.Polyline;
                MeasureAction.FillSymbol = MeasureSymbol; //Dependency Property
                MeasureAction.Attach(Maps[0]);
            }
        }


And then to invoke the measure action:
        MeasureAction.Execute();


So I am launching the action in a much different way, but still not sure why this would be different with the touch input...
0 Kudos
JenniferNery
Esri Regular Contributor
When you put breakpoints in debug-mode, does InitializeMeasureAction() and Execute() get hit? When do you invoke MeasureAction.Execute() - through button click, mouse event?
0 Kudos
RyanCoodey
Frequent Contributor
Both of these get hit... MeasureAction.Execute() gets set in a ToolbarItemClicked event handler from a class that is derived from ESRI.ArcGIS.Client.Toolkit.Toolbar.

Also, if I use the mouse on the same touch machine, the measure works, but using the finger does not.

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
It's hard to tell where the problem could be. Are you saying using touch, ToolbarItemClicked eventhandler is not hit, but using mouse it does?
0 Kudos