2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2020-01-09 19:40:10 +01:00
|
|
|
|
// © 2020 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2020-05-24 21:00:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Windows.UI.Core;
|
2020-05-13 00:03:50 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2020-05-13 00:03:50 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// MapBase with default input event handling.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Map : MapBase
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2020-05-13 00:03:50 +02:00
|
|
|
|
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
|
|
|
|
|
|
2020-05-24 21:00:07 +02:00
|
|
|
|
private Vector transformTranslation;
|
|
|
|
|
|
private double transformRotation;
|
|
|
|
|
|
private double transformScale = 1d;
|
|
|
|
|
|
private bool transformPending;
|
|
|
|
|
|
|
2012-11-26 19:17:12 +01:00
|
|
|
|
public Map()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2020-01-17 19:51:56 +01:00
|
|
|
|
ManipulationMode = ManipulationModes.Scale
|
|
|
|
|
|
| ManipulationModes.TranslateX
|
|
|
|
|
|
| ManipulationModes.TranslateY
|
|
|
|
|
|
| ManipulationModes.TranslateInertia;
|
2013-10-10 00:46:47 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
ManipulationDelta += OnManipulationDelta;
|
|
|
|
|
|
PointerWheelChanged += OnPointerWheelChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-13 00:03:50 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
|
|
|
|
|
|
/// The default value is 1.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double MouseWheelZoomDelta
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2020-05-13 00:03:50 +02:00
|
|
|
|
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
|
|
|
|
|
|
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
|
|
|
|
|
}
|
2016-08-08 20:36:02 +02:00
|
|
|
|
|
2020-05-24 21:00:07 +02:00
|
|
|
|
private async void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
2020-05-13 00:03:50 +02:00
|
|
|
|
{
|
2020-05-24 21:00:07 +02:00
|
|
|
|
transformTranslation.X += e.Delta.Translation.X;
|
|
|
|
|
|
transformTranslation.Y += e.Delta.Translation.Y;
|
|
|
|
|
|
transformRotation += e.Delta.Rotation;
|
|
|
|
|
|
transformScale *= e.Delta.Scale;
|
|
|
|
|
|
|
|
|
|
|
|
if (!transformPending)
|
|
|
|
|
|
{
|
|
|
|
|
|
transformPending = true;
|
|
|
|
|
|
|
|
|
|
|
|
await Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
|
|
|
|
|
() => TransformMap(e.Position, transformTranslation, transformRotation, transformScale));
|
|
|
|
|
|
|
|
|
|
|
|
transformTranslation.X = 0d;
|
|
|
|
|
|
transformTranslation.Y = 0d;
|
|
|
|
|
|
transformRotation = 0d;
|
|
|
|
|
|
transformScale = 1d;
|
|
|
|
|
|
transformPending = false;
|
|
|
|
|
|
}
|
2013-05-07 18:12:25 +02:00
|
|
|
|
}
|
2020-01-17 19:51:56 +01:00
|
|
|
|
|
|
|
|
|
|
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetCurrentPoint(this);
|
|
|
|
|
|
var zoomDelta = MouseWheelZoomDelta * point.Properties.MouseWheelDelta / 120d;
|
|
|
|
|
|
|
|
|
|
|
|
ZoomMap(point.Position, TargetZoomLevel + zoomDelta);
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|