Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2287 - 1

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