Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2498 | - | 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 | /// |
||
10 | ///"spatialReference": |
||
11 | ///{"wkid":4326},"singleFusedMapCache":true,"tileInfo": |
||
12 | ///{"rows":256,"cols":256,"dpi":96,"format":"PNG8","compressionQuality":0, |
||
13 | ///"origin":{"x":-400,"y":400},"spatialReference":{"wkid":4326},"lods": |
||
14 | /// |
||
15 | ///[{"level":0,"resolution":0.0118973050291514,"scale":5000000}, |
||
16 | ///{"level":1,"resolution":0.0059486525145757,"scale":2500000}, |
||
17 | ///{"level":2,"resolution":0.00297432625728785,"scale":1250000}, |
||
18 | ///{"level":3,"resolution":0.00118973050291514,"scale":500000}, |
||
19 | ///{"level":4,"resolution":0.00059486525145757,"scale":250000}, |
||
20 | ///{"level":5,"resolution":0.000356919150874542,"scale":150000}, |
||
21 | ///{"level":6,"resolution":0.000178459575437271,"scale":75000}, |
||
22 | ///{"level":7,"resolution":0.000118973050291514,"scale":50000}, |
||
23 | ///{"level":8,"resolution":5.9486525145757E-05,"scale":25000}, |
||
24 | ///{"level":9,"resolution":3.56919150874542E-05,"scale":15000}, |
||
25 | ///{"level":10,"resolution":1.90356880466422E-05,"scale":8000}, |
||
26 | ///{"level":11,"resolution":9.51784402332112E-06,"scale":4000}, |
||
27 | ///{"level":12,"resolution":4.75892201166056E-06,"scale":2000}]}, |
||
28 | /// |
||
29 | ///"initialExtent": |
||
30 | ///{"xmin":42.1125196069871,"ymin":18.6650706214551,"xmax":65.698643558112 |
||
31 | ///4,"ymax":29.4472987133981,"spatialReference":{"wkid":4326}}, |
||
32 | /// |
||
33 | ///"fullExtent": |
||
34 | ///{"xmin":41.522866508209,"ymin":18.7071563263201,"xmax":66.2882966568906 |
||
35 | ///,"ymax":29.4052130085331,"spatialReference":{"wkid":4326}}, |
||
36 | /// |
||
37 | ///"units":"esriDecimalDegrees" |
||
38 | /// </summary> |
||
39 | public class PlateCarreeProjectionDarbAe : PureProjection |
||
40 | { |
||
41 | public static readonly PlateCarreeProjectionDarbAe Instance = new PlateCarreeProjectionDarbAe(); |
||
42 | |||
43 | public static readonly double MinLatitude = 18.7071563263201; |
||
44 | public static readonly double MaxLatitude = 29.4052130085331; |
||
45 | public static readonly double MinLongitude = 41.522866508209; |
||
46 | public static readonly double MaxLongitude = 66.2882966568906; |
||
47 | |||
48 | static readonly double orignX = -400; |
||
49 | static readonly double orignY = 400; |
||
50 | |||
51 | public override RectLatLng Bounds |
||
52 | { |
||
53 | get |
||
54 | { |
||
55 | return RectLatLng.FromLTRB(MinLongitude, MaxLatitude, MaxLongitude, MinLatitude); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | GSize tileSize = new GSize(256, 256); |
||
60 | public override GSize TileSize |
||
61 | { |
||
62 | get |
||
63 | { |
||
64 | return tileSize; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public override double Axis |
||
69 | { |
||
70 | get |
||
71 | { |
||
72 | return 6378137; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | public override double Flattening |
||
77 | { |
||
78 | get |
||
79 | { |
||
80 | return (1.0 / 298.257223563); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | public override GPoint FromLatLngToPixel(double lat, double lng, int zoom) |
||
85 | { |
||
86 | GPoint ret = GPoint.Empty; |
||
87 | |||
88 | lat = Clip(lat, MinLatitude, MaxLatitude); |
||
89 | lng = Clip(lng, MinLongitude, MaxLongitude); |
||
90 | |||
91 | /* |
||
92 | getContainingTileCoords:function(ti,_1dd,lod) |
||
93 | { |
||
94 | var to=ti.origin, |
||
95 | res=lod.resolution, |
||
96 | tmw=ti.width*res, |
||
97 | tmh=ti.height*res, |
||
98 | tc=Math.floor((_1dd.x-to.x)/tmw), |
||
99 | tr=Math.floor((to.y-_1dd.y)/tmh); |
||
100 | } |
||
101 | */ |
||
102 | |||
103 | double res = GetTileMatrixResolution(zoom); |
||
104 | |||
105 | ret.X = (long)Math.Floor((lng - orignX) / res); |
||
106 | ret.Y = (long)Math.Floor((orignY - lat) / res); |
||
107 | |||
108 | return ret; |
||
109 | } |
||
110 | |||
111 | public override PointLatLng FromPixelToLatLng(long x, long y, int zoom) |
||
112 | { |
||
113 | PointLatLng ret = PointLatLng.Empty; |
||
114 | |||
115 | double res = GetTileMatrixResolution(zoom); |
||
116 | |||
117 | ret.Lat = orignY - (y * res); |
||
118 | ret.Lng = (x * res) + orignX; |
||
119 | |||
120 | return ret; |
||
121 | } |
||
122 | |||
123 | public static double GetTileMatrixResolution(int zoom) |
||
124 | { |
||
125 | double ret = 0; |
||
126 | |||
127 | switch(zoom) |
||
128 | { |
||
129 | #region -- sizes -- |
||
130 | case 0: |
||
131 | { |
||
132 | ret = 0.0118973050291514; |
||
133 | } |
||
134 | break; |
||
135 | |||
136 | case 1: |
||
137 | { |
||
138 | ret = 0.0059486525145757; |
||
139 | } |
||
140 | break; |
||
141 | |||
142 | case 2: |
||
143 | { |
||
144 | ret = 0.00297432625728785; |
||
145 | } |
||
146 | break; |
||
147 | |||
148 | case 3: |
||
149 | { |
||
150 | ret = 0.00118973050291514; |
||
151 | } |
||
152 | break; |
||
153 | |||
154 | case 4: |
||
155 | { |
||
156 | ret = 0.00059486525145757; |
||
157 | } |
||
158 | break; |
||
159 | |||
160 | case 5: |
||
161 | { |
||
162 | ret = 0.000356919150874542; |
||
163 | } |
||
164 | break; |
||
165 | |||
166 | case 6: |
||
167 | { |
||
168 | ret = 0.000178459575437271; |
||
169 | } |
||
170 | break; |
||
171 | |||
172 | case 7: |
||
173 | { |
||
174 | ret = 0.000118973050291514; |
||
175 | } |
||
176 | break; |
||
177 | |||
178 | case 8: |
||
179 | { |
||
180 | ret = 5.9486525145757E-05; |
||
181 | } |
||
182 | break; |
||
183 | |||
184 | case 9: |
||
185 | { |
||
186 | ret = 3.56919150874542E-05; |
||
187 | } |
||
188 | break; |
||
189 | |||
190 | case 10: |
||
191 | { |
||
192 | ret = 1.90356880466422E-05; |
||
193 | } |
||
194 | break; |
||
195 | |||
196 | case 11: |
||
197 | { |
||
198 | ret = 9.51784402332112E-06; |
||
199 | } |
||
200 | break; |
||
201 | |||
202 | case 12: |
||
203 | { |
||
204 | ret = 4.75892201166056E-06; |
||
205 | } |
||
206 | break; |
||
207 | #endregion |
||
208 | } |
||
209 | |||
210 | return ret; |
||
211 | } |
||
212 | |||
213 | public override double GetGroundResolution(int zoom, double latitude) |
||
214 | { |
||
215 | return GetTileMatrixResolution(zoom); |
||
216 | } |
||
217 | |||
218 | public override GSize GetTileMatrixMaxXY(int zoom) |
||
219 | { |
||
220 | var maxPx = FromLatLngToPixel(MinLatitude, MaxLongitude, zoom); |
||
221 | return new GSize(FromPixelToTileXY(maxPx)); |
||
222 | } |
||
223 | |||
224 | public override GSize GetTileMatrixMinXY(int zoom) |
||
225 | { |
||
226 | var minPx = FromLatLngToPixel(MaxLatitude, MinLongitude, zoom); |
||
227 | return new GSize(FromPixelToTileXY(minPx)); |
||
228 | } |
||
229 | } |
||
230 | } |