mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Removed MoveMap feature
This commit is contained in:
parent
4c669f4df0
commit
4b2771d27d
|
|
@ -70,33 +70,55 @@ namespace MapControl
|
|||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
|
||||
if (point.Pointer.Type == PointerType.Mouse && HandleMousePressed(point) ||
|
||||
point.Pointer.Type == PointerType.Touch && HandleTouchPressed(point))
|
||||
if (pointer1 == null && point.Pointer.Type == PointerType.Mouse && point.Properties.IsLeftButtonPressed ||
|
||||
pointer2 == null && point.Pointer.Type == PointerType.Touch && ManipulationModes != ManipulationModes.None)
|
||||
{
|
||||
point.Pointer.Capture(this);
|
||||
SetTransformCenter(point.Position);
|
||||
|
||||
if (pointer1 == null)
|
||||
{
|
||||
pointer1 = point.Pointer;
|
||||
position1 = point.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointer2 = point.Pointer;
|
||||
position2 = point.Position;
|
||||
}
|
||||
}
|
||||
|
||||
base.OnPointerPressed(e);
|
||||
}
|
||||
|
||||
private void HandlePointerReleased(IPointer pointer, bool releaseCapture)
|
||||
{
|
||||
if (pointer == pointer1 || pointer == pointer2)
|
||||
{
|
||||
if (pointer == pointer1)
|
||||
{
|
||||
pointer1 = pointer2;
|
||||
position1 = position2;
|
||||
}
|
||||
|
||||
pointer2 = null;
|
||||
|
||||
if (releaseCapture)
|
||||
{
|
||||
pointer.Capture(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
{
|
||||
if (HandlePointerReleased(e.Pointer))
|
||||
{
|
||||
EndMoveMap();
|
||||
e.Pointer.Capture(null);
|
||||
}
|
||||
HandlePointerReleased(e.Pointer, true);
|
||||
|
||||
base.OnPointerReleased(e);
|
||||
}
|
||||
|
||||
protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
|
||||
{
|
||||
if (HandlePointerReleased(e.Pointer))
|
||||
{
|
||||
EndMoveMap();
|
||||
}
|
||||
HandlePointerReleased(e.Pointer, false);
|
||||
|
||||
base.OnPointerCaptureLost(e);
|
||||
}
|
||||
|
|
@ -113,66 +135,14 @@ namespace MapControl
|
|||
}
|
||||
else if (e.Pointer.Type == PointerType.Mouse || ManipulationModes.HasFlag(ManipulationModes.Translate))
|
||||
{
|
||||
TranslateMap(new Point(position.X - position1.X, position.Y - position1.Y));
|
||||
position1 = position;
|
||||
MoveMap(position);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnPointerMoved(e);
|
||||
}
|
||||
|
||||
private bool HandleMousePressed(PointerPoint point)
|
||||
{
|
||||
var handled = pointer1 == null && point.Properties.IsLeftButtonPressed;
|
||||
|
||||
if (handled)
|
||||
{
|
||||
pointer1 = point.Pointer;
|
||||
position1 = point.Position;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private bool HandleTouchPressed(PointerPoint point)
|
||||
{
|
||||
var handled = pointer2 == null && ManipulationModes != ManipulationModes.None;
|
||||
|
||||
if (handled)
|
||||
{
|
||||
if (pointer1 == null)
|
||||
{
|
||||
pointer1 = point.Pointer;
|
||||
position1 = point.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointer2 = point.Pointer;
|
||||
position2 = point.Position;
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private bool HandlePointerReleased(IPointer pointer)
|
||||
{
|
||||
var handled = pointer == pointer1 || pointer == pointer2;
|
||||
|
||||
if (handled)
|
||||
{
|
||||
if (pointer == pointer1)
|
||||
{
|
||||
pointer1 = pointer2;
|
||||
position1 = position2;
|
||||
}
|
||||
|
||||
pointer2 = null;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private void HandleManipulation(IPointer pointer, Point position)
|
||||
{
|
||||
var oldDistance = new Vector(position2.X - position1.X, position2.Y - position1.Y);
|
||||
|
|
|
|||
|
|
@ -277,39 +277,11 @@ namespace MapControl
|
|||
viewCenter = new Point(ActualWidth / 2d, ActualHeight / 2d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the map by the difference of the specified position in view coordinates and a temporary
|
||||
/// transform origin point that has been set before by a call to SetTransformCenter. Map movement
|
||||
/// must be terminated by a call to EndMoveMap. MoveMap provides higher accuracy than TranslateMap.
|
||||
/// </summary>
|
||||
public void MoveMap(Point position)
|
||||
{
|
||||
if (transformCenter != null)
|
||||
{
|
||||
viewCenter = position;
|
||||
UpdateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Terminates map movement by the MoveMap method.
|
||||
/// </summary>
|
||||
public void EndMoveMap()
|
||||
{
|
||||
if (transformCenter != null)
|
||||
{
|
||||
ResetTransformCenter();
|
||||
UpdateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Center property according to the specified translation in view coordinates.
|
||||
/// </summary>
|
||||
public void TranslateMap(Point translation)
|
||||
{
|
||||
EndMoveMap();
|
||||
|
||||
if (translation.X != 0d || translation.Y != 0d)
|
||||
{
|
||||
var center = ViewToLocation(new Point(viewCenter.X - translation.X, viewCenter.Y - translation.Y));
|
||||
|
|
@ -328,7 +300,11 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public void TransformMap(Point center, Point translation, double rotation, double scale)
|
||||
{
|
||||
if (rotation != 0d || scale != 1d)
|
||||
if (rotation == 0d && scale == 1d)
|
||||
{
|
||||
TranslateMap(translation);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTransformCenter(center);
|
||||
|
||||
|
|
@ -352,12 +328,6 @@ namespace MapControl
|
|||
|
||||
UpdateTransform(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// More accurate than SetTransformCenter.
|
||||
//
|
||||
TranslateMap(translation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -234,6 +234,24 @@ namespace MapControl
|
|||
{
|
||||
var center = new Point(mapRect.X + mapRect.Width / 2d, mapRect.Y + mapRect.Height / 2d);
|
||||
var position = parentMap.ViewTransform.MapToView(center);
|
||||
|
||||
if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical &&
|
||||
!parentMap.InsideViewBounds(position))
|
||||
{
|
||||
var location = parentMap.MapProjection.MapToLocation(center);
|
||||
|
||||
if (location != null)
|
||||
{
|
||||
var coercedPosition = parentMap.LocationToView(
|
||||
new Location(location.Latitude, parentMap.CoerceLongitude(location.Longitude)));
|
||||
|
||||
if (coercedPosition.HasValue)
|
||||
{
|
||||
position = coercedPosition.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var width = mapRect.Width * parentMap.ViewTransform.Scale;
|
||||
var height = mapRect.Height * parentMap.ViewTransform.Scale;
|
||||
var x = position.X - width / 2d;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace MapControl
|
|||
public static readonly DependencyProperty ManipulationModeProperty =
|
||||
DependencyPropertyHelper.Register<Map, ManipulationModes>(nameof(ManipulationMode), ManipulationModes.Translate | ManipulationModes.Scale);
|
||||
|
||||
private Point? mousePosition;
|
||||
private double mouseWheelDelta;
|
||||
|
||||
static Map()
|
||||
|
|
@ -72,21 +73,26 @@ namespace MapControl
|
|||
{
|
||||
if (Keyboard.Modifiers == ModifierKeys.None && CaptureMouse())
|
||||
{
|
||||
SetTransformCenter(e.GetPosition(this));
|
||||
mousePosition = e.GetPosition(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
EndMoveMap();
|
||||
if (mousePosition.HasValue)
|
||||
{
|
||||
mousePosition = null;
|
||||
ReleaseMouseCapture();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
if (mousePosition.HasValue)
|
||||
{
|
||||
MoveMap(e.GetPosition(this));
|
||||
var p = e.GetPosition(this);
|
||||
TranslateMap(new Point(p.X - mousePosition.Value.X, p.Y - mousePosition.Value.Y));
|
||||
mousePosition = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace MapControl
|
|||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
|
||||
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
||||
|
||||
private bool mouseMoveEnabled;
|
||||
private Point? mousePosition;
|
||||
private double mouseWheelDelta;
|
||||
|
||||
public Map()
|
||||
|
|
@ -53,9 +53,11 @@ namespace MapControl
|
|||
|
||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
if (mouseMoveEnabled || e.Delta.Rotation == 0d && e.Delta.Scale == 1d)
|
||||
if (mousePosition.HasValue)
|
||||
{
|
||||
MoveMap(e.Position);
|
||||
var p = e.Position;
|
||||
TranslateMap(new Point(p.X - mousePosition.Value.X, p.Y - mousePosition.Value.Y));
|
||||
mousePosition = p;
|
||||
}
|
||||
else if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
||||
{
|
||||
|
|
@ -67,20 +69,23 @@ namespace MapControl
|
|||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
|
||||
mouseMoveEnabled = e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
||||
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
||||
e.KeyModifiers == VirtualKeyModifiers.None &&
|
||||
point.Properties.IsLeftButtonPressed;
|
||||
|
||||
if (mouseMoveEnabled || e.Pointer.PointerDeviceType != PointerDeviceType.Mouse)
|
||||
point.Properties.IsLeftButtonPressed &&
|
||||
CapturePointer(e.Pointer))
|
||||
{
|
||||
SetTransformCenter(point.Position);
|
||||
mousePosition = point.Position;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
mouseMoveEnabled = false;
|
||||
EndMoveMap();
|
||||
if (mousePosition.HasValue &&
|
||||
e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
||||
{
|
||||
mousePosition = null;
|
||||
ReleasePointerCapture(e.Pointer);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@
|
|||
<map:Map x:Name="map"
|
||||
Center="53.5,8.2"
|
||||
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
|
||||
ManipulationMode="All"
|
||||
DoubleTapped="MapDoubleTapped"
|
||||
PointerPressed="MapPointerPressed"
|
||||
PointerReleased="MapPointerReleased"
|
||||
|
|
|
|||
Loading…
Reference in a new issue