mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Fixed panning for UWP/WinUI
This commit is contained in:
parent
2ac4985c47
commit
e2f4fc13b1
6 changed files with 128 additions and 30 deletions
|
|
@ -21,6 +21,8 @@ namespace MapControl
|
|||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
||||
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
||||
|
||||
private Point? mousePosition;
|
||||
|
||||
public Map()
|
||||
{
|
||||
ManipulationMode = ManipulationModes.Scale
|
||||
|
|
@ -28,8 +30,11 @@ namespace MapControl
|
|||
| ManipulationModes.TranslateY
|
||||
| ManipulationModes.TranslateInertia;
|
||||
|
||||
ManipulationDelta += OnManipulationDelta;
|
||||
PointerWheelChanged += OnPointerWheelChanged;
|
||||
PointerPressed += OnPointerPressed;
|
||||
PointerReleased += OnPointerReleased;
|
||||
PointerMoved += OnPointerMoved;
|
||||
ManipulationDelta += OnManipulationDelta;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -42,11 +47,6 @@ namespace MapControl
|
|||
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
|
|
@ -54,5 +54,42 @@ namespace MapControl
|
|||
|
||||
ZoomMap(point.Position, MouseWheelZoomDelta * Math.Round(zoomLevel / MouseWheelZoomDelta));
|
||||
}
|
||||
|
||||
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (CapturePointer(e.Pointer))
|
||||
{
|
||||
mousePosition = e.GetCurrentPoint(this).Position;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (mousePosition.HasValue)
|
||||
{
|
||||
mousePosition = null;
|
||||
ReleasePointerCaptures();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (mousePosition.HasValue)
|
||||
{
|
||||
Point position = e.GetCurrentPoint(this).Position;
|
||||
var translation = position - mousePosition.Value;
|
||||
mousePosition = position;
|
||||
|
||||
TranslateMap(translation);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
if (!mousePosition.HasValue)
|
||||
{
|
||||
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
MapControl/WinUI/Timer.WinUI.cs
Normal file
33
MapControl/WinUI/Timer.WinUI.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2021 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
internal static class Timer
|
||||
{
|
||||
public static DispatcherQueueTimer CreateTimer(this DependencyObject obj, TimeSpan interval)
|
||||
{
|
||||
var timer = obj.DispatcherQueue.CreateTimer();
|
||||
timer.Interval = interval;
|
||||
return timer;
|
||||
}
|
||||
|
||||
public static void Run(this DispatcherQueueTimer timer, bool restart = false)
|
||||
{
|
||||
if (restart)
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
if (!timer.IsRunning)
|
||||
{
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue