Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2498 - 1

2
namespace GMap.NET.Projections
3
{
4
   using System;
5
   using System.Collections.Generic;
6
 
7
   /// <summary>
8
   /// GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]
9
   /// PROJCS["LKS92 / Latvia TM",GEOGCS["LKS92",DATUM["D_Latvia_1992",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",24],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",-6000000],UNIT["Meter",1]]
10
   /// </summary>
11
   public class LKS92Projection : PureProjection
12
   {
13
      public static readonly LKS92Projection Instance = new LKS92Projection();
14
 
15
      static readonly double MinLatitude = 55.55;
16
      static readonly double MaxLatitude = 58.22;
17
      static readonly double MinLongitude = 20.22;
18
      static readonly double MaxLongitude = 28.28;
19
 
20
      static readonly double orignX = -5120900;
21
      static readonly double orignY = 3998100;
22
 
23
      static readonly double scaleFactor = 0.9996;                      // scale factor                         
24
      static readonly double centralMeridian = 0.41887902047863912;// Center longitude (projection center) 
25
      static readonly double latOrigin = 0.0;                      // center latitude                   
26
      static readonly double falseNorthing = -6000000.0;                  // y offset in meters                 
27
      static readonly double falseEasting = 500000.0;          // x offset in meters                    
28
      static readonly double semiMajor = 6378137.0;                 // major axis
29
      static readonly double semiMinor = 6356752.3141403561; // minor axis
30
      static readonly double semiMinor2 = 6356752.3142451793;           // minor axis
31
      static readonly double metersPerUnit = 1.0;
32
      static readonly double COS_67P5 = 0.38268343236508977; // cosine of 67.5 degrees
33
      static readonly double AD_C = 1.0026000;               // Toms region 1 constant
34
 
35
      public override RectLatLng Bounds
36
      {
37
         get
38
         {
39
            return RectLatLng.FromLTRB(MinLongitude, MaxLatitude, MaxLongitude, MinLatitude);
40
         }
41
      }
42
 
43
      GSize tileSize = new GSize(256, 256);
44
      public override GSize TileSize
45
      {
46
         get
47
         {
48
            return tileSize;
49
         }
50
      }
51
 
52
      public override double Axis
53
      {
54
         get
55
         {
56
            return 6378137;
57
         }
58
      }
59
 
60
      public override double Flattening
61
      {
62
         get
63
         {
64
            return (1.0 / 298.257222101);
65
         }
66
      }
67
 
68
      public override GPoint FromLatLngToPixel(double lat, double lng, int zoom)
69
      {
70
         lat = Clip(lat, MinLatitude, MaxLatitude);
71
         lng = Clip(lng, MinLongitude, MaxLongitude);
72
 
73
         double[] lks = new double[] { lng, lat };
74
         lks = DTM10(lks);
75
         lks = MTD10(lks);
76
         lks = DTM00(lks);
77
 
78
         double res = GetTileMatrixResolution(zoom);
79
         return LksToPixel(lks, res);
80
      }
81
 
82
      static GPoint LksToPixel(double[] lks, double res)
83
      {
84
         return new GPoint((long)Math.Floor((lks[0] - orignX) / res), (long)Math.Floor((orignY - lks[1]) / res));
85
      }
86
 
87
      public override PointLatLng FromPixelToLatLng(long x, long y, int zoom)
88
      {
89
         PointLatLng ret = PointLatLng.Empty;
90
 
91
         double res = GetTileMatrixResolution(zoom);
92
 
93
         double[] lks = new double[] { (x * res) + orignX, orignY - (y * res) };
94
         lks = MTD11(lks);
95
         lks = DTM10(lks);
96
         lks = MTD10(lks);
97
 
98
         ret.Lat = Clip(lks[1], MinLatitude, MaxLatitude);
99
         ret.Lng = Clip(lks[0], MinLongitude, MaxLongitude);
100
 
101
         return ret;
102
      }
103
 
104
      double[] DTM10(double[] lonlat)
105
      {
106
         // Eccentricity squared : (a^2 - b^2)/a^2
107
         double es = 1.0 - (semiMinor2 * semiMinor2) / (semiMajor * semiMajor); // e^2
108
 
109
         // Second eccentricity squared : (a^2 - b^2)/b^2
110
         double ses = (Math.Pow(semiMajor, 2) - Math.Pow(semiMinor2, 2)) / Math.Pow(semiMinor2, 2);
111
 
112
         double ba = semiMinor2 / semiMajor;
113
         double ab = semiMajor / semiMinor2;
114
 
115
         double lon = DegreesToRadians(lonlat[0]);
116
         double lat = DegreesToRadians(lonlat[1]);
117
         double h = lonlat.Length < 3 ? 0 : lonlat[2].Equals(Double.NaN) ? 0 : lonlat[2];
118
         double v = semiMajor / Math.Sqrt(1 - es * Math.Pow(Math.Sin(lat), 2));
119
         double x = (v + h) * Math.Cos(lat) * Math.Cos(lon);
120
         double y = (v + h) * Math.Cos(lat) * Math.Sin(lon);
121
         double z = ((1 - es) * v + h) * Math.Sin(lat);
122
         return new double[] { x, y, z, };
123
      }
124
 
125
      double[] MTD10(double[] pnt)
126
      {
127
         // Eccentricity squared : (a^2 - b^2)/a^2
128
         double es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor); // e^2
129
 
130
         // Second eccentricity squared : (a^2 - b^2)/b^2
131
         double ses = (Math.Pow(semiMajor, 2) - Math.Pow(semiMinor, 2)) / Math.Pow(semiMinor, 2);
132
 
133
         double ba = semiMinor / semiMajor;
134
         double ab = semiMajor / semiMinor;
135
 
136
         bool AtPole = false; // is location in polar region
137
         double Z = pnt.Length < 3 ? 0 : pnt[2].Equals(Double.NaN) ? 0 : pnt[2];
138
 
139
         double lon = 0;
140
         double lat = 0;
141
         double Height = 0;
142
         if(pnt[0] != 0.0)
143
         {
144
            lon = Math.Atan2(pnt[1], pnt[0]);
145
         }
146
         else
147
         {
148
            if(pnt[1] > 0)
149
            {
150
               lon = Math.PI / 2;
151
            }
152
            else
153
               if(pnt[1] < 0)
154
               {
155
                  lon = -Math.PI * 0.5;
156
               }
157
               else
158
               {
159
                  AtPole = true;
160
                  lon = 0.0;
161
                  if(Z > 0.0) // north pole
162
                  {
163
                     lat = Math.PI * 0.5;
164
                  }
165
                  else
166
                     if(Z < 0.0) // south pole
167
                     {
168
                        lat = -Math.PI * 0.5;
169
                     }
170
                     else // center of earth
171
                     {
172
                        return new double[] { RadiansToDegrees(lon), RadiansToDegrees(Math.PI * 0.5), -semiMinor, };
173
                     }
174
               }
175
         }
176
         double W2 = pnt[0] * pnt[0] + pnt[1] * pnt[1]; // Square of distance from Z axis
177
         double W = Math.Sqrt(W2); // distance from Z axis
178
         double T0 = Z * AD_C; // initial estimate of vertical component
179
         double S0 = Math.Sqrt(T0 * T0 + W2); // initial estimate of horizontal component
180
         double Sin_B0 = T0 / S0; // sin(B0), B0 is estimate of Bowring aux variable
181
         double Cos_B0 = W / S0; // cos(B0)
182
         double Sin3_B0 = Math.Pow(Sin_B0, 3);
183
         double T1 = Z + semiMinor * ses * Sin3_B0; // corrected estimate of vertical component
184
         double Sum = W - semiMajor * es * Cos_B0 * Cos_B0 * Cos_B0; // numerator of cos(phi1)
185
         double S1 = Math.Sqrt(T1 * T1 + Sum * Sum); // corrected estimate of horizontal component
186
         double Sin_p1 = T1 / S1; // sin(phi1), phi1 is estimated latitude
187
         double Cos_p1 = Sum / S1; // cos(phi1)
188
         double Rn = semiMajor / Math.Sqrt(1.0 - es * Sin_p1 * Sin_p1); // Earth radius at location
189
         if(Cos_p1 >= COS_67P5)
190
         {
191
            Height = W / Cos_p1 - Rn;
192
         }
193
         else
194
            if(Cos_p1 <= -COS_67P5)
195
            {
196
               Height = W / -Cos_p1 - Rn;
197
            }
198
            else
199
            {
200
               Height = Z / Sin_p1 + Rn * (es - 1.0);
201
            }
202
 
203
         if(!AtPole)
204
         {
205
            lat = Math.Atan(Sin_p1 / Cos_p1);
206
         }
207
         return new double[] { RadiansToDegrees(lon), RadiansToDegrees(lat), Height, };
208
      }
209
 
210
      double[] DTM00(double[] lonlat)
211
      {
212
         double e0, e1, e2, e3; // eccentricity constants               
213
         double e, es, esp;             // eccentricity constants               
214
         double ml0;                     // small value m                       
215
 
216
         es = 1.0 - Math.Pow(semiMinor / semiMajor, 2);
217
         e = Math.Sqrt(es);
218
         e0 = e0fn(es);
219
         e1 = e1fn(es);
220
         e2 = e2fn(es);
221
         e3 = e3fn(es);
222
         ml0 = semiMajor * mlfn(e0, e1, e2, e3, latOrigin);
223
         esp = es / (1.0 - es);
224
 
225
         // ...         
226
 
227
         double lon = DegreesToRadians(lonlat[0]);
228
         double lat = DegreesToRadians(lonlat[1]);
229
 
230
         double delta_lon = 0.0;  // Delta longitude (Given longitude - center)
231
         double sin_phi, cos_phi; // sin and cos value                          
232
         double al, als;                    // temporary values                         
233
         double c, t, tq;              // temporary values                              
234
         double con, n, ml;         // cone constant, small m                   
235
 
236
         delta_lon = AdjustLongitude(lon - centralMeridian);
237
         SinCos(lat, out sin_phi, out cos_phi);
238
 
239
         al = cos_phi * delta_lon;
240
         als = Math.Pow(al, 2);
241
         c = esp * Math.Pow(cos_phi, 2);
242
         tq = Math.Tan(lat);
243
         t = Math.Pow(tq, 2);
244
         con = 1.0 - es * Math.Pow(sin_phi, 2);
245
         n = semiMajor / Math.Sqrt(con);
246
         ml = semiMajor * mlfn(e0, e1, e2, e3, lat);
247
 
248
         double x = scaleFactor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 *
249
             (5.0 - 18.0 * t + Math.Pow(t, 2) + 72.0 * c - 58.0 * esp))) + falseEasting;
250
 
251
         double y = scaleFactor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 *
252
             (5.0 - t + 9.0 * c + 4.0 * Math.Pow(c, 2) + als / 30.0 * (61.0 - 58.0 * t
253
             + Math.Pow(t, 2) + 600.0 * c - 330.0 * esp))))) + falseNorthing;
254
 
255
         if(lonlat.Length < 3)
256
            return new double[] { x / metersPerUnit, y / metersPerUnit };
257
         else
258
            return new double[] { x / metersPerUnit, y / metersPerUnit, lonlat[2] };
259
      }
260
 
261
      double[] DTM01(double[] lonlat)
262
      {
263
         // Eccentricity squared : (a^2 - b^2)/a^2
264
         double es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor);
265
 
266
         // Second eccentricity squared : (a^2 - b^2)/b^2
267
         double ses = (Math.Pow(semiMajor, 2) - Math.Pow(semiMinor, 2)) / Math.Pow(semiMinor, 2);
268
 
269
         double ba = semiMinor / semiMajor;
270
         double ab = semiMajor / semiMinor;
271
 
272
         double lon = DegreesToRadians(lonlat[0]);
273
         double lat = DegreesToRadians(lonlat[1]);
274
         double h = lonlat.Length < 3 ? 0 : lonlat[2].Equals(Double.NaN) ? 0 : lonlat[2];
275
         double v = semiMajor / Math.Sqrt(1 - es * Math.Pow(Math.Sin(lat), 2));
276
         double x = (v + h) * Math.Cos(lat) * Math.Cos(lon);
277
         double y = (v + h) * Math.Cos(lat) * Math.Sin(lon);
278
         double z = ((1 - es) * v + h) * Math.Sin(lat);
279
         return new double[] { x, y, z, };
280
      }
281
 
282
      double[] MTD01(double[] pnt)
283
      {
284
         // Eccentricity squared : (a^2 - b^2)/a^2
285
         double es = 1.0 - (semiMinor2 * semiMinor2) / (semiMajor * semiMajor);
286
 
287
         // Second eccentricity squared : (a^2 - b^2)/b^2
288
         double ses = (Math.Pow(semiMajor, 2) - Math.Pow(semiMinor2, 2)) / Math.Pow(semiMinor2, 2);
289
 
290
         double ba = semiMinor2 / semiMajor;
291
         double ab = semiMajor / semiMinor2;
292
 
293
         bool At_Pole = false; // is location in polar region
294
         double Z = pnt.Length < 3 ? 0 : pnt[2].Equals(Double.NaN) ? 0 : pnt[2];
295
 
296
         double lon = 0;
297
         double lat = 0;
298
         double Height = 0;
299
         if(pnt[0] != 0.0)
300
         {
301
            lon = Math.Atan2(pnt[1], pnt[0]);
302
         }
303
         else
304
         {
305
            if(pnt[1] > 0)
306
            {
307
               lon = Math.PI / 2;
308
            }
309
            else
310
               if(pnt[1] < 0)
311
               {
312
                  lon = -Math.PI * 0.5;
313
               }
314
               else
315
               {
316
                  At_Pole = true;
317
                  lon = 0.0;
318
                  if(Z > 0.0) // north pole
319
                  {
320
                     lat = Math.PI * 0.5;
321
                  }
322
                  else
323
                     if(Z < 0.0) // south pole
324
                     {
325
                        lat = -Math.PI * 0.5;
326
                     }
327
                     else // center of earth
328
                     {
329
                        return new double[] { RadiansToDegrees(lon), RadiansToDegrees(Math.PI * 0.5), -semiMinor2, };
330
                     }
331
               }
332
         }
333
 
334
         double W2 = pnt[0] * pnt[0] + pnt[1] * pnt[1]; // Square of distance from Z axis
335
         double W = Math.Sqrt(W2);                      // distance from Z axis
336
         double T0 = Z * AD_C;                // initial estimate of vertical component
337
         double S0 = Math.Sqrt(T0 * T0 + W2); //initial estimate of horizontal component
338
         double Sin_B0 = T0 / S0;             // sin(B0), B0 is estimate of Bowring aux variable
339
         double Cos_B0 = W / S0;              // cos(B0)
340
         double Sin3_B0 = Math.Pow(Sin_B0, 3);
341
         double T1 = Z + semiMinor2 * ses * Sin3_B0; //corrected estimate of vertical component
342
         double Sum = W - semiMajor * es * Cos_B0 * Cos_B0 * Cos_B0; // numerator of cos(phi1)
343
         double S1 = Math.Sqrt(T1 * T1 + Sum * Sum); // corrected estimate of horizontal component
344
         double Sin_p1 = T1 / S1;  // sin(phi1), phi1 is estimated latitude
345
         double Cos_p1 = Sum / S1; // cos(phi1)
346
         double Rn = semiMajor / Math.Sqrt(1.0 - es * Sin_p1 * Sin_p1); // Earth radius at location
347
 
348
         if(Cos_p1 >= COS_67P5)
349
         {
350
            Height = W / Cos_p1 - Rn;
351
         }
352
         else
353
            if(Cos_p1 <= -COS_67P5)
354
            {
355
               Height = W / -Cos_p1 - Rn;
356
            }
357
            else
358
            {
359
               Height = Z / Sin_p1 + Rn * (es - 1.0);
360
            }
361
 
362
         if(!At_Pole)
363
         {
364
            lat = Math.Atan(Sin_p1 / Cos_p1);
365
         }
366
         return new double[] { RadiansToDegrees(lon), RadiansToDegrees(lat), Height, };
367
      }
368
 
369
      double[] MTD11(double[] p)
370
      {
371
         double e0, e1, e2, e3; // eccentricity constants               
372
         double e, es, esp;             // eccentricity constants               
373
         double ml0;                // small value m
374
 
375
         es = 1.0 - Math.Pow(semiMinor / semiMajor, 2);
376
         e = Math.Sqrt(es);
377
         e0 = e0fn(es);
378
         e1 = e1fn(es);
379
         e2 = e2fn(es);
380
         e3 = e3fn(es);
381
         ml0 = semiMajor * mlfn(e0, e1, e2, e3, latOrigin);
382
         esp = es / (1.0 - es);
383
 
384
         // ...
385
 
386
         double con, phi;
387
         double delta_phi;
388
         long i;
389
         double sin_phi, cos_phi, tan_phi;
390
         double c, cs, t, ts, n, r, d, ds;
391
         long max_iter = 6;
392
 
393
         double x = p[0] * metersPerUnit - falseEasting;
394
         double y = p[1] * metersPerUnit - falseNorthing;
395
 
396
         con = (ml0 + y / scaleFactor) / semiMajor;
397
         phi = con;
398
         for(i = 0; ; i++)
399
         {
400
            delta_phi = ((con + e1 * Math.Sin(2.0 * phi) - e2 * Math.Sin(4.0 * phi) + e3 * Math.Sin(6.0 * phi)) / e0) - phi;
401
            phi += delta_phi;
402
 
403
            if(Math.Abs(delta_phi) <= EPSLoN)
404
               break;
405
 
406
            if(i >= max_iter)
407
               throw new ArgumentException("Latitude failed to converge");
408
         }
409
 
410
         if(Math.Abs(phi) < HALF_PI)
411
         {
412
            SinCos(phi, out sin_phi, out cos_phi);
413
            tan_phi = Math.Tan(phi);
414
            c = esp * Math.Pow(cos_phi, 2);
415
            cs = Math.Pow(c, 2);
416
            t = Math.Pow(tan_phi, 2);
417
            ts = Math.Pow(t, 2);
418
            con = 1.0 - es * Math.Pow(sin_phi, 2);
419
            n = semiMajor / Math.Sqrt(con);
420
            r = n * (1.0 - es) / con;
421
            d = x / (n * scaleFactor);
422
            ds = Math.Pow(d, 2);
423
 
424
            double lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24.0 * (5.0 + 3.0 * t +
425
                10.0 * c - 4.0 * cs - 9.0 * esp - ds / 30.0 * (61.0 + 90.0 * t +
426
                298.0 * c + 45.0 * ts - 252.0 * esp - 3.0 * cs)));
427
 
428
            double lon = AdjustLongitude(centralMeridian + (d * (1.0 - ds / 6.0 * (1.0 + 2.0 * t +
429
                c - ds / 20.0 * (5.0 - 2.0 * c + 28.0 * t - 3.0 * cs + 8.0 * esp +
430
                24.0 * ts))) / cos_phi));
431
 
432
            if(p.Length < 3)
433
               return new double[] { RadiansToDegrees(lon), RadiansToDegrees(lat) };
434
            else
435
               return new double[] { RadiansToDegrees(lon), RadiansToDegrees(lat), p[2] };
436
         }
437
         else
438
         {
439
            if(p.Length < 3)
440
               return new double[] { RadiansToDegrees(HALF_PI * Sign(y)), RadiansToDegrees(centralMeridian) };
441
            else
442
               return new double[] { RadiansToDegrees(HALF_PI * Sign(y)), RadiansToDegrees(centralMeridian), p[2] };
443
         }
444
      }
445
 
446
      #region -- levels info --
447
       /*
448
       "spatialReference":{"wkid":3059,"latestWkid":3059},"singleFusedMapCache":true,
449
       * "tileInfo":{"rows":256,"cols":256,"dpi":96,"format":"PNG8","compressionQuality":0,
450
       * "origin":{"x":-5120900,"y":3998100},
451
       * "spatialReference":{"wkid":3059,"latestWkid":3059},
452
       *
453
       * "lods":[
454
       * {"level":0,"resolution":1587.5031750063501,"scale":6000000},
455
       * {"level":1,"resolution":793.7515875031751,"scale":3000000},
456
       * {"level":2,"resolution":529.1677250021168,"scale":2000000},
457
       * {"level":3,"resolution":264.5838625010584,"scale":1000000},
458
       * {"level":4,"resolution":132.2919312505292,"scale":500000},
459
       * {"level":5,"resolution":52.91677250021167,"scale":200000},
460
       * {"level":6,"resolution":26.458386250105836,"scale":100000},
461
       * {"level":7,"resolution":13.229193125052918,"scale":50000},
462
       * {"level":8,"resolution":6.614596562526459,"scale":25000},
463
       * {"level":9,"resolution":2.6458386250105836,"scale":10000},
464
       * {"level":10,"resolution":1.3229193125052918,"scale":5000},
465
       * {"level":11,"resolution":0.5291677250021167,"scale":2000}]},
466
       *
467
       * "initialExtent":
468
       * {"xmin":352544.7096929534,"ymin":240883.24768736016,
469
       * "xmax":722784.980307047,"ymax":539178.473189597,
470
       * "spatialReference":{"wkid":3059,"latestWkid":3059}},
471
       *
472
       * "fullExtent":
473
       * {"xmin":312773.6900000004,"ymin":172941,
474
       * "xmax":762556,"ymax":438880,
475
       * "spatialReference":{"wkid":3059,"latestWkid":3059}},
476
       *
477
       * "minScale":6000000,"maxScale":2000,"units":"esriMeters","supportedImageFormatTypes":"PNG32,PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,BMP",
478
       * "documentInfo":{"Title":"ikartelv","Author":"gstanevicius","Comments":"","Subject":"","Category":"","AntialiasingMode":"None","TextAntialiasingMode":"Force","Keywords":""},"capabilities":"Map,Query,Data","supportedQueryFormats":"JSON, AMF","exportTilesAllowed":false,"maxRecordCount":500,"maxImageHeight":4096,"maxImageWidth":4096,"supportedExtensions":"KmlServer, WMSServer"});
479
      */    
480
 
481
      #endregion
482
 
483
      public static double GetTileMatrixResolution(int zoom)
484
      {
485
         double ret = 0;
486
 
487
         switch(zoom)
488
         {
489
            #region -- sizes --
490
            case 0:
491
            {
492
               ret = 1587.5031750063501;
493
            }
494
            break;
495
 
496
            case 1:
497
            {
498
               ret = 793.7515875031751;
499
            }
500
            break;
501
 
502
            case 2:
503
            {
504
               ret = 529.1677250021168;
505
            }
506
            break;
507
 
508
            case 3:
509
            {
510
               ret = 264.5838625010584;
511
            }
512
            break;
513
 
514
            case 4:
515
            {
516
               ret = 132.2919312505292;
517
            }
518
            break;
519
 
520
            case 5:
521
            {
522
               ret = 52.91677250021167;
523
            }
524
            break;
525
 
526
            case 6:
527
            {
528
               ret = 26.458386250105836;
529
            }
530
            break;
531
 
532
            case 7:
533
            {
534
               ret = 13.229193125052918;
535
            }
536
            break;
537
 
538
            case 8:
539
            {
540
               ret = 6.614596562526459;
541
            }
542
            break;
543
 
544
            case 9:
545
            {
546
               ret = 2.6458386250105836;
547
            }
548
            break;
549
 
550
            case 10:
551
            {
552
               ret = 1.3229193125052918;
553
            }
554
            break;
555
 
556
            case 11:
557
            {
558
               ret = 0.5291677250021167;
559
            }
560
            break;
561
            #endregion
562
         }
563
 
564
         return ret;
565
      }
566
 
567
      public override double GetGroundResolution(int zoom, double latitude)
568
      {
569
         return GetTileMatrixResolution(zoom);
570
      }
571
 
572
      Dictionary<int, GSize> extentMatrixMin;
573
      Dictionary<int, GSize> extentMatrixMax;
574
 
575
      public override GSize GetTileMatrixMinXY(int zoom)
576
      {
577
         if(extentMatrixMin == null)
578
         {
579
            GenerateExtents();
580
         }
581
         return extentMatrixMin[zoom];
582
      }
583
 
584
      public override GSize GetTileMatrixMaxXY(int zoom)
585
      {
586
         if(extentMatrixMax == null)
587
         {
588
            GenerateExtents();
589
         }
590
         return extentMatrixMax[zoom];
591
      }
592
 
593
      void GenerateExtents()
594
      {
595
         extentMatrixMin = new Dictionary<int, GSize>();
596
         extentMatrixMax = new Dictionary<int, GSize>();
597
         //RectLatLng Extent = RectLatLng.FromLTRB(219818.60040028347, 6407318.126743601, 747927.9899523959, 5826291.964691277);
598
 
599
         for(int i = 0; i <= 11; i++)
600
         {
601
            double res = GetTileMatrixResolution(i);
602
            //extentMatrixMin.Add(i, new GSize(FromPixelToTileXY(LksToPixel(new double[]{ Extent.Left, Extent.Top }, res))));
603
            //extentMatrixMax.Add(i, new GSize(FromPixelToTileXY(LksToPixel(new double[] { Extent.Right, Extent.Bottom }, res))));
604
 
605
            extentMatrixMin.Add(i, new GSize(FromPixelToTileXY(FromLatLngToPixel(Bounds.LocationTopLeft, i))));
606
            extentMatrixMax.Add(i, new GSize(FromPixelToTileXY(FromLatLngToPixel(Bounds.LocationRightBottom, i))));
607
         }
608
      }
609
   }
610
}