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)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#if WINRT
|
|
|
|
|
|
using Windows.Foundation;
|
|
|
|
|
|
#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
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Transforms latitude and longitude values in degrees to cartesian coordinates
|
|
|
|
|
|
/// according to the Mercator transform.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MercatorTransform : MapTransform
|
|
|
|
|
|
{
|
|
|
|
|
|
public override double MaxLatitude
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return 85.0511; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-05-04 12:52:20 +02:00
|
|
|
|
public override double RelativeScale(Location location)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-05-04 12:52:20 +02:00
|
|
|
|
if (location.Latitude <= -90d)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
return double.NegativeInfinity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-05-04 12:52:20 +02:00
|
|
|
|
if (location.Latitude >= 90d)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
return double.PositiveInfinity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-05-04 12:52:20 +02:00
|
|
|
|
return 1d / Math.Cos(location.Latitude * Math.PI / 180d);
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-05-04 12:52:20 +02:00
|
|
|
|
public override Point Transform(Location location)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
if (double.IsNaN(location.Y))
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
if (location.Latitude <= -90d)
|
|
|
|
|
|
{
|
|
|
|
|
|
location.Y = double.NegativeInfinity;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (location.Latitude >= 90d)
|
|
|
|
|
|
{
|
|
|
|
|
|
location.Y = double.PositiveInfinity;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var lat = location.Latitude * Math.PI / 180d;
|
|
|
|
|
|
location.Y = (Math.Log(Math.Tan(lat) + 1d / Math.Cos(lat))) / Math.PI * 180d;
|
|
|
|
|
|
}
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
return new Point(location.Longitude, location.Y);
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
public override Location Transform(Point point)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var location = new Location(Math.Atan(Math.Sinh(point.Y * Math.PI / 180d)) / Math.PI * 180d, point.X);
|
|
|
|
|
|
location.Y = point.Y;
|
|
|
|
|
|
return location;
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|