Changed class Location to readonly struct

This commit is contained in:
ClemensFischer 2026-02-01 22:56:50 +01:00
parent d7d7bba5f2
commit 6566167ff0
27 changed files with 194 additions and 307 deletions

View file

@ -23,11 +23,11 @@ namespace MapControl
new QuadraticEase { EasingMode = EasingMode.EaseOut });
public static readonly DependencyProperty CenterProperty =
DependencyPropertyHelper.Register<MapBase, Location>(nameof(Center), new Location(),
DependencyPropertyHelper.Register<MapBase, Location>(nameof(Center), new Location(0d, 0d),
(map, oldValue, newValue) => map.CenterPropertyChanged(newValue));
public static readonly DependencyProperty TargetCenterProperty =
DependencyPropertyHelper.Register<MapBase, Location>(nameof(TargetCenter), new Location(),
DependencyPropertyHelper.Register<MapBase, Location>(nameof(TargetCenter), new Location(0d, 0d),
(map, oldValue, newValue) => map.TargetCenterPropertyChanged(newValue));
public static readonly DependencyProperty MinZoomLevelProperty =

View file

@ -1,52 +1,21 @@
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
#endif
namespace MapControl
{
/// <summary>
/// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
/// </summary>
public partial class MapContentControl : ContentControl
public partial class MapContentControl
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.Register<MapContentControl, bool>(nameof(AutoCollapse), false,
(control, oldValue, newValue) => MapPanel.SetAutoCollapse(control, newValue));
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.Register<MapContentControl, Location>(nameof(Location), null,
(control, oldValue, newValue) => MapPanel.SetLocation(control, newValue));
public MapContentControl()
{
DefaultStyleKey = typeof(MapContentControl);
MapPanel.InitMapElement(this);
}
/// <summary>
/// Gets/sets MapPanel.AutoCollapse.
/// </summary>
public bool AutoCollapse
{
get => (bool)GetValue(AutoCollapseProperty);
set => SetValue(AutoCollapseProperty, value);
}
/// <summary>
/// Gets/sets MapPanel.Location.
/// </summary>
public Location Location
{
get => (Location)GetValue(LocationProperty);
set => SetValue(LocationProperty, value);
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
@ -76,10 +45,7 @@ namespace MapControl
}
}
/// <summary>
/// MapContentControl with a Pushpin Style.
/// </summary>
public class Pushpin : MapContentControl
public partial class Pushpin : MapContentControl
{
public Pushpin()
{

View file

@ -16,18 +16,6 @@ namespace MapControl
{
public partial class MapItem
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.Register<MapItem, bool>(nameof(AutoCollapse), false,
(item, oldValue, newValue) => MapPanel.SetAutoCollapse(item, newValue));
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.Register<MapItem, Location>(nameof(Location), null,
(item, oldValue, newValue) =>
{
MapPanel.SetLocation(item, newValue);
item.UpdateMapTransform();
});
private Windows.Foundation.Point? pointerPressedPosition;
public MapItem()

View file

@ -14,7 +14,7 @@ namespace MapControl
DependencyPropertyHelper.RegisterAttached<bool>("AutoCollapse", typeof(MapPanel));
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<Location>("Location", typeof(MapPanel), null,
DependencyPropertyHelper.RegisterAttached<Location?>("Location", typeof(MapPanel), null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public static readonly DependencyProperty BoundingBoxProperty =

View file

@ -18,7 +18,7 @@ namespace MapControl
if (ParentMap != null && locations != null)
{
var longitudeOffset = GetLongitudeOffset(Location ?? locations.FirstOrDefault());
var longitudeOffset = GetLongitudeOffset(locations);
AddPolylinePoints(figures, locations, longitudeOffset, closed);
}
@ -31,7 +31,7 @@ namespace MapControl
if (ParentMap != null && polygons != null)
{
var longitudeOffset = GetLongitudeOffset(Location);
var longitudeOffset = GetLongitudeOffset(polygons.FirstOrDefault());
foreach (var locations in polygons)
{

View file

@ -5,28 +5,12 @@ namespace MapControl
/// <summary>
/// Replaces Windows.Foundation.Rect for double floating point precision.
/// </summary>
public readonly struct Rect : IEquatable<Rect>
public readonly struct Rect(double x, double y, double width, double height) : IEquatable<Rect>
{
public Rect(double x, double y, double width, double height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public Rect(Point p1, Point p2)
{
X = Math.Min(p1.X, p2.X);
Y = Math.Min(p1.Y, p2.Y);
Width = Math.Max(p1.X, p2.X) - X;
Height = Math.Max(p1.Y, p2.Y) - Y;
}
public double X { get; }
public double Y { get; }
public double Width { get; }
public double Height { get; }
public double X => x;
public double Y => y;
public double Width => width;
public double Height => height;
public static implicit operator Windows.Foundation.Rect(Rect r) => new(r.X, r.Y, r.Width, r.Height);