2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
|
|
|
|
|
// Copyright © 2012 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Map
|
|
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
private Point? mousePosition;
|
|
|
|
|
|
|
|
|
|
|
|
public Map()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
MouseWheelZoomChange = 1d;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
MouseWheel += OnMouseWheel;
|
|
|
|
|
|
MouseLeftButtonDown += OnMouseLeftButtonDown;
|
|
|
|
|
|
MouseLeftButtonUp += OnMouseLeftButtonUp;
|
|
|
|
|
|
MouseMove += OnMouseMove;
|
|
|
|
|
|
|
|
|
|
|
|
#if !SILVERLIGHT
|
2012-11-23 23:00:50 +01:00
|
|
|
|
ManipulationDelta += (o, e) => TransformMap(
|
|
|
|
|
|
e.ManipulationOrigin, (Point)e.DeltaManipulation.Translation, e.DeltaManipulation.Rotation,
|
|
|
|
|
|
(e.DeltaManipulation.Scale.X + e.DeltaManipulation.Scale.Y) / 2d); ;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#endif
|
2012-11-23 23:00:50 +01:00
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
private void OnMouseWheel(object sender, MouseWheelEventArgs e)
|
|
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
ZoomMap(e.GetPosition(this), TargetZoomLevel + MouseWheelZoomChange * Math.Sign(e.Delta));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|