DoubleClick to zoom in/out

Topics: Windows Forms, WPF
Mar 11, 2010 at 1:52 PM

I added a function to GMapControl.cs to mimic the behaviour of maps.google.com:

 

 #if !PocketPC
     protected override void OnMouseDoubleClick(MouseEventArgs e)
      {
          Core.IsDragging = false;
          if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
          {
              Zoom--;
          }
          else
          {
              Zoom++;
          }
         base.OnMouseDoubleClick(e);
      }
#endif

 

 #if !PocketPC
     protected override void OnMouseDoubleClick(MouseEventArgs e)
      {
          Core.IsDragging = false;
          if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
          {
              Zoom--;
          }
          else
          {
              Zoom++;
          }
         base.OnMouseDoubleClick(e);
      }
#endif

Could someone put this in the source code?

Also, I made a small change to MinZoom and MaxZoom, so they appear in the designer, like so:

 

      private int maxZoom = 2;
      [Category("GMap.NET")]
      public int MaxZoom { get { return maxZoom; } set { maxZoom = value; } }

 

 

 

 

Coordinator
Mar 11, 2010 at 2:55 PM

MinZoom/MaxZoom fixed. ..But i doubt about zooming on double click, maybe someone wants use double click for other purposes(adding marker, etc...), anyway you can easily override OnMouseDoubleClick and zoom if you want

Feb 21, 2011 at 6:23 AM

Hi, radioman. I agree with your point that the double click event shouldn't be restricted to specific funtionality. However, perhaps consider including the following:

protected override void OnMouseDoubleClick(MouseEventArgs e)
{
     Core.EndDrag();
     base.OnMouseDoubleClick(e);
}

I think the double click event happens before the MouseUp event, so IsDragging is still true within the mouse double click handler. This prevents many map manipulations (such as zooming) from being performed within this event handler.

Hope this helps.

 

Coordinator
Feb 21, 2011 at 12:13 PM

actually in double click event there are 3 events:

OnMouseUp
OnMouseDoubleClick
OnMouseUp

So isDragging = false in OnMouseDoubleClick

Feb 21, 2011 at 1:04 PM

This problem comes up when DragButton = MouseButtons.Left.

When DragButton = MouseButtons.Right - both GMapControl IsDragging and Core.IsDragging are false in the OnMouseDoubleClick handler.

When DragButton = MouseButtons.Left - GMapControl IsDragging is false (as expected) but Core.IsDragging is true. This disables any zoom functionality within the MouseDoubleClick handler.

That's why I found the easiest workaround was to add the Core.EndDrag to the GMapControl MouseDoubleClick event. Do you have a better way to do this (when DragButton is Left)?

Feb 22, 2011 at 3:45 PM
Edited Feb 22, 2011 at 3:46 PM

I've encountered this issue as well, and have been unable to implement doubleclick zooming when DragButton is set to MouseButtons.Left.  Further to this, I have been unable to implement a two-click select+zoom pattern intended to work like this:

1) User activates "Zoom to Selection" mode. 

2) First click on map  -- sets origin of selected region.

3) Move cursor -- cursor indicates second point of selected region.  User moves cursor until they are happy with the selection.

4) Second click -- end selection. Zoom and center the selected region.  Clear selection.  Disable "Zoom to Selection" mode.

So during the second click event in step 4, IsDragging = true, and the zoom and center does not work.

 

I think a full-proof solution exists that would make the Click and DoubleClick events completely usable for whatever purposes in all scenarios.  The idea is to set IsDragging=True after the user has initiated a drag by actually moving the mouse.  During the MouseDown event, the location of the click can be captured.  Then during the MouseMove event, we could determine whether the user has actually moved the cursor beyond the System.Windows.Forms.SystemInformation.DragSize (http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.dragsize.aspx).  Once the user has moved beyond the DragSize, set IsDragging=True.

What do you think?

 

 

Coordinator
Feb 22, 2011 at 4:23 PM

first you can zoom to area holding shift and dragging rectangle, and about doubleclick, need some tuning i guess...

Feb 22, 2011 at 4:59 PM

Agreed about holding shift -- there are many alternative methods available.  

However, users of our application may have no mouse or keyboard, having only touchscreen for input.  So we need to build all functionality into single and double clicks.

I have no problem creating a fork for the solution proposed above -- I just wanted your feedback and direction before doing so.  If you like the idea, I can make the fork.

Thanks again for all of your hard work.

Coordinator
Feb 22, 2011 at 5:44 PM

fork sounds nice ;}

Feb 23, 2011 at 8:33 PM

Fork complete.  Please review the changes when you get a chance.

I updated WindowsForms and WPF controls.  I did not modify GMapControlNew in WPF version -- that version of the control does not utilize the Core.BeginDrag/Core.EndDrag paradigm -- I thought it would be best to leave that implementation up to you :-)

Thanks again,

Matt

Coordinator
Feb 28, 2011 at 5:19 PM

perfect, finally we have DoubleClick support ;} thx mattgerg

May 26, 2011 at 7:44 AM

Hello

I am also interested in the doubleclick for zooming in on the map. Great work :-)
But unfortunately I couldn't find the fork you guys are referring to above... Could you please post the link here?

Thanks.

Coordinator
May 26, 2011 at 8:03 AM

...as i remember it was fixed, doesn't it work?

May 27, 2011 at 7:56 AM

did you merge the fork with the main release? because i couldn't find the fork mattgerg was talking above.
we need to zoom with the doubleclick with the wpf version... any suggestion how this can be achieved without changing the library code?

May 27, 2011 at 12:07 PM

freesurfer,

The doubleclick zoom does not work out of the box.  You have to implement it yourself by overriding the OnDoubleClick method in an inherited control, or handling the DoubleClick event otherwise.  Something like....

void OnDoubleClick(MouseEventArgs e) {
    if (e.Button == MouseButtons.Left) {
        ZoomIn();
    } else {
        ZoomOut();
    }
}

Coordinator
May 27, 2011 at 5:04 PM

so whats the problem ;/

May 27, 2011 at 5:34 PM

I dunno?  :-)

May 27, 2011 at 9:14 PM

the time is the problem ;-) we don't have much time left before we have to hand in our thesis. the software is part of that and we need more time for testing and documenting. we realized kind of late that zooming with a double click would be nice... changing the code now for that takes too much time, unfortunately.
but thanks for your interest and your support :-)

Coordinator
May 28, 2011 at 1:52 AM

10s is to much ;/ really

Jun 3, 2011 at 3:21 PM
Edited Jun 3, 2011 at 3:28 PM

i tried to inherit from GMap.NET.WindowsPresentation.GMapControl but i can't get it to work... :( when i want to instantiate that control in my xaml code i get an error in the code behind that the map does not exist in the current context...

here my code

new class

namespace WVSH.Ui.Controls
{
    class GMapControl123 : GMap.NET.WindowsPresentation.GMapControl
    {
        public void OnDoubleClick(MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                base.Zoom++;
            }
            else
            {
                base.Zoom--;
            }
        }

    }
}

 

xaml from mainwindow

xmlns:controls="clr-namespace:WVSH.Ui.Controls"
[...]
<controls:GMapControl123 Name="map" ItemsSource="{Binding Markers}" MapType="GoogleMap" MouseWheelZoomType="MousePositionWithoutCenter" OnMapDrag="map_OnMapDrag" />

 

code behind from mainwindow where i get the "map does not exist in the current context" error message

            // initalize map
            map.Manager.Mode = AccessMode.ServerAndCache;
            map.CacheLocation = System.IO.Directory.GetCurrentDirectory() + "\\";
            map.ShowCenter = false;
            map.IgnoreMarkerOnMouseWheel = true;
            map.DragButton = MouseButton.Left;


//Error    1    The name 'map' does not exist in the current context    D:\WVSH\WVSH.Ui\MainWindow.xaml.cs    84    13    WVSH.Ui

 

before when i used the original GMapControl all of this code did work just fine... maybe you guys can help me. as radioman said, the adjustment should just take 10s.... ;/

thanks for your support

Coordinator
Jun 3, 2011 at 4:53 PM

tried public override void OnDoubleClick?

Jun 3, 2011 at 5:23 PM

Also, you will probably want to use:

class GMapControl123 : GMap.NET.WindowsPresentation.GMapControl
    {
        public void OnDoubleClick(MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                base.Zoom++;
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                base.Zoom--;
            }
        }

    }
This way, for 3+ button mice, you don't zoom out for every button other than Left :-)

Jun 4, 2011 at 6:35 PM
Edited Jun 4, 2011 at 6:36 PM

override doesn't work:

 

Error	1	'WVSH.Ui.Controls.GMapControl123.OnDoubleClick(System.Windows.Input.MouseEventArgs)': no suitable method found to override	

 

thanks mattgerg for the additional code ;-)
i still have the problem that after the xaml code i get an error in the code behind for the variable "map"... (see my post above)
what am i missing?

Coordinator
Jun 4, 2011 at 6:44 PM

;/