mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Version 4.16.1. Improved manipulation and mouse pan handling
This commit is contained in:
parent
e44ca90653
commit
30ad3f6f0f
4 changed files with 127 additions and 81 deletions
|
|
@ -3,72 +3,48 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml.Input;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// MapBase with default input event handling.
|
||||
/// </summary>
|
||||
public class Map : MapBase
|
||||
public partial class Map
|
||||
{
|
||||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
||||
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
||||
|
||||
private bool transformPending;
|
||||
private Vector transformTranslation;
|
||||
private double transformRotation;
|
||||
private double transformScale = 1d;
|
||||
|
||||
public Map()
|
||||
{
|
||||
ManipulationMode = ManipulationModes.Scale |
|
||||
ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;
|
||||
ManipulationMode = ManipulationModes.Scale
|
||||
| ManipulationModes.TranslateX
|
||||
| ManipulationModes.TranslateY
|
||||
| ManipulationModes.TranslateInertia;
|
||||
|
||||
ManipulationDelta += OnManipulationDelta;
|
||||
PointerWheelChanged += OnPointerWheelChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
|
||||
/// </summary>
|
||||
public double MouseWheelZoomDelta
|
||||
private async void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
|
||||
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
||||
}
|
||||
|
||||
protected virtual void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
var zoomChange = MouseWheelZoomDelta * point.Properties.MouseWheelDelta / 120d;
|
||||
|
||||
ZoomMap(point.Position, TargetZoomLevel + zoomChange);
|
||||
}
|
||||
|
||||
protected virtual async void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
transformTranslation.X += e.Delta.Translation.X;
|
||||
transformTranslation.Y += e.Delta.Translation.Y;
|
||||
transformRotation += e.Delta.Rotation;
|
||||
transformScale *= e.Delta.Scale;
|
||||
translation.X += e.Delta.Translation.X;
|
||||
translation.Y += e.Delta.Translation.Y;
|
||||
rotation += e.Delta.Rotation;
|
||||
scale *= e.Delta.Scale;
|
||||
|
||||
if (!transformPending)
|
||||
{
|
||||
transformPending = true;
|
||||
|
||||
await Dispatcher.RunIdleAsync(a =>
|
||||
{
|
||||
TransformMap(e.Position, transformTranslation, transformRotation, transformScale);
|
||||
await Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
||||
() => TransformMap(e.Position, translation, rotation, scale));
|
||||
|
||||
transformPending = false;
|
||||
transformTranslation.X = 0d;
|
||||
transformTranslation.Y = 0d;
|
||||
transformRotation = 0d;
|
||||
transformScale = 1d;
|
||||
});
|
||||
ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
var zoomDelta = MouseWheelZoomDelta * point.Properties.MouseWheelDelta / 120d;
|
||||
|
||||
ZoomMap(point.Position, TargetZoomLevel + zoomDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@
|
|||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue