projection.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * DevExtreme (viz/vector_map/projection.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var projectionModule = require("./projection.main");
  11. var projection = projectionModule.projection;
  12. var _min = Math.min;
  13. var _max = Math.max;
  14. var _sin = Math.sin;
  15. var _asin = Math.asin;
  16. var _tan = Math.tan;
  17. var _atan = Math.atan;
  18. var _exp = Math.exp;
  19. var _log = Math.log;
  20. var PI = Math.PI;
  21. var PI_DIV_4 = PI / 4;
  22. var GEO_LON_BOUND = 180;
  23. var GEO_LAT_BOUND = 90;
  24. var RADIANS = PI / 180;
  25. var MERCATOR_LAT_BOUND = (2 * _atan(_exp(PI)) - PI / 2) / RADIANS;
  26. var MILLER_LAT_BOUND = (2.5 * _atan(_exp(.8 * PI)) - .625 * PI) / RADIANS;
  27. function clamp(value, threshold) {
  28. return _max(_min(value, +threshold), -threshold)
  29. }
  30. projection.add("mercator", projection({
  31. aspectRatio: 1,
  32. to: function(coordinates) {
  33. return [coordinates[0] / GEO_LON_BOUND, _log(_tan(PI_DIV_4 + clamp(coordinates[1], MERCATOR_LAT_BOUND) * RADIANS / 2)) / PI]
  34. },
  35. from: function(coordinates) {
  36. return [coordinates[0] * GEO_LON_BOUND, (2 * _atan(_exp(coordinates[1] * PI)) - PI / 2) / RADIANS]
  37. }
  38. }));
  39. projection.add("equirectangular", projection({
  40. aspectRatio: 2,
  41. to: function(coordinates) {
  42. return [coordinates[0] / GEO_LON_BOUND, coordinates[1] / GEO_LAT_BOUND]
  43. },
  44. from: function(coordinates) {
  45. return [coordinates[0] * GEO_LON_BOUND, coordinates[1] * GEO_LAT_BOUND]
  46. }
  47. }));
  48. projection.add("lambert", projection({
  49. aspectRatio: 2,
  50. to: function(coordinates) {
  51. return [coordinates[0] / GEO_LON_BOUND, _sin(clamp(coordinates[1], GEO_LAT_BOUND) * RADIANS)]
  52. },
  53. from: function(coordinates) {
  54. return [coordinates[0] * GEO_LON_BOUND, _asin(clamp(coordinates[1], 1)) / RADIANS]
  55. }
  56. }));
  57. projection.add("miller", projection({
  58. aspectRatio: 1,
  59. to: function(coordinates) {
  60. return [coordinates[0] / GEO_LON_BOUND, 1.25 * _log(_tan(PI_DIV_4 + clamp(coordinates[1], MILLER_LAT_BOUND) * RADIANS * .4)) / PI]
  61. },
  62. from: function(coordinates) {
  63. return [coordinates[0] * GEO_LON_BOUND, (2.5 * _atan(_exp(.8 * coordinates[1] * PI)) - .625 * PI) / RADIANS]
  64. }
  65. }));
  66. exports.projection = projection;