2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
|
|
|
|
|
// Copyright © 2012 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Windows.Devices.Input;
|
|
|
|
|
|
using Windows.Foundation;
|
|
|
|
|
|
using Windows.UI.Xaml.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Map
|
|
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
private Point? mousePosition;
|
|
|
|
|
|
|
|
|
|
|
|
public Map()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
MouseWheelZoomChange = 1d;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
ManipulationMode = ManipulationModes.All;
|
|
|
|
|
|
ManipulationDelta += OnManipulationDelta;
|
|
|
|
|
|
PointerWheelChanged += OnPointerWheelChanged;
|
|
|
|
|
|
PointerPressed += OnPointerPressed;
|
|
|
|
|
|
PointerReleased += OnPointerReleased;
|
|
|
|
|
|
PointerCanceled += OnPointerReleased;
|
|
|
|
|
|
PointerCaptureLost += OnPointerReleased;
|
|
|
|
|
|
PointerMoved += OnPointerMoved;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetCurrentPoint(this);
|
2012-11-26 19:17:12 +01:00
|
|
|
|
ZoomMap(point.Position, TargetZoomLevel + MouseWheelZoomChange * Math.Sign(point.Properties.MouseWheelDelta));
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|