XAML-Map-Control/MapControl/Map.cs

89 lines
2.4 KiB
C#
Raw Normal View History

2012-05-04 12:52:20 +02:00
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2012-04-25 22:02:53 +02:00
using System.Windows;
using System.Windows.Input;
2012-04-25 22:02:53 +02:00
namespace MapControl
{
2012-05-04 12:52:20 +02:00
/// <summary>
/// MapBase with input event handling.
2012-05-04 12:52:20 +02:00
/// </summary>
public class Map : MapBase
2012-04-25 22:02:53 +02:00
{
private double mouseWheelZoom = 1d;
private Point? mousePosition;
2012-04-25 22:02:53 +02:00
public double MouseWheelZoom
2012-04-25 22:02:53 +02:00
{
get { return mouseWheelZoom; }
set { mouseWheelZoom = value; }
2012-04-25 22:02:53 +02:00
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
2012-04-25 22:02:53 +02:00
{
base.OnMouseWheel(e);
2012-04-25 22:02:53 +02:00
ZoomMap(e.GetPosition(this), TargetZoomLevel + mouseWheelZoom * Math.Sign(e.Delta));
2012-04-25 22:02:53 +02:00
}
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
2012-08-08 20:42:06 +02:00
{
base.OnMouseRightButtonDown(e);
2012-08-08 20:42:06 +02:00
if (e.ClickCount == 2)
2012-08-08 20:42:06 +02:00
{
ZoomMap(e.GetPosition(this), Math.Ceiling(ZoomLevel - 1.5));
2012-08-08 20:42:06 +02:00
}
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
2012-04-25 22:02:53 +02:00
{
base.OnMouseLeftButtonDown(e);
2012-04-25 22:02:53 +02:00
if (e.ClickCount == 1)
2012-04-25 22:02:53 +02:00
{
mousePosition = e.GetPosition(this);
CaptureMouse();
2012-04-25 22:02:53 +02:00
}
else if (e.ClickCount == 2)
2012-04-25 22:02:53 +02:00
{
ZoomMap(e.GetPosition(this), Math.Floor(ZoomLevel + 1.5));
2012-04-25 22:02:53 +02:00
}
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
2012-04-25 22:02:53 +02:00
{
base.OnMouseLeftButtonUp(e);
2012-04-25 22:02:53 +02:00
if (mousePosition.HasValue)
2012-04-25 22:02:53 +02:00
{
mousePosition = null;
ReleaseMouseCapture();
2012-04-25 22:02:53 +02:00
}
}
protected override void OnMouseMove(MouseEventArgs e)
2012-04-25 22:02:53 +02:00
{
base.OnMouseMove(e);
2012-04-25 22:02:53 +02:00
if (mousePosition.HasValue)
2012-04-25 22:02:53 +02:00
{
Point position = e.GetPosition(this);
TranslateMap(position - mousePosition.Value);
mousePosition = position;
2012-04-25 22:02:53 +02:00
}
}
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
2012-04-25 22:02:53 +02:00
{
base.OnManipulationDelta(e);
2012-04-25 22:02:53 +02:00
ManipulationDelta d = e.DeltaManipulation;
TransformMap(e.ManipulationOrigin, d.Translation, d.Rotation, (d.Scale.X + d.Scale.Y) / 2d);
2012-04-25 22:02:53 +02:00
}
}
}