Subversion Repositories Projects

Rev

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
   /// <summary>
7
   /// Plate Carrée (literally, “plane square”) projection
8
   /// PROJCS["WGS 84 / World Equidistant Cylindrical",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],UNIT["Meter",1]]
9
   /// </summary>
10
   public class PlateCarreeProjection : PureProjection
11
   {
12
      public static readonly PlateCarreeProjection Instance = new PlateCarreeProjection();
13
 
14
      static readonly double MinLatitude = -85.05112878;
15
      static readonly double MaxLatitude = 85.05112878;
16
      static readonly double MinLongitude = -180;
17
      static readonly double MaxLongitude = 180;
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(512, 512);
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 6378137;
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
         GPoint ret = GPoint.Empty;
55
 
56
         lat = Clip(lat, MinLatitude, MaxLatitude);
57
         lng = Clip(lng, MinLongitude, MaxLongitude);
58
 
59
         GSize s = GetTileMatrixSizePixel(zoom);
60
         double mapSizeX = s.Width;
61
         double mapSizeY = s.Height;
62
 
63
         double scale = 360.0 / mapSizeX;
64
 
65
         ret.Y = (long)((90.0 - lat) / scale);
66
         ret.X = (long)((lng + 180.0) / scale);
67
 
68
         return ret;
69
      }
70
 
71
      public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
72
      {
73
         PointLatLng ret = PointLatLng.Empty;
74
 
75
         GSize s = GetTileMatrixSizePixel(zoom);
76
         double mapSizeX = s.Width;
77
         double mapSizeY = s.Height;
78
 
79
         double scale = 360.0 / mapSizeX;
80
 
81
         ret.Lat = 90 - (y * scale);
82
         ret.Lng = (x * scale) - 180;
83
 
84
         return ret;
85
      }
86
 
87
      public override GSize GetTileMatrixMaxXY(int zoom)
88
      {
89
         long y = (long)Math.Pow(2, zoom);
90
         return new GSize((2 * y) - 1, y - 1);
91
      }
92
 
93
      public override GSize GetTileMatrixMinXY(int zoom)
94
      {
95
         return new GSize(0, 0);
96
      }
97
   }
98
}