@math.gl/web-mercator 3.6.0-alpha.1 → 3.6.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/es5/fit-bounds.js +37 -31
  2. package/dist/es5/fit-bounds.js.map +1 -1
  3. package/dist/es5/fly-to-viewport.js +98 -75
  4. package/dist/es5/fly-to-viewport.js.map +1 -1
  5. package/dist/es5/get-bounds.js +25 -26
  6. package/dist/es5/get-bounds.js.map +1 -1
  7. package/dist/es5/index.js +31 -23
  8. package/dist/es5/index.js.map +1 -1
  9. package/dist/es5/math-utils.js +8 -3
  10. package/dist/es5/math-utils.js.map +1 -1
  11. package/dist/es5/normalize-viewport-props.js +21 -23
  12. package/dist/es5/normalize-viewport-props.js.map +1 -1
  13. package/dist/es5/web-mercator-utils.js +118 -92
  14. package/dist/es5/web-mercator-utils.js.map +1 -1
  15. package/dist/es5/web-mercator-viewport.js +239 -178
  16. package/dist/es5/web-mercator-viewport.js.map +1 -1
  17. package/dist/esm/fit-bounds.js +6 -13
  18. package/dist/esm/fit-bounds.js.map +1 -1
  19. package/dist/esm/fly-to-viewport.js.map +1 -1
  20. package/dist/esm/get-bounds.js +1 -1
  21. package/dist/esm/get-bounds.js.map +1 -1
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/math-utils.js +3 -0
  25. package/dist/esm/math-utils.js.map +1 -1
  26. package/dist/esm/normalize-viewport-props.js.map +1 -1
  27. package/dist/esm/web-mercator-utils.js +2 -1
  28. package/dist/esm/web-mercator-utils.js.map +1 -1
  29. package/dist/esm/web-mercator-viewport.js +1 -1
  30. package/dist/esm/web-mercator-viewport.js.map +1 -1
  31. package/dist/fit-bounds.d.ts +3 -2
  32. package/dist/fit-bounds.d.ts.map +1 -1
  33. package/dist/fit-bounds.js +6 -13
  34. package/dist/fly-to-viewport.d.ts +6 -6
  35. package/dist/fly-to-viewport.d.ts.map +1 -1
  36. package/dist/get-bounds.js +1 -1
  37. package/dist/index.d.ts +4 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/math-utils.d.ts +2 -1
  41. package/dist/math-utils.d.ts.map +1 -1
  42. package/dist/math-utils.js +3 -0
  43. package/dist/normalize-viewport-props.d.ts +1 -2
  44. package/dist/normalize-viewport-props.d.ts.map +1 -1
  45. package/dist/web-mercator-utils.d.ts +4 -3
  46. package/dist/web-mercator-utils.d.ts.map +1 -1
  47. package/dist/web-mercator-utils.js +3 -2
  48. package/dist/web-mercator-viewport.d.ts +4 -5
  49. package/dist/web-mercator-viewport.d.ts.map +1 -1
  50. package/dist/web-mercator-viewport.js +1 -2
  51. package/package.json +3 -3
  52. package/src/fit-bounds.ts +8 -16
  53. package/src/fly-to-viewport.ts +26 -11
  54. package/src/get-bounds.ts +4 -4
  55. package/src/index.ts +5 -0
  56. package/src/math-utils.ts +6 -2
  57. package/src/normalize-viewport-props.ts +1 -1
  58. package/src/web-mercator-utils.ts +9 -8
  59. package/src/web-mercator-viewport.ts +8 -10
package/dist/es5/index.js CHANGED
@@ -2,132 +2,140 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  Object.defineProperty(exports, "default", {
9
11
  enumerable: true,
10
- get: function () {
12
+ get: function get() {
11
13
  return _webMercatorViewport.default;
12
14
  }
13
15
  });
14
16
  Object.defineProperty(exports, "WebMercatorViewport", {
15
17
  enumerable: true,
16
- get: function () {
18
+ get: function get() {
17
19
  return _webMercatorViewport.default;
18
20
  }
19
21
  });
20
22
  Object.defineProperty(exports, "getBounds", {
21
23
  enumerable: true,
22
- get: function () {
24
+ get: function get() {
23
25
  return _getBounds.default;
24
26
  }
25
27
  });
26
28
  Object.defineProperty(exports, "fitBounds", {
27
29
  enumerable: true,
28
- get: function () {
30
+ get: function get() {
29
31
  return _fitBounds.default;
30
32
  }
31
33
  });
32
34
  Object.defineProperty(exports, "normalizeViewportProps", {
33
35
  enumerable: true,
34
- get: function () {
36
+ get: function get() {
35
37
  return _normalizeViewportProps.default;
36
38
  }
37
39
  });
38
40
  Object.defineProperty(exports, "flyToViewport", {
39
41
  enumerable: true,
40
- get: function () {
42
+ get: function get() {
41
43
  return _flyToViewport.default;
42
44
  }
43
45
  });
44
46
  Object.defineProperty(exports, "getFlyToDuration", {
45
47
  enumerable: true,
46
- get: function () {
48
+ get: function get() {
47
49
  return _flyToViewport.getFlyToDuration;
48
50
  }
49
51
  });
52
+ Object.defineProperty(exports, "MAX_LATITUDE", {
53
+ enumerable: true,
54
+ get: function get() {
55
+ return _webMercatorUtils.MAX_LATITUDE;
56
+ }
57
+ });
50
58
  Object.defineProperty(exports, "lngLatToWorld", {
51
59
  enumerable: true,
52
- get: function () {
60
+ get: function get() {
53
61
  return _webMercatorUtils.lngLatToWorld;
54
62
  }
55
63
  });
56
64
  Object.defineProperty(exports, "worldToLngLat", {
57
65
  enumerable: true,
58
- get: function () {
66
+ get: function get() {
59
67
  return _webMercatorUtils.worldToLngLat;
60
68
  }
61
69
  });
62
70
  Object.defineProperty(exports, "worldToPixels", {
63
71
  enumerable: true,
64
- get: function () {
72
+ get: function get() {
65
73
  return _webMercatorUtils.worldToPixels;
66
74
  }
67
75
  });
68
76
  Object.defineProperty(exports, "pixelsToWorld", {
69
77
  enumerable: true,
70
- get: function () {
78
+ get: function get() {
71
79
  return _webMercatorUtils.pixelsToWorld;
72
80
  }
73
81
  });
74
82
  Object.defineProperty(exports, "zoomToScale", {
75
83
  enumerable: true,
76
- get: function () {
84
+ get: function get() {
77
85
  return _webMercatorUtils.zoomToScale;
78
86
  }
79
87
  });
80
88
  Object.defineProperty(exports, "scaleToZoom", {
81
89
  enumerable: true,
82
- get: function () {
90
+ get: function get() {
83
91
  return _webMercatorUtils.scaleToZoom;
84
92
  }
85
93
  });
86
94
  Object.defineProperty(exports, "altitudeToFovy", {
87
95
  enumerable: true,
88
- get: function () {
96
+ get: function get() {
89
97
  return _webMercatorUtils.altitudeToFovy;
90
98
  }
91
99
  });
92
100
  Object.defineProperty(exports, "fovyToAltitude", {
93
101
  enumerable: true,
94
- get: function () {
102
+ get: function get() {
95
103
  return _webMercatorUtils.fovyToAltitude;
96
104
  }
97
105
  });
98
106
  Object.defineProperty(exports, "getMeterZoom", {
99
107
  enumerable: true,
100
- get: function () {
108
+ get: function get() {
101
109
  return _webMercatorUtils.getMeterZoom;
102
110
  }
103
111
  });
104
112
  Object.defineProperty(exports, "getDistanceScales", {
105
113
  enumerable: true,
106
- get: function () {
114
+ get: function get() {
107
115
  return _webMercatorUtils.getDistanceScales;
108
116
  }
109
117
  });
110
118
  Object.defineProperty(exports, "addMetersToLngLat", {
111
119
  enumerable: true,
112
- get: function () {
120
+ get: function get() {
113
121
  return _webMercatorUtils.addMetersToLngLat;
114
122
  }
115
123
  });
116
124
  Object.defineProperty(exports, "getViewMatrix", {
117
125
  enumerable: true,
118
- get: function () {
126
+ get: function get() {
119
127
  return _webMercatorUtils.getViewMatrix;
120
128
  }
121
129
  });
122
130
  Object.defineProperty(exports, "getProjectionMatrix", {
123
131
  enumerable: true,
124
- get: function () {
132
+ get: function get() {
125
133
  return _webMercatorUtils.getProjectionMatrix;
126
134
  }
127
135
  });
128
136
  Object.defineProperty(exports, "getProjectionParameters", {
129
137
  enumerable: true,
130
- get: function () {
138
+ get: function get() {
131
139
  return _webMercatorUtils.getProjectionParameters;
132
140
  }
133
141
  });
@@ -144,7 +152,7 @@ var _flyToViewport = _interopRequireWildcard(require("./fly-to-viewport"));
144
152
 
145
153
  var _webMercatorUtils = require("./web-mercator-utils");
146
154
 
147
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
155
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
148
156
 
149
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
157
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
150
158
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAEA","sourcesContent":["// Classic web-mercator-project\nexport {default} from './web-mercator-viewport';\nexport {default as WebMercatorViewport} from './web-mercator-viewport';\n\nexport {default as getBounds} from './get-bounds';\nexport {default as fitBounds} from './fit-bounds';\nexport {default as normalizeViewportProps} from './normalize-viewport-props';\nexport {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';\n\nexport {\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAEA","sourcesContent":["// Classic web-mercator-project\nexport {default} from './web-mercator-viewport';\nexport {default as WebMercatorViewport} from './web-mercator-viewport';\n\nexport {default as getBounds} from './get-bounds';\nexport {default as fitBounds} from './fit-bounds';\nexport {default as normalizeViewportProps} from './normalize-viewport-props';\nexport {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';\n\nexport {\n MAX_LATITUDE,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n\n/** Types */\nexport type {FitBoundsOptions} from './fit-bounds';\nexport type {DistanceScales} from './web-mercator-utils';\n"],"file":"index.js"}
@@ -7,6 +7,7 @@ exports.createMat4 = createMat4;
7
7
  exports.transformVector = transformVector;
8
8
  exports.mod = mod;
9
9
  exports.lerp = lerp;
10
+ exports.clamp = clamp;
10
11
  exports.log2 = void 0;
11
12
 
12
13
  var _vec = require("gl-matrix/vec4");
@@ -16,13 +17,13 @@ function createMat4() {
16
17
  }
17
18
 
18
19
  function transformVector(matrix, vector) {
19
- const result = (0, _vec.transformMat4)([], vector, matrix);
20
+ var result = (0, _vec.transformMat4)([], vector, matrix);
20
21
  (0, _vec.scale)(result, result, 1 / result[3]);
21
22
  return result;
22
23
  }
23
24
 
24
25
  function mod(value, divisor) {
25
- const modulus = value % divisor;
26
+ var modulus = value % divisor;
26
27
  return modulus < 0 ? divisor + modulus : modulus;
27
28
  }
28
29
 
@@ -30,10 +31,14 @@ function lerp(start, end, step) {
30
31
  return step * end + (1 - step) * start;
31
32
  }
32
33
 
34
+ function clamp(x, min, max) {
35
+ return x < min ? min : x > max ? max : x;
36
+ }
37
+
33
38
  function ieLog2(x) {
34
39
  return Math.log(x) * Math.LOG2E;
35
40
  }
36
41
 
37
- const log2 = Math.log2 || ieLog2;
42
+ var log2 = Math.log2 || ieLog2;
38
43
  exports.log2 = log2;
39
44
  //# sourceMappingURL=math-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math-utils.ts"],"names":["createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","ieLog2","x","Math","log","LOG2E","log2"],"mappings":";;;;;;;;;;;AAAA;;AAGO,SAASA,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;;AAGM,SAASC,eAAT,CAAyBC,MAAzB,EAAiCC,MAAjC,EAAyC;AAC9C,QAAMC,MAAM,GAAG,wBAAc,EAAd,EAAkBD,MAAlB,EAA0BD,MAA1B,CAAf;AACA,kBAAME,MAAN,EAAcA,MAAd,EAAsB,IAAIA,MAAM,CAAC,CAAD,CAAhC;AACA,SAAOA,MAAP;AACD;;AAEM,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,QAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;;AAEM,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;;AAED,SAASG,MAAT,CAAgBC,CAAhB,EAAmC;AACjC,SAAOC,IAAI,CAACC,GAAL,CAASF,CAAT,IAAcC,IAAI,CAACE,KAA1B;AACD;;AAEM,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaL,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix, vector) {\n const result = transformMat4([], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
1
+ {"version":3,"sources":["../../src/math-utils.ts"],"names":["createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","clamp","x","min","max","ieLog2","Math","log","LOG2E","log2"],"mappings":";;;;;;;;;;;;AAAA;;AAGO,SAASA,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;;AAGM,SAASC,eAAT,CAAyBC,MAAzB,EAA2CC,MAA3C,EAAuE;AAC5E,MAAMC,MAAM,GAAG,wBAAc,EAAd,EAA8BD,MAA9B,EAAsCD,MAAtC,CAAf;AACA,kBAAME,MAAN,EAAcA,MAAd,EAAsB,IAAIA,MAAM,CAAC,CAAD,CAAhC;AACA,SAAOA,MAAP;AACD;;AAEM,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,MAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;;AAEM,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;;AAEM,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAEM,IAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = transformMat4([] as number[], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
@@ -9,20 +9,18 @@ var _webMercatorUtils = require("./web-mercator-utils");
9
9
 
10
10
  var _mathUtils = require("./math-utils");
11
11
 
12
- const TILE_SIZE = 512;
12
+ var TILE_SIZE = 512;
13
13
 
14
14
  function normalizeViewportProps(props) {
15
- const {
16
- width,
17
- height,
18
- pitch = 0
19
- } = props;
20
- let {
21
- longitude,
22
- latitude,
23
- zoom,
24
- bearing = 0
25
- } = props;
15
+ var width = props.width,
16
+ height = props.height,
17
+ _props$pitch = props.pitch,
18
+ pitch = _props$pitch === void 0 ? 0 : _props$pitch;
19
+ var longitude = props.longitude,
20
+ latitude = props.latitude,
21
+ zoom = props.zoom,
22
+ _props$bearing = props.bearing,
23
+ bearing = _props$bearing === void 0 ? 0 : _props$bearing;
26
24
 
27
25
  if (longitude < -180 || longitude > 180) {
28
26
  longitude = (0, _mathUtils.mod)(longitude + 180, 360) - 180;
@@ -32,19 +30,19 @@ function normalizeViewportProps(props) {
32
30
  bearing = (0, _mathUtils.mod)(bearing + 180, 360) - 180;
33
31
  }
34
32
 
35
- const minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
33
+ var minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
36
34
 
37
35
  if (zoom <= minZoom) {
38
36
  zoom = minZoom;
39
37
  latitude = 0;
40
38
  } else {
41
- const halfHeightPixels = height / 2 / Math.pow(2, zoom);
42
- const minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
39
+ var halfHeightPixels = height / 2 / Math.pow(2, zoom);
40
+ var minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
43
41
 
44
42
  if (latitude < minLatitude) {
45
43
  latitude = minLatitude;
46
44
  } else {
47
- const maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
45
+ var maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
48
46
 
49
47
  if (latitude > maxLatitude) {
50
48
  latitude = maxLatitude;
@@ -53,13 +51,13 @@ function normalizeViewportProps(props) {
53
51
  }
54
52
 
55
53
  return {
56
- width,
57
- height,
58
- longitude,
59
- latitude,
60
- zoom,
61
- pitch,
62
- bearing
54
+ width: width,
55
+ height: height,
56
+ longitude: longitude,
57
+ latitude: latitude,
58
+ zoom: zoom,
59
+ pitch: pitch,
60
+ bearing: bearing
63
61
  };
64
62
  }
65
63
  //# sourceMappingURL=normalize-viewport-props.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude","latitude","zoom","bearing","minZoom","halfHeightPixels","Math","pow","minLatitude","maxLatitude"],"mappings":";;;;;;;AAAA;;AACA;;AAGA,MAAMA,SAAS,GAAG,GAAlB;;AAkBe,SAASC,sBAAT,CAAgCC,KAAhC,EAAqE;AAClF,QAAM;AAACC,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBC,IAAAA,KAAK,GAAG;AAAxB,MAA6BH,KAAnC;AACA,MAAI;AAACI,IAAAA,SAAD;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,IAAtB;AAA4BC,IAAAA,OAAO,GAAG;AAAtC,MAA2CP,KAA/C;;AAGA,MAAII,SAAS,GAAG,CAAC,GAAb,IAAoBA,SAAS,GAAG,GAApC,EAAyC;AACvCA,IAAAA,SAAS,GAAG,oBAAIA,SAAS,GAAG,GAAhB,EAAqB,GAArB,IAA4B,GAAxC;AACD;;AACD,MAAIG,OAAO,GAAG,CAAC,GAAX,IAAkBA,OAAO,GAAG,GAAhC,EAAqC;AACnCA,IAAAA,OAAO,GAAG,oBAAIA,OAAO,GAAG,GAAd,EAAmB,GAAnB,IAA0B,GAApC;AACD;;AAGD,QAAMC,OAAO,GAAG,qBAAKN,MAAM,GAAGJ,SAAd,CAAhB;;AACA,MAAIQ,IAAI,IAAIE,OAAZ,EAAqB;AACnBF,IAAAA,IAAI,GAAGE,OAAP;AACAH,IAAAA,QAAQ,GAAG,CAAX;AACD,GAHD,MAGO;AAEL,UAAMI,gBAAgB,GAAGP,MAAM,GAAG,CAAT,GAAaQ,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYL,IAAZ,CAAtC;AACA,UAAMM,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIH,gBAAJ,CAAd,EAAqC,CAArC,CAApB;;AACA,QAAIJ,QAAQ,GAAGO,WAAf,EAA4B;AAC1BP,MAAAA,QAAQ,GAAGO,WAAX;AACD,KAFD,MAEO;AACL,YAAMC,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIf,SAAS,GAAGW,gBAAhB,CAAd,EAAiD,CAAjD,CAApB;;AACA,UAAIJ,QAAQ,GAAGQ,WAAf,EAA4B;AAC1BR,QAAAA,QAAQ,GAAGQ,WAAX;AACD;AACF;AACF;;AAED,SAAO;AAACZ,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBE,IAAAA,SAAhB;AAA2BC,IAAAA,QAA3B;AAAqCC,IAAAA,IAArC;AAA2CH,IAAAA,KAA3C;AAAkDI,IAAAA;AAAlD,GAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport {mod, log2} from './math-utils';\n\n// defined by mapbox-gl\nconst TILE_SIZE = 512;\n\n/** Description of viewport */\ntype ViewportProps = {\n width: number;\n height: number;\n longitude: number;\n latitude: number;\n zoom: number;\n pitch?: number;\n bearing?: number;\n};\n\n/**\n * Apply mathematical constraints to viewport props\n * @param props\n */\n// eslint-disable-next-line complexity\nexport default function normalizeViewportProps(props: ViewportProps): ViewportProps {\n const {width, height, pitch = 0} = props;\n let {longitude, latitude, zoom, bearing = 0} = props;\n\n // Normalize degrees\n if (longitude < -180 || longitude > 180) {\n longitude = mod(longitude + 180, 360) - 180;\n }\n if (bearing < -180 || bearing > 180) {\n bearing = mod(bearing + 180, 360) - 180;\n }\n\n // Constrain zoom and shift center at low zoom levels\n const minZoom = log2(height / TILE_SIZE);\n if (zoom <= minZoom) {\n zoom = minZoom;\n latitude = 0;\n } else {\n // Eliminate white space above and below the map\n const halfHeightPixels = height / 2 / Math.pow(2, zoom);\n const minLatitude = worldToLngLat([0, halfHeightPixels])[1];\n if (latitude < minLatitude) {\n latitude = minLatitude;\n } else {\n const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];\n if (latitude > maxLatitude) {\n latitude = maxLatitude;\n }\n }\n }\n\n return {width, height, longitude, latitude, zoom, pitch, bearing};\n}\n"],"file":"normalize-viewport-props.js"}
1
+ {"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude","latitude","zoom","bearing","minZoom","halfHeightPixels","Math","pow","minLatitude","maxLatitude"],"mappings":";;;;;;;AAAA;;AACA;;AAGA,IAAMA,SAAS,GAAG,GAAlB;;AAkBe,SAASC,sBAAT,CAAgCC,KAAhC,EAAqE;AAClF,MAAOC,KAAP,GAAmCD,KAAnC,CAAOC,KAAP;AAAA,MAAcC,MAAd,GAAmCF,KAAnC,CAAcE,MAAd;AAAA,qBAAmCF,KAAnC,CAAsBG,KAAtB;AAAA,MAAsBA,KAAtB,6BAA8B,CAA9B;AACA,MAAKC,SAAL,GAA+CJ,KAA/C,CAAKI,SAAL;AAAA,MAAgBC,QAAhB,GAA+CL,KAA/C,CAAgBK,QAAhB;AAAA,MAA0BC,IAA1B,GAA+CN,KAA/C,CAA0BM,IAA1B;AAAA,uBAA+CN,KAA/C,CAAgCO,OAAhC;AAAA,MAAgCA,OAAhC,+BAA0C,CAA1C;;AAGA,MAAIH,SAAS,GAAG,CAAC,GAAb,IAAoBA,SAAS,GAAG,GAApC,EAAyC;AACvCA,IAAAA,SAAS,GAAG,oBAAIA,SAAS,GAAG,GAAhB,EAAqB,GAArB,IAA4B,GAAxC;AACD;;AACD,MAAIG,OAAO,GAAG,CAAC,GAAX,IAAkBA,OAAO,GAAG,GAAhC,EAAqC;AACnCA,IAAAA,OAAO,GAAG,oBAAIA,OAAO,GAAG,GAAd,EAAmB,GAAnB,IAA0B,GAApC;AACD;;AAGD,MAAMC,OAAO,GAAG,qBAAKN,MAAM,GAAGJ,SAAd,CAAhB;;AACA,MAAIQ,IAAI,IAAIE,OAAZ,EAAqB;AACnBF,IAAAA,IAAI,GAAGE,OAAP;AACAH,IAAAA,QAAQ,GAAG,CAAX;AACD,GAHD,MAGO;AAEL,QAAMI,gBAAgB,GAAGP,MAAM,GAAG,CAAT,GAAaQ,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYL,IAAZ,CAAtC;AACA,QAAMM,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIH,gBAAJ,CAAd,EAAqC,CAArC,CAApB;;AACA,QAAIJ,QAAQ,GAAGO,WAAf,EAA4B;AAC1BP,MAAAA,QAAQ,GAAGO,WAAX;AACD,KAFD,MAEO;AACL,UAAMC,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIf,SAAS,GAAGW,gBAAhB,CAAd,EAAiD,CAAjD,CAApB;;AACA,UAAIJ,QAAQ,GAAGQ,WAAf,EAA4B;AAC1BR,QAAAA,QAAQ,GAAGQ,WAAX;AACD;AACF;AACF;;AAED,SAAO;AAACZ,IAAAA,KAAK,EAALA,KAAD;AAAQC,IAAAA,MAAM,EAANA,MAAR;AAAgBE,IAAAA,SAAS,EAATA,SAAhB;AAA2BC,IAAAA,QAAQ,EAARA,QAA3B;AAAqCC,IAAAA,IAAI,EAAJA,IAArC;AAA2CH,IAAAA,KAAK,EAALA,KAA3C;AAAkDI,IAAAA,OAAO,EAAPA;AAAlD,GAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport {mod, log2} from './math-utils';\n\n// defined by mapbox-gl\nconst TILE_SIZE = 512;\n\n/** Description of viewport */\nexport type ViewportProps = {\n width: number;\n height: number;\n longitude: number;\n latitude: number;\n zoom: number;\n pitch?: number;\n bearing?: number;\n};\n\n/**\n * Apply mathematical constraints to viewport props\n * @param props\n */\n// eslint-disable-next-line complexity\nexport default function normalizeViewportProps(props: ViewportProps): ViewportProps {\n const {width, height, pitch = 0} = props;\n let {longitude, latitude, zoom, bearing = 0} = props;\n\n // Normalize degrees\n if (longitude < -180 || longitude > 180) {\n longitude = mod(longitude + 180, 360) - 180;\n }\n if (bearing < -180 || bearing > 180) {\n bearing = mod(bearing + 180, 360) - 180;\n }\n\n // Constrain zoom and shift center at low zoom levels\n const minZoom = log2(height / TILE_SIZE);\n if (zoom <= minZoom) {\n zoom = minZoom;\n latitude = 0;\n } else {\n // Eliminate white space above and below the map\n const halfHeightPixels = height / 2 / Math.pow(2, zoom);\n const minLatitude = worldToLngLat([0, halfHeightPixels])[1];\n if (latitude < minLatitude) {\n latitude = minLatitude;\n } else {\n const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];\n if (latitude > maxLatitude) {\n latitude = maxLatitude;\n }\n }\n }\n\n return {width, height, longitude, latitude, zoom, pitch, bearing};\n}\n"],"file":"normalize-viewport-props.js"}
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
@@ -19,7 +21,9 @@ exports.altitudeToFovy = altitudeToFovy;
19
21
  exports.fovyToAltitude = fovyToAltitude;
20
22
  exports.worldToPixels = worldToPixels;
21
23
  exports.pixelsToWorld = pixelsToWorld;
22
- exports.DEFAULT_ALTITUDE = void 0;
24
+ exports.DEFAULT_ALTITUDE = exports.MAX_LATITUDE = void 0;
25
+
26
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
23
27
 
24
28
  var _mathUtils = require("./math-utils");
25
29
 
@@ -31,17 +35,19 @@ var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
31
35
 
32
36
  var _assert = _interopRequireDefault(require("./assert"));
33
37
 
34
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
38
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
39
 
36
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
40
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
41
 
38
- const PI = Math.PI;
39
- const PI_4 = PI / 4;
40
- const DEGREES_TO_RADIANS = PI / 180;
41
- const RADIANS_TO_DEGREES = 180 / PI;
42
- const TILE_SIZE = 512;
43
- const EARTH_CIRCUMFERENCE = 40.03e6;
44
- const DEFAULT_ALTITUDE = 1.5;
42
+ var PI = Math.PI;
43
+ var PI_4 = PI / 4;
44
+ var DEGREES_TO_RADIANS = PI / 180;
45
+ var RADIANS_TO_DEGREES = 180 / PI;
46
+ var TILE_SIZE = 512;
47
+ var EARTH_CIRCUMFERENCE = 40.03e6;
48
+ var MAX_LATITUDE = 85.051129;
49
+ exports.MAX_LATITUDE = MAX_LATITUDE;
50
+ var DEFAULT_ALTITUDE = 1.5;
45
51
  exports.DEFAULT_ALTITUDE = DEFAULT_ALTITUDE;
46
52
 
47
53
  function zoomToScale(zoom) {
@@ -53,45 +59,48 @@ function scaleToZoom(scale) {
53
59
  }
54
60
 
55
61
  function lngLatToWorld(lngLat) {
56
- const [lng, lat] = lngLat;
62
+ var _lngLat = (0, _slicedToArray2.default)(lngLat, 2),
63
+ lng = _lngLat[0],
64
+ lat = _lngLat[1];
65
+
57
66
  (0, _assert.default)(Number.isFinite(lng));
58
67
  (0, _assert.default)(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
59
- const lambda2 = lng * DEGREES_TO_RADIANS;
60
- const phi2 = lat * DEGREES_TO_RADIANS;
61
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
62
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
68
+ var lambda2 = lng * DEGREES_TO_RADIANS;
69
+ var phi2 = lat * DEGREES_TO_RADIANS;
70
+ var x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
71
+ var y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
63
72
  return [x, y];
64
73
  }
65
74
 
66
75
  function worldToLngLat(xy) {
67
- const [x, y] = xy;
68
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
69
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
76
+ var _xy = (0, _slicedToArray2.default)(xy, 2),
77
+ x = _xy[0],
78
+ y = _xy[1];
79
+
80
+ var lambda2 = x / TILE_SIZE * (2 * PI) - PI;
81
+ var phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
70
82
  return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
71
83
  }
72
84
 
73
85
  function getMeterZoom(options) {
74
- const {
75
- latitude
76
- } = options;
86
+ var latitude = options.latitude;
77
87
  (0, _assert.default)(Number.isFinite(latitude));
78
- const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
88
+ var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
79
89
  return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
80
90
  }
81
91
 
82
92
  function getDistanceScales(options) {
83
- const {
84
- latitude,
85
- longitude,
86
- highPrecision = false
87
- } = options;
93
+ var latitude = options.latitude,
94
+ longitude = options.longitude,
95
+ _options$highPrecisio = options.highPrecision,
96
+ highPrecision = _options$highPrecisio === void 0 ? false : _options$highPrecisio;
88
97
  (0, _assert.default)(Number.isFinite(latitude) && Number.isFinite(longitude));
89
- const worldSize = TILE_SIZE;
90
- const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
91
- const unitsPerDegreeX = worldSize / 360;
92
- const unitsPerDegreeY = unitsPerDegreeX / latCosine;
93
- const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
94
- const result = {
98
+ var worldSize = TILE_SIZE;
99
+ var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
100
+ var unitsPerDegreeX = worldSize / 360;
101
+ var unitsPerDegreeY = unitsPerDegreeX / latCosine;
102
+ var altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
103
+ var result = {
95
104
  unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],
96
105
  metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],
97
106
  unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],
@@ -99,10 +108,10 @@ function getDistanceScales(options) {
99
108
  };
100
109
 
101
110
  if (highPrecision) {
102
- const latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
103
- const unitsPerDegreeY2 = unitsPerDegreeX * latCosine2 / 2;
104
- const altUnitsPerDegree2 = worldSize / EARTH_CIRCUMFERENCE * latCosine2;
105
- const altUnitsPerMeter2 = altUnitsPerDegree2 / unitsPerDegreeY * altUnitsPerMeter;
111
+ var latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
112
+ var unitsPerDegreeY2 = unitsPerDegreeX * latCosine2 / 2;
113
+ var altUnitsPerDegree2 = worldSize / EARTH_CIRCUMFERENCE * latCosine2;
114
+ var altUnitsPerMeter2 = altUnitsPerDegree2 / unitsPerDegreeY * altUnitsPerMeter;
106
115
  result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];
107
116
  result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];
108
117
  }
@@ -111,38 +120,44 @@ function getDistanceScales(options) {
111
120
  }
112
121
 
113
122
  function addMetersToLngLat(lngLatZ, xyz) {
114
- const [longitude, latitude, z0] = lngLatZ;
115
- const [x, y, z] = xyz;
116
- const {
117
- unitsPerMeter,
118
- unitsPerMeter2
119
- } = getDistanceScales({
120
- longitude,
121
- latitude,
123
+ var _lngLatZ = (0, _slicedToArray2.default)(lngLatZ, 3),
124
+ longitude = _lngLatZ[0],
125
+ latitude = _lngLatZ[1],
126
+ z0 = _lngLatZ[2];
127
+
128
+ var _xyz = (0, _slicedToArray2.default)(xyz, 3),
129
+ x = _xyz[0],
130
+ y = _xyz[1],
131
+ z = _xyz[2];
132
+
133
+ var _getDistanceScales = getDistanceScales({
134
+ longitude: longitude,
135
+ latitude: latitude,
122
136
  highPrecision: true
123
- });
124
- const worldspace = lngLatToWorld(lngLatZ);
137
+ }),
138
+ unitsPerMeter = _getDistanceScales.unitsPerMeter,
139
+ unitsPerMeter2 = _getDistanceScales.unitsPerMeter2;
140
+
141
+ var worldspace = lngLatToWorld(lngLatZ);
125
142
  worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);
126
143
  worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
127
- const newLngLat = worldToLngLat(worldspace);
128
- const newZ = (z0 || 0) + (z || 0);
144
+ var newLngLat = worldToLngLat(worldspace);
145
+ var newZ = (z0 || 0) + (z || 0);
129
146
  return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
130
147
  }
131
148
 
132
149
  function getViewMatrix(options) {
133
- const {
134
- height,
135
- pitch,
136
- bearing,
137
- altitude,
138
- scale,
139
- center = null
140
- } = options;
141
- const vm = (0, _mathUtils.createMat4)();
150
+ var height = options.height,
151
+ pitch = options.pitch,
152
+ bearing = options.bearing,
153
+ altitude = options.altitude,
154
+ scale = options.scale,
155
+ center = options.center;
156
+ var vm = (0, _mathUtils.createMat4)();
142
157
  mat4.translate(vm, vm, [0, 0, -altitude]);
143
158
  mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
144
159
  mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
145
- const relativeScale = scale / height;
160
+ var relativeScale = scale / height;
146
161
  mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
147
162
 
148
163
  if (center) {
@@ -153,44 +168,44 @@ function getViewMatrix(options) {
153
168
  }
154
169
 
155
170
  function getProjectionParameters(options) {
156
- const {
157
- width,
158
- height,
159
- altitude,
160
- pitch = 0,
161
- nearZMultiplier = 1,
162
- farZMultiplier = 1
163
- } = options;
164
- let {
165
- fovy = altitudeToFovy(DEFAULT_ALTITUDE)
166
- } = options;
171
+ var width = options.width,
172
+ height = options.height,
173
+ altitude = options.altitude,
174
+ _options$pitch = options.pitch,
175
+ pitch = _options$pitch === void 0 ? 0 : _options$pitch,
176
+ _options$nearZMultipl = options.nearZMultiplier,
177
+ nearZMultiplier = _options$nearZMultipl === void 0 ? 1 : _options$nearZMultipl,
178
+ _options$farZMultipli = options.farZMultiplier,
179
+ farZMultiplier = _options$farZMultipli === void 0 ? 1 : _options$farZMultipli;
180
+ var _options$fovy = options.fovy,
181
+ fovy = _options$fovy === void 0 ? altitudeToFovy(DEFAULT_ALTITUDE) : _options$fovy;
167
182
 
168
183
  if (altitude !== undefined) {
169
184
  fovy = altitudeToFovy(altitude);
170
185
  }
171
186
 
172
- const halfFov = 0.5 * fovy * DEGREES_TO_RADIANS;
173
- const focalDistance = fovyToAltitude(fovy);
174
- const pitchRadians = pitch * DEGREES_TO_RADIANS;
175
- const topHalfSurfaceDistance = Math.sin(halfFov) * focalDistance / Math.sin(Math.min(Math.max(Math.PI / 2 - pitchRadians - halfFov, 0.01), Math.PI - 0.01));
176
- const farZ = Math.sin(pitchRadians) * topHalfSurfaceDistance + focalDistance;
187
+ var halfFov = 0.5 * fovy * DEGREES_TO_RADIANS;
188
+ var focalDistance = fovyToAltitude(fovy);
189
+ var pitchRadians = pitch * DEGREES_TO_RADIANS;
190
+ var topHalfSurfaceDistance = Math.sin(halfFov) * focalDistance / Math.sin(Math.min(Math.max(Math.PI / 2 - pitchRadians - halfFov, 0.01), Math.PI - 0.01));
191
+ var farZ = Math.sin(pitchRadians) * topHalfSurfaceDistance + focalDistance;
177
192
  return {
178
193
  fov: 2 * halfFov,
179
194
  aspect: width / height,
180
- focalDistance,
195
+ focalDistance: focalDistance,
181
196
  near: nearZMultiplier,
182
197
  far: farZ * farZMultiplier
183
198
  };
184
199
  }
185
200
 
186
201
  function getProjectionMatrix(options) {
187
- const {
188
- fov,
189
- aspect,
190
- near,
191
- far
192
- } = getProjectionParameters(options);
193
- const projectionMatrix = mat4.perspective([], fov, aspect, near, far);
202
+ var _getProjectionParamet = getProjectionParameters(options),
203
+ fov = _getProjectionParamet.fov,
204
+ aspect = _getProjectionParamet.aspect,
205
+ near = _getProjectionParamet.near,
206
+ far = _getProjectionParamet.far;
207
+
208
+ var projectionMatrix = mat4.perspective([], fov, aspect, near, far);
194
209
  return projectionMatrix;
195
210
  }
196
211
 
@@ -203,25 +218,36 @@ function fovyToAltitude(fovy) {
203
218
  }
204
219
 
205
220
  function worldToPixels(xyz, pixelProjectionMatrix) {
206
- const [x, y, z = 0] = xyz;
221
+ var _xyz2 = (0, _slicedToArray2.default)(xyz, 3),
222
+ x = _xyz2[0],
223
+ y = _xyz2[1],
224
+ _xyz2$ = _xyz2[2],
225
+ z = _xyz2$ === void 0 ? 0 : _xyz2$;
226
+
207
227
  (0, _assert.default)(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));
208
228
  return (0, _mathUtils.transformVector)(pixelProjectionMatrix, [x, y, z, 1]);
209
229
  }
210
230
 
211
- function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {
212
- const [x, y, z] = xyz;
231
+ function pixelsToWorld(xyz, pixelUnprojectionMatrix) {
232
+ var targetZ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
233
+
234
+ var _xyz3 = (0, _slicedToArray2.default)(xyz, 3),
235
+ x = _xyz3[0],
236
+ y = _xyz3[1],
237
+ z = _xyz3[2];
238
+
213
239
  (0, _assert.default)(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');
214
240
 
215
241
  if (Number.isFinite(z)) {
216
- const coord = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, z, 1]);
242
+ var coord = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, z, 1]);
217
243
  return coord;
218
244
  }
219
245
 
220
- const coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 0, 1]);
221
- const coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 1, 1]);
222
- const z0 = coord0[2];
223
- const z1 = coord1[2];
224
- const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
246
+ var coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 0, 1]);
247
+ var coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 1, 1]);
248
+ var z0 = coord0[2];
249
+ var z1 = coord1[2];
250
+ var t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
225
251
  return vec2.lerp([], coord0, coord1, t);
226
252
  }
227
253
  //# sourceMappingURL=web-mercator-utils.js.map