XAML-Map-Control/MapControl/MapGraticule.cs

53 lines
1.6 KiB
C#
Raw Normal View History

// XAML Map Control - http://xamlmapcontrol.codeplex.com/
2015-01-20 17:52:02 +01:00
// © 2015 Clemens Fischer
2012-05-04 12:52:20 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if NETFX_CORE
using Windows.UI.Xaml;
#else
2012-04-25 22:02:53 +02:00
using System.Windows;
#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>
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 };
public static readonly DependencyProperty MinLineSpacingProperty = DependencyProperty.Register(
"MinLineSpacing", typeof(double), typeof(MapGraticule), new PropertyMetadata(150d));
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)
{
var hemisphere = hemispheres[0];
2012-04-25 22:02:53 +02:00
if (value < -1e-8) // ~1mm
{
value = -value;
hemisphere = hemispheres[1];
}
var minutes = (int)Math.Round(value * 60d);
2012-04-25 22:02:53 +02:00
return string.Format(format, hemisphere, minutes / 60, (double)(minutes % 60));
}
}
}