// 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.Linq; 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() { UIElement.IsHitTestVisibleProperty.OverrideMetadata( typeof(MapGraticule), new FrameworkPropertyMetadata(false)); MapOverlay.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 minSpacing = MinLineSpacing * 360d / (Math.Pow(2d, ParentMap.ZoomLevel) * TileSource.TileSize); var spacing = LineSpacings[LineSpacings.Length - 1]; if (spacing >= minSpacing) { spacing = LineSpacings.FirstOrDefault(s => s >= minSpacing); } var latLabelStart = Math.Ceiling(start.Latitude / spacing) * spacing; var lonLabelStart = Math.Ceiling(start.Longitude / spacing) * spacing; var latLabels = new List