Removed Map.TransformDelay property

This commit is contained in:
ClemensF 2020-05-13 00:03:50 +02:00
parent 4d9f19dd5a
commit 414389513e
4 changed files with 44 additions and 109 deletions

View file

@ -1,45 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2020 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if WINDOWS_UWP
using Windows.UI.Xaml;
#else
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
/// MapBase with default input event handling.
/// </summary>
public partial class Map : MapBase
{
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
/// <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
{
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
set { SetValue(MouseWheelZoomDeltaProperty, value); }
}
private Vector translation;
private double rotation;
private double scale = 1d;
private bool transformPending;
private void ResetTransform()
{
translation.X = 0d;
translation.Y = 0d;
rotation = 0d;
scale = 1d;
transformPending = false;
}
}
}

View file

@ -2,14 +2,19 @@
// © 2020 Clemens Fischer // © 2020 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System; using Windows.UI.Xaml;
using Windows.UI.Core;
using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Input;
namespace MapControl namespace MapControl
{ {
public partial class Map /// <summary>
/// MapBase with default input event handling.
/// </summary>
public class Map : MapBase
{ {
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
public Map() public Map()
{ {
ManipulationMode = ManipulationModes.Scale ManipulationMode = ManipulationModes.Scale
@ -21,22 +26,19 @@ namespace MapControl
PointerWheelChanged += OnPointerWheelChanged; PointerWheelChanged += OnPointerWheelChanged;
} }
private async void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) /// <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
{ {
translation.X += e.Delta.Translation.X; get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
translation.Y += e.Delta.Translation.Y; set { SetValue(MouseWheelZoomDeltaProperty, value); }
rotation += e.Delta.Rotation; }
scale *= e.Delta.Scale;
if (!transformPending) private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{ {
transformPending = true; TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
await Dispatcher.RunAsync(CoreDispatcherPriority.Low,
() => TransformMap(e.Position, translation, rotation, scale));
ResetTransform();
}
} }
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)

View file

@ -86,9 +86,6 @@
<Compile Include="..\Shared\LocationEx.cs"> <Compile Include="..\Shared\LocationEx.cs">
<Link>LocationEx.cs</Link> <Link>LocationEx.cs</Link>
</Compile> </Compile>
<Compile Include="..\Shared\Map.cs">
<Link>Map.cs</Link>
</Compile>
<Compile Include="..\Shared\MapBase.cs"> <Compile Include="..\Shared\MapBase.cs">
<Link>MapBase.cs</Link> <Link>MapBase.cs</Link>
</Compile> </Compile>

View file

@ -2,22 +2,22 @@
// © 2020 Clemens Fischer // © 2020 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading;
namespace MapControl namespace MapControl
{ {
public partial class Map /// <summary>
/// MapBase with default input event handling.
/// </summary>
public class Map : MapBase
{ {
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
public static readonly DependencyProperty ManipulationModeProperty = DependencyProperty.Register( public static readonly DependencyProperty ManipulationModeProperty = DependencyProperty.Register(
nameof(ManipulationMode), typeof(ManipulationModes), typeof(Map), new PropertyMetadata(ManipulationModes.All)); nameof(ManipulationMode), typeof(ManipulationModes), typeof(Map), new PropertyMetadata(ManipulationModes.All));
public static readonly DependencyProperty TransformDelayProperty = DependencyProperty.Register(
nameof(TransformDelay), typeof(TimeSpan), typeof(Map), new PropertyMetadata(TimeSpan.FromMilliseconds(50)));
private Point? mousePosition; private Point? mousePosition;
static Map() static Map()
@ -35,6 +35,16 @@ namespace MapControl
MouseWheel += OnMouseWheel; MouseWheel += OnMouseWheel;
} }
/// <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
{
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
set { SetValue(MouseWheelZoomDeltaProperty, value); }
}
/// <summary> /// <summary>
/// Gets or sets a value that specifies how the map control handles manipulations. /// Gets or sets a value that specifies how the map control handles manipulations.
/// </summary> /// </summary>
@ -44,46 +54,17 @@ namespace MapControl
set { SetValue(ManipulationModeProperty, value); } set { SetValue(ManipulationModeProperty, value); }
} }
/// <summary>
/// Gets or sets a delay interval between adjacent calls to TranslateMap or TransformMap during mouse pan and manipulation.
/// The default value is 50 milliseconds.
/// </summary>
public TimeSpan TransformDelay
{
get { return (TimeSpan)GetValue(TransformDelayProperty); }
set { SetValue(TransformDelayProperty, value); }
}
private async Task InvokeTransformAsync(Action action)
{
if (!transformPending)
{
transformPending = true;
if (TransformDelay > TimeSpan.Zero)
{
await Task.Delay(TransformDelay);
}
await Dispatcher.InvokeAsync(action);
ResetTransform();
}
}
private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e) private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
{ {
Manipulation.SetManipulationMode(this, ManipulationMode); Manipulation.SetManipulationMode(this, ManipulationMode);
} }
private async void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e) private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{ {
translation.X += e.DeltaManipulation.Translation.X; TransformMap(e.ManipulationOrigin,
translation.Y += e.DeltaManipulation.Translation.Y; e.DeltaManipulation.Translation,
rotation += e.DeltaManipulation.Rotation; e.DeltaManipulation.Rotation,
scale *= e.DeltaManipulation.Scale.LengthSquared / 2d; e.DeltaManipulation.Scale.LengthSquared / 2d);
await InvokeTransformAsync(() => TransformMap(e.ManipulationOrigin, translation, rotation, scale));
} }
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@ -103,15 +84,15 @@ namespace MapControl
} }
} }
private async void OnMouseMove(object sender, MouseEventArgs e) private void OnMouseMove(object sender, MouseEventArgs e)
{ {
if (mousePosition.HasValue) if (mousePosition.HasValue)
{ {
var position = e.GetPosition(this); var position = e.GetPosition(this);
translation += position - mousePosition.Value; var translation = position - mousePosition.Value;
mousePosition = position; mousePosition = position;
await InvokeTransformAsync(() => TranslateMap(translation)); TranslateMap(translation);
} }
} }