Skip to content

Commit

Permalink
Added MouseWheelZoomEnabled boolean property to enable/disable mouse …
Browse files Browse the repository at this point in the history
…wheel zooming (default is true for backward compatibility)
  • Loading branch information
guillea committed Feb 6, 2014
1 parent 4d74610 commit ea29b52
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 52 deletions.
1 change: 1 addition & 0 deletions GMap.NET.Core/GMap.NET.Internals/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class Core : IDisposable
public GPoint mouseLastZoom;

public MouseWheelZoomType MouseWheelZoomType = MouseWheelZoomType.MousePositionAndCenter;
public bool MouseWheelZoomEnabled = true;

public PointLatLng? LastLocationInBounds = null;
public bool VirtualSizeEnabled = false;
Expand Down
124 changes: 72 additions & 52 deletions GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ public MouseWheelZoomType MouseWheelZoomType
}
}

/// <summary>
/// enable map zoom on mouse wheel
/// </summary>
[Category("GMap.NET")]
[Description("enable map zoom on mouse wheel")]
public bool MouseWheelZoomEnabled
{
get
{
return Core.MouseWheelZoomEnabled;
}
set
{
Core.MouseWheelZoomEnabled = value;
}
}

/// <summary>
/// text on empty tiles
/// </summary>
Expand Down Expand Up @@ -2295,65 +2312,68 @@ protected override void OnMouseLeave(EventArgs e)

protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
base.OnMouseWheel(e);

if(mouseIn && (!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging)
if (MouseWheelZoomEnabled)
{
if(Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y)
{
if(MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter)
{
Core.position = FromLocalToLatLng(e.X, e.Y);
}
else if(MouseWheelZoomType == MouseWheelZoomType.ViewCenter)
{
Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2);
}
else if(MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter)
{
Core.position = FromLocalToLatLng(e.X, e.Y);
}
if (mouseIn && (!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging)
{
if (Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y)
{
if (MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter)
{
Core.position = FromLocalToLatLng(e.X, e.Y);
}
else if (MouseWheelZoomType == MouseWheelZoomType.ViewCenter)
{
Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2);
}
else if (MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter)
{
Core.position = FromLocalToLatLng(e.X, e.Y);
}

Core.mouseLastZoom.X = e.X;
Core.mouseLastZoom.Y = e.Y;
}
Core.mouseLastZoom.X = e.X;
Core.mouseLastZoom.Y = e.Y;
}

// set mouse position to map center
if(MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter)
{
if(!GMaps.Instance.IsRunningOnMono)
{
System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2));
Stuff.SetCursorPos((int)p.X, (int)p.Y);
}
}
// set mouse position to map center
if (MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter)
{
if (!GMaps.Instance.IsRunningOnMono)
{
System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2));
Stuff.SetCursorPos((int)p.X, (int)p.Y);
}
}

Core.MouseWheelZooming = true;
Core.MouseWheelZooming = true;

if(e.Delta > 0)
{
if(!InvertedMouseWheelZooming)
{
Zoom = ((int)Zoom) + 1;
}
else
{
Zoom = ((int)(Zoom + 0.99)) - 1;
}
}
else if(e.Delta < 0)
{
if(!InvertedMouseWheelZooming)
{
Zoom = ((int)(Zoom + 0.99)) - 1;
}
else
{
Zoom = ((int)Zoom) + 1;
}
}
if (e.Delta > 0)
{
if (!InvertedMouseWheelZooming)
{
Zoom = ((int)Zoom) + 1;
}
else
{
Zoom = ((int)(Zoom + 0.99)) - 1;
}
}
else if (e.Delta < 0)
{
if (!InvertedMouseWheelZooming)
{
Zoom = ((int)(Zoom + 0.99)) - 1;
}
else
{
Zoom = ((int)Zoom) + 1;
}
}

Core.MouseWheelZooming = false;
Core.MouseWheelZooming = false;
}
}
}
#endif
Expand Down

0 comments on commit ea29b52

Please sign in to comment.