2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2018-02-09 17:43:47 +01:00
|
|
|
|
// © 2018 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MapBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty ForegroundProperty =
|
2014-11-19 21:11:14 +01:00
|
|
|
|
Control.ForegroundProperty.AddOwner(typeof(MapBase));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2013-12-05 17:56:04 +01:00
|
|
|
|
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(Center), typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).CenterPropertyChanged((Location)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetCenterProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(TargetCenter), typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetCenterPropertyChanged((Location)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ZoomLevelProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(ZoomLevel), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).ZoomLevelPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetZoomLevelProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(TargetZoomLevel), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetZoomLevelPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty HeadingProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(Heading), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).HeadingPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty TargetHeadingProperty = DependencyProperty.Register(
|
2017-06-25 23:05:48 +02:00
|
|
|
|
nameof(TargetHeading), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata(
|
2013-12-05 17:56:04 +01:00
|
|
|
|
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
|
|
|
|
(o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue)));
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
static MapBase()
|
|
|
|
|
|
{
|
2017-06-25 23:05:48 +02:00
|
|
|
|
ClipToBoundsProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(true));
|
|
|
|
|
|
BackgroundProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Transparent));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-05 20:57:17 +02:00
|
|
|
|
public MapBase()
|
2016-02-23 20:07:30 +01:00
|
|
|
|
{
|
2017-09-05 20:57:17 +02:00
|
|
|
|
MapProjection = new WebMercatorProjection();
|
|
|
|
|
|
ScaleRotateTransform.Children.Add(ScaleTransform);
|
|
|
|
|
|
ScaleRotateTransform.Children.Add(RotateTransform);
|
2016-02-23 20:07:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-30 11:50:53 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Changes the Center property according to the specified translation in viewport coordinates.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void TranslateMap(Vector translation)
|
|
|
|
|
|
{
|
|
|
|
|
|
TranslateMap((Point)translation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Changes the Center, Heading and ZoomLevel properties according to the specified
|
|
|
|
|
|
/// viewport coordinate translation, rotation and scale delta values. Rotation and scaling
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// is performed relative to the specified center point in viewport coordinates.
|
2016-01-30 11:50:53 +01:00
|
|
|
|
/// </summary>
|
2017-06-25 23:05:48 +02:00
|
|
|
|
public void TransformMap(Point center, Vector translation, double rotation, double scale)
|
2016-01-30 11:50:53 +01:00
|
|
|
|
{
|
2017-06-25 23:05:48 +02:00
|
|
|
|
TransformMap(center, (Point)translation, rotation, scale);
|
2016-01-30 11:50:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-04 18:01:13 +02:00
|
|
|
|
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-04-04 18:01:13 +02:00
|
|
|
|
base.OnRenderSizeChanged(sizeInfo);
|
2015-08-09 20:04:44 +02:00
|
|
|
|
|
2017-06-25 23:05:48 +02:00
|
|
|
|
ResetTransformCenter();
|
2012-11-22 21:42:29 +01:00
|
|
|
|
UpdateTransform();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|