// XAML Map Control - http://xamlmapcontrol.codeplex.com/ // © 2015 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() { InvalidateVisual(); } protected override void OnRender(DrawingContext drawingContext) { if (ParentMap != null) { var bounds = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(ParentMap.RenderSize)); var start = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y)); var end = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height)); var lineDistance = GetLineDistance(); var labelFormat = GetLabelFormat(lineDistance); var latLabelStart = Math.Ceiling(start.Latitude / lineDistance) * lineDistance; var lonLabelStart = Math.Ceiling(start.Longitude / lineDistance) * lineDistance; var latLabels = new List