mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
|
// Copyright © Clemens Fischer 2012-2013
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace MapControl
|
|
{
|
|
/// <summary>
|
|
/// Default input event handling.
|
|
/// </summary>
|
|
public class Map : MapBase
|
|
{
|
|
public static readonly DependencyProperty MouseWheelZoomChangeProperty = DependencyProperty.Register(
|
|
"MouseWheelZoomChange", typeof(double), typeof(Map), new PropertyMetadata(1d));
|
|
|
|
private Point? mousePosition;
|
|
|
|
public Map()
|
|
{
|
|
MouseWheel += OnMouseWheel;
|
|
MouseLeftButtonDown += OnMouseLeftButtonDown;
|
|
MouseLeftButtonUp += OnMouseLeftButtonUp;
|
|
MouseMove += OnMouseMove;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
|
|
/// </summary>
|
|
public double MouseWheelZoomChange
|
|
{
|
|
get { return (double)GetValue(MouseWheelZoomChangeProperty); }
|
|
set { SetValue(MouseWheelZoomChangeProperty, value); }
|
|
}
|
|
|
|
private void OnMouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
var zoomChange = MouseWheelZoomChange * (double)e.Delta / 120d;
|
|
ZoomMap(e.GetPosition(this), TargetZoomLevel + zoomChange);
|
|
}
|
|
|
|
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (CaptureMouse())
|
|
{
|
|
mousePosition = e.GetPosition(this);
|
|
}
|
|
}
|
|
|
|
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (mousePosition.HasValue)
|
|
{
|
|
mousePosition = null;
|
|
ReleaseMouseCapture();
|
|
}
|
|
}
|
|
|
|
private void OnMouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (mousePosition.HasValue)
|
|
{
|
|
var position = e.GetPosition(this);
|
|
TranslateMap(new Point(position.X - mousePosition.Value.X, position.Y - mousePosition.Value.Y));
|
|
mousePosition = position;
|
|
}
|
|
}
|
|
}
|
|
}
|