// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control // © 2021 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) using System; #if WINUI using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Input; #else using Windows.UI.Xaml; using Windows.UI.Xaml.Input; #endif namespace MapControl { /// /// MapBase with default input event handling. /// 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 | ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia; ManipulationDelta += OnManipulationDelta; PointerWheelChanged += OnPointerWheelChanged; } /// /// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event. /// The default value is 1. /// public double MouseWheelZoomDelta { get { return (double)GetValue(MouseWheelZoomDeltaProperty); } 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); var zoomLevel = TargetZoomLevel + MouseWheelZoomDelta * Math.Sign(point.Properties.MouseWheelDelta); ZoomMap(point.Position, MouseWheelZoomDelta * Math.Round(zoomLevel / MouseWheelZoomDelta)); } } }