2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2014-01-10 20:11:39 +01:00
|
|
|
|
// Copyright © 2014 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using Windows.Devices.Input;
|
|
|
|
|
|
using Windows.Foundation;
|
2013-05-08 17:05:17 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-05-07 18:12:25 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Default input event handling.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Map : MapBase
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-06-11 23:03:13 +02:00
|
|
|
|
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
|
|
|
|
|
"MouseWheelZoomDelta", typeof(double), typeof(Map), new PropertyMetadata(1d));
|
2013-05-08 17:05:17 +02:00
|
|
|
|
|
2012-11-26 19:17:12 +01:00
|
|
|
|
private Point? mousePosition;
|
|
|
|
|
|
|
|
|
|
|
|
public Map()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
ManipulationMode = ManipulationModes.Scale |
|
2013-10-10 00:46:47 +02:00
|
|
|
|
ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
ManipulationDelta += OnManipulationDelta;
|
|
|
|
|
|
PointerWheelChanged += OnPointerWheelChanged;
|
|
|
|
|
|
PointerPressed += OnPointerPressed;
|
|
|
|
|
|
PointerReleased += OnPointerReleased;
|
|
|
|
|
|
PointerCanceled += OnPointerReleased;
|
|
|
|
|
|
PointerCaptureLost += OnPointerReleased;
|
|
|
|
|
|
PointerMoved += OnPointerMoved;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-07 18:12:25 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
|
|
|
|
|
|
/// </summary>
|
2014-06-11 23:03:13 +02:00
|
|
|
|
public double MouseWheelZoomDelta
|
2013-05-08 17:05:17 +02:00
|
|
|
|
{
|
2014-06-11 23:03:13 +02:00
|
|
|
|
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
|
|
|
|
|
|
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
2013-05-08 17:05:17 +02:00
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetCurrentPoint(this);
|
2014-06-11 23:03:13 +02:00
|
|
|
|
var zoomChange = MouseWheelZoomDelta * (double)point.Properties.MouseWheelDelta / 120d;
|
2013-03-15 18:08:51 +01:00
|
|
|
|
ZoomMap(point.Position, TargetZoomLevel + zoomChange);
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
|
|
|
|
|
CapturePointer(e.Pointer))
|
|
|
|
|
|
{
|
|
|
|
|
|
mousePosition = e.GetCurrentPoint(this).Position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
mousePosition = null;
|
|
|
|
|
|
ReleasePointerCapture(e.Pointer);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mousePosition.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var position = e.GetCurrentPoint(this).Position;
|
|
|
|
|
|
TranslateMap(new Point(position.X - mousePosition.Value.X, position.Y - mousePosition.Value.Y));
|
|
|
|
|
|
mousePosition = position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-05-07 18:12:25 +02:00
|
|
|
|
|
|
|
|
|
|
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|