2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2012-05-04 12:52:20 +02:00
|
|
|
|
// Copyright © 2012 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#if WINRT
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
#else
|
2012-04-25 22:02:53 +02:00
|
|
|
|
using System.Windows;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#endif
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2012-05-04 12:52:20 +02:00
|
|
|
|
/// <summary>
|
2012-10-25 08:42:51 +02:00
|
|
|
|
/// Draws a graticule overlay.
|
2012-05-04 12:52:20 +02:00
|
|
|
|
/// </summary>
|
2012-11-22 21:42:29 +01:00
|
|
|
|
public partial class MapGraticule : MapOverlay
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-10-25 08:42:51 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Graticule line spacings in degrees.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static double[] LineSpacings =
|
2012-04-25 22:02:53 +02:00
|
|
|
|
new double[] { 1d / 60d, 1d / 30d, 1d / 12d, 1d / 6d, 1d / 4d, 1d / 3d, 1d / 2d, 1d, 2d, 5d, 10d, 15d, 20d, 30d, 45d };
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
public static readonly DependencyProperty MinLineSpacingProperty = DependencyProperty.Register(
|
|
|
|
|
|
"MinLineSpacing", typeof(double), typeof(MapGraticule), new PropertyMetadata(150d));
|
|
|
|
|
|
|
|
|
|
|
|
public MapGraticule()
|
|
|
|
|
|
{
|
|
|
|
|
|
StrokeThickness = 0.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-04 17:19:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Minimum spacing in pixels between adjacent graticule lines.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public double MinLineSpacing
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-07-04 17:19:48 +02:00
|
|
|
|
get { return (double)GetValue(MinLineSpacingProperty); }
|
|
|
|
|
|
set { SetValue(MinLineSpacingProperty, value); }
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string CoordinateString(double value, string format, string hemispheres)
|
|
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var hemisphere = hemispheres[0];
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
if (value < -1e-8) // ~1mm
|
|
|
|
|
|
{
|
|
|
|
|
|
value = -value;
|
|
|
|
|
|
hemisphere = hemispheres[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var minutes = (int)(value * 60d + 0.5);
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
return string.Format(format, hemisphere, minutes / 60, (double)(minutes % 60));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|