diff --git a/MapControl/Avalonia/Map.Avalonia.cs b/MapControl/Avalonia/Map.Avalonia.cs
index 4d0f1624..e47c2e79 100644
--- a/MapControl/Avalonia/Map.Avalonia.cs
+++ b/MapControl/Avalonia/Map.Avalonia.cs
@@ -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);
diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs
index bcbd8052..5be145c5 100644
--- a/MapControl/Shared/MapBase.cs
+++ b/MapControl/Shared/MapBase.cs
@@ -277,39 +277,11 @@ namespace MapControl
viewCenter = new Point(ActualWidth / 2d, ActualHeight / 2d);
}
- ///
- /// 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.
- ///
- public void MoveMap(Point position)
- {
- if (transformCenter != null)
- {
- viewCenter = position;
- UpdateTransform();
- }
- }
-
- ///
- /// Terminates map movement by the MoveMap method.
- ///
- public void EndMoveMap()
- {
- if (transformCenter != null)
- {
- ResetTransformCenter();
- UpdateTransform();
- }
- }
-
///
/// Changes the Center property according to the specified translation in view coordinates.
///
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
///
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);
- }
}
///
diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs
index dd572a0f..5d7d418b 100644
--- a/MapControl/Shared/MapPanel.cs
+++ b/MapControl/Shared/MapPanel.cs
@@ -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;
diff --git a/MapControl/WPF/Map.WPF.cs b/MapControl/WPF/Map.WPF.cs
index 3afd7bdc..bf071579 100644
--- a/MapControl/WPF/Map.WPF.cs
+++ b/MapControl/WPF/Map.WPF.cs
@@ -19,6 +19,7 @@ namespace MapControl
public static readonly DependencyProperty ManipulationModeProperty =
DependencyPropertyHelper.Register