mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-20 22:05:07 +00:00
Improve touch input handling
This commit is contained in:
parent
7448daa531
commit
47a96b22cc
4 changed files with 17 additions and 47 deletions
|
|
@ -149,8 +149,15 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
else if (Children.Count == 0)
|
else if (Children.Count == 0)
|
||||||
{
|
{
|
||||||
Children.Add(new Image { Opacity = 0d, Stretch = Stretch.Fill });
|
for (int i = 0; i < 2; i++)
|
||||||
Children.Add(new Image { Opacity = 0d, Stretch = Stretch.Fill });
|
{
|
||||||
|
Children.Add(new Image
|
||||||
|
{
|
||||||
|
Opacity = 0d,
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
IsHitTestVisible = false // avoid touch capture issues
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.SetParentMap(map);
|
base.SetParentMap(map);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace MapControl
|
||||||
new PropertyMetadata(TimeSpan.FromSeconds(0.2), (o, e) => ((MapTileLayerBase)o).updateTimer.Interval = (TimeSpan)e.NewValue));
|
new PropertyMetadata(TimeSpan.FromSeconds(0.2), (o, e) => ((MapTileLayerBase)o).updateTimer.Interval = (TimeSpan)e.NewValue));
|
||||||
|
|
||||||
public static readonly DependencyProperty UpdateWhileViewportChangingProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty UpdateWhileViewportChangingProperty = DependencyProperty.Register(
|
||||||
nameof(UpdateWhileViewportChanging), typeof(bool), typeof(MapTileLayerBase), new PropertyMetadata(false));
|
nameof(UpdateWhileViewportChanging), typeof(bool), typeof(MapTileLayerBase), new PropertyMetadata(true));
|
||||||
|
|
||||||
public static readonly DependencyProperty MapBackgroundProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty MapBackgroundProperty = DependencyProperty.Register(
|
||||||
nameof(MapBackground), typeof(Brush), typeof(MapTileLayerBase), new PropertyMetadata(null));
|
nameof(MapBackground), typeof(Brush), typeof(MapTileLayerBase), new PropertyMetadata(null));
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,12 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image Image { get; } = new Image { Opacity = 0d, Stretch = Stretch.Fill };
|
public Image Image { get; } = new Image
|
||||||
|
{
|
||||||
|
Opacity = 0d,
|
||||||
|
Stretch = Stretch.Fill,
|
||||||
|
IsHitTestVisible = false // avoid touch capture issues
|
||||||
|
};
|
||||||
|
|
||||||
public bool Pending { get; set; } = true;
|
public bool Pending { get; set; } = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ namespace MapControl
|
||||||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
|
||||||
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25));
|
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25));
|
||||||
|
|
||||||
private Point? mousePosition;
|
|
||||||
private double mouseWheelDelta;
|
private double mouseWheelDelta;
|
||||||
|
|
||||||
public Map()
|
public Map()
|
||||||
|
|
@ -35,9 +34,6 @@ namespace MapControl
|
||||||
| ManipulationModes.TranslateInertia;
|
| ManipulationModes.TranslateInertia;
|
||||||
|
|
||||||
ManipulationDelta += OnManipulationDelta;
|
ManipulationDelta += OnManipulationDelta;
|
||||||
PointerPressed += OnPointerPressed;
|
|
||||||
PointerReleased += OnPointerReleased;
|
|
||||||
PointerMoved += OnPointerMoved;
|
|
||||||
PointerWheelChanged += OnPointerWheelChanged;
|
PointerWheelChanged += OnPointerWheelChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,45 +49,7 @@ namespace MapControl
|
||||||
|
|
||||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!mousePosition.HasValue)
|
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
||||||
{
|
|
||||||
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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.HasValue)
|
|
||||||
{
|
|
||||||
mousePosition = null;
|
|
||||||
ReleasePointerCaptures();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
|
|
||||||
{
|
|
||||||
// Perform translation by explicit Mouse input because with Manipulation pointer capture is
|
|
||||||
// lost when Map content changes, e.g. when a MapTileLayer or WmsImageLayer loads new images.
|
|
||||||
|
|
||||||
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
|
||||||
mousePosition.HasValue)
|
|
||||||
{
|
|
||||||
Point position = e.GetCurrentPoint(this).Position;
|
|
||||||
var translation = position - mousePosition.Value;
|
|
||||||
mousePosition = position;
|
|
||||||
|
|
||||||
TranslateMap(translation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue