From a4f19a597618e7d3208affbaf9f3101aab8f011f Mon Sep 17 00:00:00 2001 From: Clemens Date: Sat, 5 Feb 2022 15:52:17 +0100 Subject: [PATCH] PushpinBorder for all platforms --- FileDbCache/UWP/FileDbCache.UWP.csproj | 2 +- MBTiles/UWP/MBTiles.UWP.csproj | 2 +- MapControl/Shared/PushpinBorder.cs | 115 ++++++++++++++++ MapControl/UWP/MapControl.UWP.csproj | 8 +- MapControl/UWP/Themes/Generic.xaml | 37 +++--- MapControl/WPF/PushpinBorder.WPF.cs | 133 ++++--------------- MapControl/WPF/Themes/Generic.xaml | 2 +- MapControl/WinUI/MapControl.WinUI.csproj | 10 ++ MapControl/WinUI/PushpinBorder.WinUI.cs | 93 +++++++++++++ MapControl/WinUI/Themes/Generic.xaml | 37 +++--- MapProjections/UWP/MapProjections.UWP.csproj | 2 +- MapUiTools/UWP/MapUiTools.UWP.csproj | 2 +- SQLiteCache/UWP/SQLiteCache.UWP.csproj | 2 +- SampleApps/UniversalApp/MainPage.xaml | 4 +- SampleApps/UniversalApp/UniversalApp.csproj | 2 +- SampleApps/WinUiApp/MainWindow.xaml | 4 +- 16 files changed, 291 insertions(+), 164 deletions(-) create mode 100644 MapControl/Shared/PushpinBorder.cs create mode 100644 MapControl/WinUI/PushpinBorder.WinUI.cs diff --git a/FileDbCache/UWP/FileDbCache.UWP.csproj b/FileDbCache/UWP/FileDbCache.UWP.csproj index 4207dc4b..67599995 100644 --- a/FileDbCache/UWP/FileDbCache.UWP.csproj +++ b/FileDbCache/UWP/FileDbCache.UWP.csproj @@ -12,7 +12,7 @@ en-US UAP 10.0.19041.0 - 10.0.17134.0 + 10.0.17763.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} diff --git a/MBTiles/UWP/MBTiles.UWP.csproj b/MBTiles/UWP/MBTiles.UWP.csproj index a2561127..46dedbd9 100644 --- a/MBTiles/UWP/MBTiles.UWP.csproj +++ b/MBTiles/UWP/MBTiles.UWP.csproj @@ -12,7 +12,7 @@ en-US UAP 10.0.19041.0 - 10.0.17134.0 + 10.0.17763.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} diff --git a/MapControl/Shared/PushpinBorder.cs b/MapControl/Shared/PushpinBorder.cs new file mode 100644 index 00000000..5c525b55 --- /dev/null +++ b/MapControl/Shared/PushpinBorder.cs @@ -0,0 +1,115 @@ +// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control +// © 2022 Clemens Fischer +// Licensed under the Microsoft Public License (Ms-PL) + +using System; +#if WINUI +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using Windows.Foundation; +#elif UWP +using Windows.Foundation; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; +#else +using System.Windows; +using System.Windows.Media; +#endif + +namespace MapControl +{ + public partial class PushpinBorder + { + public Size ArrowSize + { + get { return (Size)GetValue(ArrowSizeProperty); } + set { SetValue(ArrowSizeProperty, value); } + } + + public double BorderWidth + { + get { return (double)GetValue(BorderWidthProperty); } + set { SetValue(BorderWidthProperty, value); } + } + + protected virtual Geometry BuildGeometry() + { + var width = Math.Floor(RenderSize.Width); + var height = Math.Floor(RenderSize.Height); + var x1 = BorderWidth / 2d; + var y1 = BorderWidth / 2d; + var x2 = width - x1; + var y3 = height - y1; + var y2 = y3 - ArrowSize.Height; + var aw = ArrowSize.Width; + var r1 = CornerRadius.TopLeft; + var r2 = CornerRadius.TopRight; + var r3 = CornerRadius.BottomRight; + var r4 = CornerRadius.BottomLeft; + + var figure = new PathFigure + { + StartPoint = new Point(x1, y1 + r1), + IsClosed = true, + IsFilled = true + }; + + figure.Segments.Add(ArcTo(x1 + r1, y1, r1)); + figure.Segments.Add(LineTo(x2 - r2, y1)); + figure.Segments.Add(ArcTo(x2, y1 + r2, r2)); + + if (HorizontalAlignment == HorizontalAlignment.Right) + { + figure.Segments.Add(LineTo(x2, y3)); + figure.Segments.Add(LineTo(x2 - aw, y2)); + } + else + { + figure.Segments.Add(LineTo(x2, y2 - r3)); + figure.Segments.Add(ArcTo(x2 - r3, y2, r3)); + } + + if (HorizontalAlignment != HorizontalAlignment.Left && HorizontalAlignment != HorizontalAlignment.Right) + { + var c = width / 2d; + figure.Segments.Add(LineTo(c + aw / 2d, y2)); + figure.Segments.Add(LineTo(c, y3)); + figure.Segments.Add(LineTo(c - aw / 2d, y2)); + } + + if (HorizontalAlignment == HorizontalAlignment.Left) + { + figure.Segments.Add(LineTo(x1 + aw, y2)); + figure.Segments.Add(LineTo(x1, y3)); + } + else + { + figure.Segments.Add(LineTo(x1 + r4, y2)); + figure.Segments.Add(ArcTo(x1, y2 - r4, r4)); + } + + var geometry = new PathGeometry(); + geometry.Figures.Add(figure); + + return geometry; + } + + private static LineSegment LineTo(double x, double y) + { + return new LineSegment + { + Point = new Point(x, y) + }; + } + + private static ArcSegment ArcTo(double x, double y, double r) + { + return new ArcSegment + { + Point = new Point(x, y), + Size = new Size(r, r), + SweepDirection = SweepDirection.Clockwise + }; + } + } +} diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index ea8ce1c5..45745012 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -12,7 +12,7 @@ en-US UAP 10.0.19041.0 - 10.0.17134.0 + 10.0.17763.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -140,6 +140,9 @@ OrthographicProjection.cs + + PushpinBorder.cs + StereographicProjection.cs @@ -233,6 +236,9 @@ Point.WinUI.cs + + PushpinBorder.WinUI.cs + Tile.WinUI.cs diff --git a/MapControl/UWP/Themes/Generic.xaml b/MapControl/UWP/Themes/Generic.xaml index bb354d73..fbd41ed6 100644 --- a/MapControl/UWP/Themes/Generic.xaml +++ b/MapControl/UWP/Themes/Generic.xaml @@ -49,31 +49,24 @@