// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control // © 2019 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) using System; using System.Collections.Generic; using System.Globalization; using System.Windows; using System.Windows.Media; namespace MapControl { public partial class MapGraticule { private class Label { public readonly double Position; public readonly FormattedText Text; public Label(double position, FormattedText text) { Position = position; Text = text; } } static MapGraticule() { IsHitTestVisibleProperty.OverrideMetadata(typeof(MapGraticule), new FrameworkPropertyMetadata(false)); 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) { var lineDistance = GetLineDistance(); var labelFormat = GetLabelFormat(lineDistance); if (projection.IsNormalCylindrical) { DrawCylindricalGraticule(drawingContext, projection, lineDistance, labelFormat); } else { // todo } } } private void DrawCylindricalGraticule(DrawingContext drawingContext, MapProjection projection, double lineDistance, string labelFormat) { var boundingBox = projection.ViewportRectToBoundingBox(new Rect(ParentMap.RenderSize)); var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance; var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance; var latLabels = new List