This repository was archived by the owner on Mar 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMap.WinRT.cs
More file actions
88 lines (77 loc) · 3.1 KB
/
Map.WinRT.cs
File metadata and controls
88 lines (77 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © 2014 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
namespace MapControl
{
/// <summary>
/// Default input event handling.
/// </summary>
public class Map : MapBase
{
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
"MouseWheelZoomDelta", typeof(double), typeof(Map), new PropertyMetadata(1d));
private Point? mousePosition;
public Map()
{
ManipulationMode = ManipulationModes.Scale |
ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;
ManipulationDelta += OnManipulationDelta;
PointerWheelChanged += OnPointerWheelChanged;
PointerPressed += OnPointerPressed;
PointerReleased += OnPointerReleased;
PointerCanceled += OnPointerReleased;
PointerCaptureLost += OnPointerReleased;
PointerMoved += OnPointerMoved;
}
/// <summary>
/// Gets or sets the amount by which the ZoomLevel property changes during a MouseWheel event.
/// </summary>
public double MouseWheelZoomDelta
{
get { return (double)GetValue(MouseWheelZoomDeltaProperty); }
set { SetValue(MouseWheelZoomDeltaProperty, value); }
}
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);
var zoomChange = MouseWheelZoomDelta * (double)point.Properties.MouseWheelDelta / 120d;
ZoomMap(point.Position, TargetZoomLevel + zoomChange);
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
CapturePointer(e.Pointer))
{
mousePosition = e.GetCurrentPoint(this).Position;
}
}
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
mousePosition = null;
ReleasePointerCapture(e.Pointer);
}
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
if (mousePosition.HasValue)
{
var position = e.GetCurrentPoint(this).Position;
TranslateMap(new Point(position.X - mousePosition.Value.X, position.Y - mousePosition.Value.Y));
mousePosition = position;
}
}
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (e.PointerDeviceType != PointerDeviceType.Mouse)
{
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
}
}
}