CoordinateConverter.cs 1019 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. namespace FastReport.Map
  6. {
  7. internal static class CoordinateConverter
  8. {
  9. private const double MaxLat = 85.0511287798066;
  10. public static float GetX(double x, double minX, float scale)
  11. {
  12. return (float)((x - minX) * scale);
  13. }
  14. public static float GetY(double y, double maxY, float scale, bool mercator)
  15. {
  16. if (mercator)
  17. {
  18. y = ConvertMercator(y);
  19. maxY = ConvertMercator(maxY);
  20. }
  21. return (float)(-(y - maxY) * scale);
  22. }
  23. public static double ConvertMercator(double value)
  24. {
  25. if (value > MaxLat)
  26. value = MaxLat;
  27. else if (value < -MaxLat)
  28. value = -MaxLat;
  29. double sinLat = Math.Sin((Math.PI / 180) * value);
  30. return (90 / Math.PI) * Math.Log((1 + sinLat) / (1 - sinLat));
  31. }
  32. }
  33. }