XAML-Map-Control/MapControl/WinUI/Map.WinUI.cs

59 lines
1.9 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2021-01-13 21:19:27 +01:00
// © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
2021-01-07 19:27:25 +01:00
using System;
2021-06-14 21:41:37 +02:00
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
#else
2020-05-13 00:03:50 +02:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
2021-06-14 21:41:37 +02:00
#endif
namespace MapControl
{
2020-05-13 00:03:50 +02:00
/// <summary>
/// MapBase with default input event handling.
/// </summary>
public class Map : MapBase
{
2020-05-13 00:03:50 +02:00
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
public Map()
{
ManipulationMode = ManipulationModes.Scale
| ManipulationModes.TranslateX
| ManipulationModes.TranslateY
| ManipulationModes.TranslateInertia;
ManipulationDelta += OnManipulationDelta;
PointerWheelChanged += OnPointerWheelChanged;
}
2020-05-13 00:03:50 +02:00
/// <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
{
2020-05-13 00:03:50 +02:00
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
set { SetValue(MouseWheelZoomDeltaProperty, value); }
}
2020-09-04 16:56:57 +02:00
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
2020-05-13 00:03:50 +02:00
{
2020-09-04 16:56:57 +02:00
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);
2021-01-07 19:27:25 +01:00
var zoomLevel = TargetZoomLevel + MouseWheelZoomDelta * Math.Sign(point.Properties.MouseWheelDelta);
2021-01-07 19:27:25 +01:00
ZoomMap(point.Position, MouseWheelZoomDelta * Math.Round(zoomLevel / MouseWheelZoomDelta));
}
}
}