2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// © 2019 Clemens Fischer
|
2013-05-07 18:12:25 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2015-11-28 21:09:25 +01:00
|
|
|
|
/// MapBase with default input event handling.
|
2013-05-07 18:12:25 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Map : MapBase
|
|
|
|
|
|
{
|
2013-05-08 17:05:17 +02:00
|
|
|
|
public static readonly DependencyProperty ManipulationModeProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(ManipulationMode), typeof(ManipulationModes), typeof(Map), new PropertyMetadata(ManipulationModes.All));
|
2013-05-08 17:05:17 +02:00
|
|
|
|
|
2014-06-11 23:03:13 +02:00
|
|
|
|
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
2013-05-08 17:05:17 +02:00
|
|
|
|
|
2013-05-07 18:12:25 +02:00
|
|
|
|
private Point? mousePosition;
|
|
|
|
|
|
|
2013-05-08 17:05:17 +02:00
|
|
|
|
static Map()
|
|
|
|
|
|
{
|
|
|
|
|
|
IsManipulationEnabledProperty.OverrideMetadata(typeof(Map), new FrameworkPropertyMetadata(true));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a value that specifies how the map control handles manipulations.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ManipulationModes ManipulationMode
|
2013-05-07 18:12:25 +02:00
|
|
|
|
{
|
2013-05-08 17:05:17 +02:00
|
|
|
|
get { return (ManipulationModes)GetValue(ManipulationModeProperty); }
|
|
|
|
|
|
set { SetValue(ManipulationModeProperty, value); }
|
2013-05-07 18:12:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
|
|
|
|
|
|
/// </summary>
|
2014-06-11 23:03:13 +02:00
|
|
|
|
public double MouseWheelZoomDelta
|
2013-05-08 17:05:17 +02:00
|
|
|
|
{
|
2014-06-11 23:03:13 +02:00
|
|
|
|
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
|
|
|
|
|
|
set { SetValue(MouseWheelZoomDeltaProperty, value); }
|
2013-05-08 17:05:17 +02:00
|
|
|
|
}
|
2013-05-07 18:12:25 +02:00
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseWheel(MouseWheelEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnMouseWheel(e);
|
|
|
|
|
|
|
2017-02-05 18:35:30 +01:00
|
|
|
|
var zoomDelta = MouseWheelZoomDelta * e.Delta / 120d;
|
2014-06-11 23:03:13 +02:00
|
|
|
|
ZoomMap(e.GetPosition(this), TargetZoomLevel + zoomDelta);
|
2013-05-07 18:12:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnMouseLeftButtonDown(e);
|
|
|
|
|
|
|
|
|
|
|
|
if (CaptureMouse())
|
|
|
|
|
|
{
|
|
|
|
|
|
mousePosition = e.GetPosition(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnMouseLeftButtonUp(e);
|
|
|
|
|
|
|
|
|
|
|
|
if (mousePosition.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
mousePosition = null;
|
|
|
|
|
|
ReleaseMouseCapture();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseMove(MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnMouseMove(e);
|
|
|
|
|
|
|
|
|
|
|
|
if (mousePosition.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var position = e.GetPosition(this);
|
2016-01-30 11:50:53 +01:00
|
|
|
|
TranslateMap(position - mousePosition.Value);
|
2013-05-07 18:12:25 +02:00
|
|
|
|
mousePosition = position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-08 17:05:17 +02:00
|
|
|
|
protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnManipulationStarted(e);
|
|
|
|
|
|
|
|
|
|
|
|
Manipulation.SetManipulationMode(this, ManipulationMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-07 18:12:25 +02:00
|
|
|
|
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnManipulationDelta(e);
|
|
|
|
|
|
|
|
|
|
|
|
TransformMap(e.ManipulationOrigin,
|
2016-01-30 11:50:53 +01:00
|
|
|
|
e.DeltaManipulation.Translation, e.DeltaManipulation.Rotation,
|
2013-05-07 18:12:25 +02:00
|
|
|
|
(e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y) / 2d);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|