Files
@ ae8f7007cb0e
Branch filter:
Location: seniordesign-ui/GMap.NET.Core/GMap.NET.Projections/MercatorProjectionYandex.cs
ae8f7007cb0e
3.3 KiB
text/x-csharp
Added licensing information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
namespace GMap.NET.Projections
{
using System;
class MercatorProjectionYandex : PureProjection
{
public static readonly MercatorProjectionYandex Instance = new MercatorProjectionYandex();
static readonly double MinLatitude = -85.05112878;
static readonly double MaxLatitude = 85.05112878;
static readonly double MinLongitude = -177;
static readonly double MaxLongitude = 177;
static readonly double RAD_DEG = 180 / Math.PI;
static readonly double DEG_RAD = Math.PI / 180;
static readonly double MathPiDiv4 = Math.PI / 4;
public override RectLatLng Bounds
{
get
{
return RectLatLng.FromLTRB(MinLongitude, MaxLatitude, MaxLongitude, MinLatitude);
}
}
GSize tileSize = new GSize(256, 256);
public override GSize TileSize
{
get
{
return tileSize;
}
}
public override double Axis
{
get
{
return 6356752.3142;
}
}
public override double Flattening
{
get
{
return (1.0 / 298.257223563);
}
}
public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
{
lat = Clip(lat, MinLatitude, MaxLatitude);
lng = Clip(lng, MinLongitude, MaxLongitude);
double rLon = lng * DEG_RAD; // Math.PI / 180;
double rLat = lat * DEG_RAD; // Math.PI / 180;
double a = 6378137;
double k = 0.0818191908426;
double z = Math.Tan(MathPiDiv4 + rLat / 2) / Math.Pow((Math.Tan(MathPiDiv4 + Math.Asin(k * Math.Sin(rLat)) / 2)), k);
double z1 = Math.Pow(2, 23 - zoom);
double DX = ((20037508.342789 + a * rLon) * 53.5865938 / z1);
double DY = ((20037508.342789 - a * Math.Log(z)) * 53.5865938 / z1);
GPoint ret = GPoint.Empty;
ret.X = (long)DX;
ret.Y = (long)DY;
return ret;
}
public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
{
GSize s = GetTileMatrixSizePixel(zoom);
double mapSizeX = s.Width;
double mapSizeY = s.Height;
double a = 6378137;
double c1 = 0.00335655146887969;
double c2 = 0.00000657187271079536;
double c3 = 0.00000001764564338702;
double c4 = 0.00000000005328478445;
double z1 = (23 - zoom);
double mercX = (x * Math.Pow(2, z1)) / 53.5865938 - 20037508.342789;
double mercY = 20037508.342789 - (y * Math.Pow(2, z1)) / 53.5865938;
double g = Math.PI / 2 - 2 * Math.Atan(1 / Math.Exp(mercY / a));
double z = g + c1 * Math.Sin(2 * g) + c2 * Math.Sin(4 * g) + c3 * Math.Sin(6 * g) + c4 * Math.Sin(8 * g);
PointLatLng ret = PointLatLng.Empty;
ret.Lat = z * RAD_DEG;
ret.Lng = mercX / a * RAD_DEG;
return ret;
}
public override GSize GetTileMatrixMinXY(int zoom)
{
return new GSize(0, 0);
}
public override GSize GetTileMatrixMaxXY(int zoom)
{
long xy = (1 << zoom);
return new GSize(xy - 1, xy - 1);
}
}
}
|