mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-01 06:10:02 +01:00
Removed Map.TransformDelay property
This commit is contained in:
parent
4d9f19dd5a
commit
414389513e
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,19 @@
|
|||
// © 2020 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Input;
|
||||
|
||||
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()
|
||||
{
|
||||
ManipulationMode = ManipulationModes.Scale
|
||||
|
|
@ -21,22 +26,19 @@ namespace MapControl
|
|||
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;
|
||||
translation.Y += e.Delta.Translation.Y;
|
||||
rotation += e.Delta.Rotation;
|
||||
scale *= e.Delta.Scale;
|
||||
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
|
||||
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
||||
}
|
||||
|
||||
if (!transformPending)
|
||||
{
|
||||
transformPending = true;
|
||||
|
||||
await Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
||||
() => TransformMap(e.Position, translation, rotation, scale));
|
||||
|
||||
ResetTransform();
|
||||
}
|
||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
||||
}
|
||||
|
||||
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
||||
|
|
|
|||
|
|
@ -86,9 +86,6 @@
|
|||
<Compile Include="..\Shared\LocationEx.cs">
|
||||
<Link>LocationEx.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\Map.cs">
|
||||
<Link>Map.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\MapBase.cs">
|
||||
<Link>MapBase.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
// © 2020 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
|
||||
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(
|
||||
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;
|
||||
|
||||
static Map()
|
||||
|
|
@ -35,6 +35,16 @@ namespace MapControl
|
|||
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>
|
||||
/// Gets or sets a value that specifies how the map control handles manipulations.
|
||||
/// </summary>
|
||||
|
|
@ -44,46 +54,17 @@ namespace MapControl
|
|||
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)
|
||||
{
|
||||
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;
|
||||
translation.Y += e.DeltaManipulation.Translation.Y;
|
||||
rotation += e.DeltaManipulation.Rotation;
|
||||
scale *= e.DeltaManipulation.Scale.LengthSquared / 2d;
|
||||
|
||||
await InvokeTransformAsync(() => TransformMap(e.ManipulationOrigin, translation, rotation, scale));
|
||||
TransformMap(e.ManipulationOrigin,
|
||||
e.DeltaManipulation.Translation,
|
||||
e.DeltaManipulation.Rotation,
|
||||
e.DeltaManipulation.Scale.LengthSquared / 2d);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var position = e.GetPosition(this);
|
||||
translation += position - mousePosition.Value;
|
||||
var translation = position - mousePosition.Value;
|
||||
mousePosition = position;
|
||||
|
||||
await InvokeTransformAsync(() => TranslateMap(translation));
|
||||
TranslateMap(translation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue