mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Removed Map.TransformDelay property
This commit is contained in:
parent
4d9f19dd5a
commit
414389513e
4 changed files with 44 additions and 109 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue