// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control // © 2018 Clemens Fischer // 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 = Control.ForegroundProperty.AddOwner(typeof(MapBase)); public static readonly DependencyProperty CenterProperty = DependencyProperty.Register( nameof(Center), typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata( new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).CenterPropertyChanged((Location)e.NewValue))); public static readonly DependencyProperty TargetCenterProperty = DependencyProperty.Register( nameof(TargetCenter), typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata( new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).TargetCenterPropertyChanged((Location)e.NewValue))); public static readonly DependencyProperty ZoomLevelProperty = DependencyProperty.Register( nameof(ZoomLevel), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata( 1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).ZoomLevelPropertyChanged((double)e.NewValue))); public static readonly DependencyProperty TargetZoomLevelProperty = DependencyProperty.Register( nameof(TargetZoomLevel), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata( 1d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).TargetZoomLevelPropertyChanged((double)e.NewValue))); public static readonly DependencyProperty HeadingProperty = DependencyProperty.Register( nameof(Heading), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata( 0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).HeadingPropertyChanged((double)e.NewValue))); public static readonly DependencyProperty TargetHeadingProperty = DependencyProperty.Register( nameof(TargetHeading), typeof(double), typeof(MapBase), new FrameworkPropertyMetadata( 0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue))); static MapBase() { ClipToBoundsProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(true)); BackgroundProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.Transparent)); } public MapBase() { MapProjection = new WebMercatorProjection(); ScaleRotateTransform.Children.Add(ScaleTransform); ScaleRotateTransform.Children.Add(RotateTransform); } /// /// Changes the Center property according to the specified translation in viewport coordinates. /// public void TranslateMap(Vector translation) { TranslateMap((Point)translation); } /// /// Changes the Center, Heading and ZoomLevel properties according to the specified /// viewport coordinate translation, rotation and scale delta values. Rotation and scaling /// is performed relative to the specified center point in viewport coordinates. /// public void TransformMap(Point center, Vector translation, double rotation, double scale) { TransformMap(center, (Point)translation, rotation, scale); } protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { base.OnRenderSizeChanged(sizeInfo); ResetTransformCenter(); UpdateTransform(); } } }