2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// © 2019 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
using System;
|
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>
|
2015-11-28 21:09:25 +01:00
|
|
|
|
/// MapBase with default input event handling.
|
2013-05-07 18:12:25 +02:00
|
|
|
|
/// </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(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
2013-05-08 17:05:17 +02:00
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
private bool transformPending;
|
2018-03-07 22:19:16 +01:00
|
|
|
|
private Vector transformTranslation;
|
2016-08-08 20:36:02 +02:00
|
|
|
|
private double transformRotation;
|
|
|
|
|
|
private double transformScale = 1d;
|
|
|
|
|
|
|
2012-11-26 19:17:12 +01:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
protected virtual void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
var point = e.GetCurrentPoint(this);
|
2016-08-08 20:36:02 +02:00
|
|
|
|
var zoomChange = MouseWheelZoomDelta * 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
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
protected virtual async void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
2013-05-07 18:12:25 +02:00
|
|
|
|
{
|
2016-08-08 20:36:02 +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.RunIdleAsync(a =>
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformMap(e.Position, transformTranslation, transformRotation, transformScale);
|
|
|
|
|
|
|
|
|
|
|
|
transformPending = false;
|
|
|
|
|
|
transformTranslation.X = 0d;
|
|
|
|
|
|
transformTranslation.Y = 0d;
|
|
|
|
|
|
transformRotation = 0d;
|
|
|
|
|
|
transformScale = 1d;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2013-05-07 18:12:25 +02:00
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|