using System; #if WPF using System.Windows; #elif UWP using Windows.UI.Xaml; #elif WINUI using Microsoft.UI.Xaml; #endif namespace MapControl { /// /// MapBase with default input event handling. /// public partial class Map : MapBase { public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyPropertyHelper.Register(nameof(MouseWheelZoomDelta), 0.25); public static readonly DependencyProperty MouseWheelZoomAnimatedProperty = DependencyPropertyHelper.Register(nameof(MouseWheelZoomAnimated), true); /// /// Gets or sets the amount by which the ZoomLevel property changes by a MouseWheel event. /// The default value is 0.25. /// public double MouseWheelZoomDelta { get => (double)GetValue(MouseWheelZoomDeltaProperty); set => SetValue(MouseWheelZoomDeltaProperty, value); } /// /// Gets or sets a value that specifies whether zooming by a MouseWheel event is animated. /// The default value is true. /// public bool MouseWheelZoomAnimated { get => (bool)GetValue(MouseWheelZoomAnimatedProperty); set => SetValue(MouseWheelZoomAnimatedProperty, value); } private void OnMouseWheel(Point position, double delta) { var zoomLevel = TargetZoomLevel + MouseWheelZoomDelta * delta; var animated = false; if (delta <= -1d || delta >= 1d) { // Zoom to integer multiple of MouseWheelZoomDelta when the event was raised by a // mouse wheel or by a large movement on a touch pad or other high resolution device. // zoomLevel = MouseWheelZoomDelta * Math.Round(zoomLevel / MouseWheelZoomDelta); animated = MouseWheelZoomAnimated; } ZoomMap(position, zoomLevel, animated); } } }