2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 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;
|
|
|
|
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
2022-11-02 19:49:18 +01:00
|
|
|
|
private static readonly DependencyPropertyKey ViewScalePropertyKey = DependencyProperty.RegisterReadOnly(
|
|
|
|
|
|
nameof(ViewScale), typeof(double), typeof(MapBase), new PropertyMetadata(0d));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ViewScaleProperty = ViewScalePropertyKey.DependencyProperty;
|
|
|
|
|
|
|
2018-03-11 21:03:44 +01:00
|
|
|
|
private static readonly DependencyProperty CenterPointProperty = DependencyProperty.Register(
|
2021-06-14 21:41:37 +02:00
|
|
|
|
"CenterPoint", typeof(Point), typeof(MapBase), new PropertyMetadata(new Point(),
|
|
|
|
|
|
(o, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var center = (Point)e.NewValue;
|
|
|
|
|
|
((MapBase)o).CenterPointPropertyChanged(new Location(center.Y, center.X));
|
|
|
|
|
|
}));
|
2018-03-11 21:03:44 +01:00
|
|
|
|
|
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));
|
2021-01-17 21:39:42 +01:00
|
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(typeof(MapBase)));
|
2012-11-22 21:42:29 +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();
|
|
|
|
|
|
}
|
2022-11-02 19:49:18 +01:00
|
|
|
|
|
|
|
|
|
|
private void SetViewScale(double scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetValue(ViewScalePropertyKey, scale);
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|