diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index 6ef6c2a5..d59c6dcb 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -3,13 +3,20 @@ // Licensed under the Microsoft Public License (Ms-PL) using System; +using System.Collections.Generic; using System.Globalization; +using System.Linq; #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 @@ -19,9 +26,22 @@ namespace MapControl /// public partial class MapGraticule : MapOverlay { + private class Label + { + public string LatitudeText { get; set; } + public string LongitudeText { get; set; } + public Point Position { get; set; } + public double Rotation { get; set; } + } + + private const double LineInterpolationResolution = 2d; + public static readonly DependencyProperty MinLineDistanceProperty = DependencyProperty.Register( nameof(MinLineDistance), typeof(double), typeof(MapGraticule), new PropertyMetadata(150d)); + private double lineDistance; + private string labelFormat; + /// /// Minimum graticule line distance in pixels. The default value is 150. /// @@ -31,7 +51,7 @@ namespace MapControl set { SetValue(MinLineDistanceProperty, value); } } - private double GetLineDistance() + private void SetLineDistance() { var minDistance = MinLineDistance / PixelPerLongitudeDegree(ParentMap.Center); var scale = minDistance < 1d / 60d ? 3600d : minDistance < 1d ? 60d : 1d; @@ -45,7 +65,10 @@ namespace MapControl i++; } - return Math.Min(lineDistances[i] / scale, 30d); + lineDistance = Math.Min(lineDistances[i] / scale, 30d); + + labelFormat = lineDistance < 1d / 60d ? "{0} {1}°{2:00}'{3:00}\"" + : lineDistance < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°"; } private double PixelPerLongitudeDegree(Location location) @@ -55,13 +78,7 @@ namespace MapControl Math.Cos(location.Latitude * Math.PI / 180d) * MapProjection.Wgs84MeterPerDegree); } - private static string GetLabelFormat(double lineDistance) - { - return lineDistance < 1d / 60d ? "{0} {1}°{2:00}'{3:00}\"" - : lineDistance < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°"; - } - - private static string GetLabelText(double value, string format, string hemispheres) + private string GetLabelText(double value, string hemispheres) { var hemisphere = hemispheres[0]; @@ -76,7 +93,252 @@ namespace MapControl var seconds = (int)Math.Round(value * 3600d); return string.Format(CultureInfo.InvariantCulture, - format, hemisphere, seconds / 3600, seconds / 60 % 60, seconds % 60); + labelFormat, hemisphere, seconds / 3600, seconds / 60 % 60, seconds % 60); + } + + private void AddLabel(ICollection