// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control // © 2022 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Media; namespace MapControl { public partial class MapGraticule { private const double LineInterpolationResolution = 2d; private class Label { public readonly double Position; public readonly FormattedText Text; public Label(double position, FormattedText text) { Position = position; Text = text; } } static MapGraticule() { StrokeThicknessProperty.OverrideMetadata(typeof(MapGraticule), new FrameworkPropertyMetadata(0.5)); } protected override void OnViewportChanged(ViewportChangedEventArgs e) { InvalidateVisual(); } protected override void OnRender(DrawingContext drawingContext) { var projection = ParentMap?.MapProjection; if (projection != null) { if (projection.Type <= MapProjectionType.NormalCylindrical) { DrawCylindricalGraticule(drawingContext); } else { DrawGraticule(drawingContext); } } } private void DrawCylindricalGraticule(DrawingContext drawingContext) { var path = new PathGeometry(); var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip; var lineDistance = GetLineDistance(); var labelFormat = GetLabelFormat(lineDistance); var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(ParentMap.RenderSize)); var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance; var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance; var latLabels = new List