@antv/l7-map 2.21.1 → 2.21.3

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 (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -5
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -42
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -6
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -41
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. package/package.json +25 -32
package/lib/util.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export interface ICancelable {
2
+ cancel: () => void;
3
+ }
4
+ export declare function wrap(n: number, min: number, max: number): number;
5
+ export declare function clamp(n: number, min: number, max: number): number;
6
+ export declare function interpolate(a: number, b: number, t: number): number;
7
+ export declare function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t: number) => number;
8
+ export declare const ease: (t: number) => number;
9
+ export declare function prefersReducedMotion(): boolean;
10
+ export declare function pick(src: {
11
+ [key: string]: any;
12
+ }, properties: string[]): {
13
+ [key: string]: any;
14
+ };
15
+ export declare const now: () => number;
16
+ export declare const raf: ((callback: FrameRequestCallback) => number) & typeof requestAnimationFrame;
17
+ export declare const cancel: ((handle: number) => void) & typeof cancelAnimationFrame;
18
+ export declare function renderframe(fn: (paintStartTimestamp: number) => void): ICancelable;
19
+ export declare function extend(dest: {
20
+ [key: string]: any;
21
+ }, ...sources: Array<Partial<{
22
+ [key: string]: any;
23
+ }>>): {
24
+ [key: string]: any;
25
+ };
package/lib/util.js CHANGED
@@ -17,13 +17,12 @@ exports.raf = void 0;
17
17
  exports.renderframe = renderframe;
18
18
  exports.wrap = wrap;
19
19
  var _unitbezier = _interopRequireDefault(require("@mapbox/unitbezier"));
20
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
21
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // @ts-ignore
23
- var reducedMotionQuery;
20
+ // @ts-ignore
21
+
22
+ let reducedMotionQuery;
24
23
  function wrap(n, min, max) {
25
- var d = max - min;
26
- var w = ((n - min) % d + d) % d + min;
24
+ const d = max - min;
25
+ const w = ((n - min) % d + d) % d + min;
27
26
  return w === min ? max : w;
28
27
  }
29
28
  function clamp(n, min, max) {
@@ -33,12 +32,12 @@ function interpolate(a, b, t) {
33
32
  return a * (1 - t) + b * t;
34
33
  }
35
34
  function bezier(p1x, p1y, p2x, p2y) {
36
- var bez = new _unitbezier.default(p1x, p1y, p2x, p2y);
37
- return function (t) {
35
+ const bez = new _unitbezier.default(p1x, p1y, p2x, p2y);
36
+ return t => {
38
37
  return bez.solve(t);
39
38
  };
40
39
  }
41
- var ease = exports.ease = bezier(0.25, 0.1, 0.25, 1);
40
+ const ease = exports.ease = bezier(0.25, 0.1, 0.25, 1);
42
41
  function prefersReducedMotion() {
43
42
  var _reducedMotionQuery;
44
43
  // Lazily initialize media query
@@ -49,32 +48,23 @@ function prefersReducedMotion() {
49
48
  return (_reducedMotionQuery = reducedMotionQuery) === null || _reducedMotionQuery === void 0 ? void 0 : _reducedMotionQuery.matches;
50
49
  }
51
50
  function pick(src, properties) {
52
- var result = {};
53
- var _iterator = _createForOfIteratorHelper(properties),
54
- _step;
55
- try {
56
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
- var name = _step.value;
58
- if (name in src) {
59
- result[name] = src[name];
60
- }
51
+ const result = {};
52
+ for (const name of properties) {
53
+ if (name in src) {
54
+ result[name] = src[name];
61
55
  }
62
- } catch (err) {
63
- _iterator.e(err);
64
- } finally {
65
- _iterator.f();
66
56
  }
67
57
  return result;
68
58
  }
69
- var now = exports.now = window.performance && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
70
- var raf = exports.raf = window.requestAnimationFrame ||
59
+ const now = exports.now = window.performance && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
60
+ const raf = exports.raf = window.requestAnimationFrame ||
71
61
  // @ts-ignore
72
62
  window.mozRequestAnimationFrame ||
73
63
  // @ts-ignore
74
64
  window.webkitRequestAnimationFrame ||
75
65
  // @ts-ignore
76
66
  window.msRequestAnimationFrame;
77
- var _cancel = exports.cancel = window.cancelAnimationFrame ||
67
+ const cancel = exports.cancel = window.cancelAnimationFrame ||
78
68
  // @ts-ignore
79
69
  window.mozCancelAnimationFrame ||
80
70
  // @ts-ignore
@@ -82,20 +72,14 @@ window.webkitCancelAnimationFrame ||
82
72
  // @ts-ignore
83
73
  window.msCancelAnimationFrame;
84
74
  function renderframe(fn) {
85
- var frame = raf(fn);
75
+ const frame = raf(fn);
86
76
  return {
87
- cancel: function cancel() {
88
- return _cancel(frame);
89
- }
77
+ cancel: () => cancel(frame)
90
78
  };
91
79
  }
92
- function extend(dest) {
93
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
94
- sources[_key - 1] = arguments[_key];
95
- }
96
- for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
97
- var src = _sources[_i];
98
- for (var k in src) {
80
+ function extend(dest, ...sources) {
81
+ for (const src of sources) {
82
+ for (const k in src) {
99
83
  if (src[k] !== undefined) {
100
84
  dest[k] = src[k];
101
85
  }
@@ -0,0 +1,12 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import type Frustum from './primitives';
3
+ export default class Aabb {
4
+ min: vec3;
5
+ max: vec3;
6
+ center: vec3;
7
+ constructor(min: vec3, max: vec3);
8
+ quadrant(index: number): Aabb;
9
+ distanceX(point: number[]): number;
10
+ distanceY(point: number[]): number;
11
+ intersects(frustum: Frustum): number;
12
+ }
package/lib/utils/Aabb.js CHANGED
@@ -5,114 +5,76 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _glMatrix = require("gl-matrix");
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
- var Aabb = exports.default = /*#__PURE__*/function () {
15
- function Aabb(min, max) {
16
- (0, _classCallCheck2.default)(this, Aabb);
10
+ class Aabb {
11
+ constructor(min, max) {
12
+ (0, _defineProperty2.default)(this, "min", void 0);
13
+ (0, _defineProperty2.default)(this, "max", void 0);
14
+ (0, _defineProperty2.default)(this, "center", void 0);
17
15
  this.min = min;
18
16
  this.max = max;
19
17
  this.center = _glMatrix.vec3.scale(new Float32Array(3), _glMatrix.vec3.add(new Float32Array(3), this.min, this.max), 0.5);
20
18
  }
21
- (0, _createClass2.default)(Aabb, [{
22
- key: "quadrant",
23
- value: function quadrant(index) {
24
- var split = [index % 2 === 0, index < 2];
25
- var qMin = _glMatrix.vec3.clone(this.min);
26
- var qMax = _glMatrix.vec3.clone(this.max);
27
- for (var axis = 0; axis < split.length; axis++) {
28
- qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
29
- qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
30
- }
31
- // Elevation is always constant, hence quadrant.max.z = this.max.z
32
- qMax[2] = this.max[2];
33
- return new Aabb(qMin, qMax);
34
- }
35
- }, {
36
- key: "distanceX",
37
- value: function distanceX(point) {
38
- var pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
39
- return pointOnAabb - point[0];
40
- }
41
- }, {
42
- key: "distanceY",
43
- value: function distanceY(point) {
44
- var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
45
- return pointOnAabb - point[1];
19
+ quadrant(index) {
20
+ const split = [index % 2 === 0, index < 2];
21
+ const qMin = _glMatrix.vec3.clone(this.min);
22
+ const qMax = _glMatrix.vec3.clone(this.max);
23
+ for (let axis = 0; axis < split.length; axis++) {
24
+ qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
25
+ qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
46
26
  }
27
+ // Elevation is always constant, hence quadrant.max.z = this.max.z
28
+ qMax[2] = this.max[2];
29
+ return new Aabb(qMin, qMax);
30
+ }
31
+ distanceX(point) {
32
+ const pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
33
+ return pointOnAabb - point[0];
34
+ }
35
+ distanceY(point) {
36
+ const pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
37
+ return pointOnAabb - point[1];
38
+ }
47
39
 
48
- // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
49
- // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
50
- }, {
51
- key: "intersects",
52
- value: function intersects(frustum) {
53
- // Execute separating axis test between two convex objects to find intersections
54
- // Each frustum plane together with 3 major axes define the separating axes
55
- // Note: test only 4 points as both min and max points have equal elevation
40
+ // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
41
+ // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
42
+ intersects(frustum) {
43
+ // Execute separating axis test between two convex objects to find intersections
44
+ // Each frustum plane together with 3 major axes define the separating axes
45
+ // Note: test only 4 points as both min and max points have equal elevation
56
46
 
57
- var aabbPoints = [[this.min[0], this.min[1], 0.0, 1], [this.max[0], this.min[1], 0.0, 1], [this.max[0], this.max[1], 0.0, 1], [this.min[0], this.max[1], 0.0, 1]];
58
- var fullyInside = true;
59
- var _iterator = _createForOfIteratorHelper(frustum.planes),
60
- _step;
61
- try {
62
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
- var plane = _step.value;
64
- var pointsInside = 0;
65
- var _iterator3 = _createForOfIteratorHelper(aabbPoints),
66
- _step3;
67
- try {
68
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
69
- var i = _step3.value;
70
- // @ts-ignore
71
- pointsInside += _glMatrix.vec4.dot(plane, i) >= 0;
72
- }
73
- } catch (err) {
74
- _iterator3.e(err);
75
- } finally {
76
- _iterator3.f();
77
- }
78
- if (pointsInside === 0) {
79
- return 0;
80
- }
81
- if (pointsInside !== aabbPoints.length) {
82
- fullyInside = false;
83
- }
84
- }
85
- } catch (err) {
86
- _iterator.e(err);
87
- } finally {
88
- _iterator.f();
47
+ const aabbPoints = [[this.min[0], this.min[1], 0.0, 1], [this.max[0], this.min[1], 0.0, 1], [this.max[0], this.max[1], 0.0, 1], [this.min[0], this.max[1], 0.0, 1]];
48
+ let fullyInside = true;
49
+ for (const plane of frustum.planes) {
50
+ let pointsInside = 0;
51
+ for (const i of aabbPoints) {
52
+ // @ts-ignore
53
+ pointsInside += _glMatrix.vec4.dot(plane, i) >= 0;
89
54
  }
90
- if (fullyInside) {
91
- return 2;
55
+ if (pointsInside === 0) {
56
+ return 0;
92
57
  }
93
- for (var axis = 0; axis < 3; axis++) {
94
- var projMin = Number.MAX_VALUE;
95
- var projMax = -Number.MAX_VALUE;
96
- var _iterator2 = _createForOfIteratorHelper(frustum.points),
97
- _step2;
98
- try {
99
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
100
- var p = _step2.value;
101
- var projectedPoint = p[axis] - this.min[axis];
102
- projMin = Math.min(projMin, projectedPoint);
103
- projMax = Math.max(projMax, projectedPoint);
104
- }
105
- } catch (err) {
106
- _iterator2.e(err);
107
- } finally {
108
- _iterator2.f();
109
- }
110
- if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
111
- return 0;
112
- }
58
+ if (pointsInside !== aabbPoints.length) {
59
+ fullyInside = false;
113
60
  }
114
- return 1;
115
61
  }
116
- }]);
117
- return Aabb;
118
- }();
62
+ if (fullyInside) {
63
+ return 2;
64
+ }
65
+ for (let axis = 0; axis < 3; axis++) {
66
+ let projMin = Number.MAX_VALUE;
67
+ let projMax = -Number.MAX_VALUE;
68
+ for (const p of frustum.points) {
69
+ const projectedPoint = p[axis] - this.min[axis];
70
+ projMin = Math.min(projMin, projectedPoint);
71
+ projMax = Math.max(projMax, projectedPoint);
72
+ }
73
+ if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
74
+ return 0;
75
+ }
76
+ }
77
+ return 1;
78
+ }
79
+ }
80
+ exports.default = Aabb;
@@ -0,0 +1,4 @@
1
+ declare const DOM: {
2
+ [key: string]: (...arg: any[]) => any;
3
+ };
4
+ export default DOM;
package/lib/utils/dom.js CHANGED
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _point = _interopRequireDefault(require("../geo/point"));
9
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // @ts-ignore
12
- var DOM = {};
9
+ // @ts-ignore
10
+
11
+ const DOM = {};
13
12
  var _default = exports.default = DOM;
14
- DOM.create = function (tagName, className, container) {
15
- var el = window.document.createElement(tagName);
13
+ DOM.create = (tagName, className, container) => {
14
+ const el = window.document.createElement(tagName);
16
15
  if (className !== undefined) {
17
16
  el.className = className;
18
17
  }
@@ -21,58 +20,49 @@ DOM.create = function (tagName, className, container) {
21
20
  }
22
21
  return el;
23
22
  };
24
- DOM.createNS = function (namespaceURI, tagName) {
25
- var el = window.document.createElementNS(namespaceURI, tagName);
23
+ DOM.createNS = (namespaceURI, tagName) => {
24
+ const el = window.document.createElementNS(namespaceURI, tagName);
26
25
  return el;
27
26
  };
28
- var docStyle = window.document && window.document.documentElement.style;
27
+ const docStyle = window.document && window.document.documentElement.style;
29
28
  function testProp(props) {
30
29
  if (!docStyle) {
31
30
  return props[0];
32
31
  }
33
- var _iterator = _createForOfIteratorHelper(props),
34
- _step;
35
- try {
36
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
- var i = _step.value;
38
- if (i in docStyle) {
39
- return i;
40
- }
32
+ for (const i of props) {
33
+ if (i in docStyle) {
34
+ return i;
41
35
  }
42
- } catch (err) {
43
- _iterator.e(err);
44
- } finally {
45
- _iterator.f();
46
36
  }
47
37
  return props[0];
48
38
  }
49
- var selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
50
- var userSelect;
51
- DOM.disableDrag = function () {
39
+ const selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
40
+ let userSelect;
41
+ DOM.disableDrag = () => {
52
42
  if (docStyle && selectProp) {
53
43
  userSelect = docStyle[selectProp];
54
44
  docStyle[selectProp] = 'none';
55
45
  }
56
46
  };
57
- DOM.enableDrag = function () {
47
+ DOM.enableDrag = () => {
58
48
  if (docStyle && selectProp) {
59
49
  docStyle[selectProp] = userSelect;
60
50
  }
61
51
  };
62
- var transformProp = testProp(['transform', 'WebkitTransform']);
63
- DOM.setTransform = function (el, value) {
52
+ const transformProp = testProp(['transform', 'WebkitTransform']);
53
+ DOM.setTransform = (el, value) => {
64
54
  // https://github.com/facebook/flow/issues/7754
65
55
  // $FlowFixMe
66
56
  el.style[transformProp] = value;
67
57
  };
68
58
 
69
59
  // Feature detection for {passive: false} support in add/removeEventListener.
70
- var passiveSupported = false;
60
+ let passiveSupported = false;
71
61
  try {
72
62
  // https://github.com/facebook/flow/issues/285
73
63
  // $FlowFixMe
74
- var options = Object.defineProperty({}, 'passive', {
75
- get: function get() {
64
+ const options = Object.defineProperty({}, 'passive', {
65
+ get() {
76
66
  // eslint-disable-line
77
67
  passiveSupported = true;
78
68
  }
@@ -84,16 +74,14 @@ try {
84
74
  } catch (err) {
85
75
  passiveSupported = false;
86
76
  }
87
- DOM.addEventListener = function (target, type, callback) {
88
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
77
+ DOM.addEventListener = (target, type, callback, options = {}) => {
89
78
  if ('passive' in options && passiveSupported) {
90
79
  target.addEventListener(type, callback, options);
91
80
  } else {
92
81
  target.addEventListener(type, callback, options.capture);
93
82
  }
94
83
  };
95
- DOM.removeEventListener = function (target, type, callback) {
96
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
84
+ DOM.removeEventListener = (target, type, callback, options = {}) => {
97
85
  if ('passive' in options && passiveSupported) {
98
86
  target.removeEventListener(type, callback, options);
99
87
  } else {
@@ -102,44 +90,35 @@ DOM.removeEventListener = function (target, type, callback) {
102
90
  };
103
91
 
104
92
  // Suppress the next click, but only if it's immediate.
105
- var suppressClick = function suppressClick(e) {
93
+ const suppressClick = e => {
106
94
  e.preventDefault();
107
95
  e.stopPropagation();
108
96
  window.removeEventListener('click', suppressClick, true);
109
97
  };
110
- DOM.suppressClick = function () {
98
+ DOM.suppressClick = () => {
111
99
  window.addEventListener('click', suppressClick, true);
112
- setTimeout(function () {
100
+ setTimeout(() => {
113
101
  window.removeEventListener('click', suppressClick, true);
114
102
  }, 0);
115
103
  };
116
- DOM.mousePos = function (el, e) {
104
+ DOM.mousePos = (el, e) => {
117
105
  // 暂时从 el 上获取 top/left, 后面需要动态获取
118
- var rect = el.getBoundingClientRect();
106
+ const rect = el.getBoundingClientRect();
119
107
  return new _point.default(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
120
108
  };
121
- DOM.touchPos = function (el, touches) {
109
+ DOM.touchPos = (el, touches) => {
122
110
  // 暂时从 el 上获取 top/left, 后面需要动态获取
123
- var rect = el.getBoundingClientRect();
124
- var points = [];
125
- var _iterator2 = _createForOfIteratorHelper(touches),
126
- _step2;
127
- try {
128
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
129
- var touche = _step2.value;
130
- points.push(new _point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
131
- }
132
- } catch (err) {
133
- _iterator2.e(err);
134
- } finally {
135
- _iterator2.f();
111
+ const rect = el.getBoundingClientRect();
112
+ const points = [];
113
+ for (const touche of touches) {
114
+ points.push(new _point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
136
115
  }
137
116
  return points;
138
117
  };
139
- DOM.mouseButton = function (e) {
118
+ DOM.mouseButton = e => {
140
119
  return e.button;
141
120
  };
142
- DOM.remove = function (node) {
121
+ DOM.remove = node => {
143
122
  if (node.parentNode) {
144
123
  node.parentNode.removeChild(node);
145
124
  }
@@ -0,0 +1,17 @@
1
+ export interface IPerformanceMetrics {
2
+ loadTime: number;
3
+ fullLoadTime: number;
4
+ fps: number;
5
+ percentDroppedFrames: number;
6
+ }
7
+ export declare const PerformanceMarkers: {
8
+ create: string;
9
+ load: string;
10
+ fullLoad: string;
11
+ };
12
+ export declare const PerformanceUtils: {
13
+ mark(marker: string): void;
14
+ frame(timestamp: number): void;
15
+ clearMetrics(): void;
16
+ getPerformanceMetrics(): IPerformanceMetrics;
17
+ };
@@ -4,65 +4,61 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PerformanceUtils = exports.PerformanceMarkers = void 0;
7
- var lastFrameTime = null;
8
- var frameTimes = [];
9
- var minFramerateTarget = 30;
10
- var frameTimeTarget = 1000 / minFramerateTarget;
11
- var performance = window.performance;
12
- var PerformanceMarkers = exports.PerformanceMarkers = {
7
+ let lastFrameTime = null;
8
+ let frameTimes = [];
9
+ const minFramerateTarget = 30;
10
+ const frameTimeTarget = 1000 / minFramerateTarget;
11
+ const performance = window.performance;
12
+ const PerformanceMarkers = exports.PerformanceMarkers = {
13
13
  create: 'create',
14
14
  load: 'load',
15
15
  fullLoad: 'fullLoad'
16
16
  };
17
- var PerformanceUtils = exports.PerformanceUtils = {
18
- mark: function mark(marker) {
17
+ const PerformanceUtils = exports.PerformanceUtils = {
18
+ mark(marker) {
19
19
  performance.mark(marker);
20
20
  },
21
- frame: function frame(timestamp) {
22
- var currTimestamp = timestamp;
21
+ frame(timestamp) {
22
+ const currTimestamp = timestamp;
23
23
  if (lastFrameTime != null) {
24
- var frameTime = currTimestamp - lastFrameTime;
24
+ const frameTime = currTimestamp - lastFrameTime;
25
25
  frameTimes.push(frameTime);
26
26
  }
27
27
  lastFrameTime = currTimestamp;
28
28
  },
29
- clearMetrics: function clearMetrics() {
29
+ clearMetrics() {
30
30
  lastFrameTime = null;
31
31
  frameTimes = [];
32
32
  performance.clearMeasures('loadTime');
33
33
  performance.clearMeasures('fullLoadTime');
34
34
  // @ts-ignore
35
35
  // tslint:disable-next-line:forin
36
- for (var marker in PerformanceMarkers) {
36
+ for (const marker in PerformanceMarkers) {
37
37
  // @ts-ignore
38
38
  performance.clearMarks(PerformanceMarkers[marker]);
39
39
  }
40
40
  },
41
- getPerformanceMetrics: function getPerformanceMetrics() {
42
- var loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load
41
+ getPerformanceMetrics() {
42
+ const loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load
43
43
  // @ts-ignore
44
44
  ).duration;
45
- var fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad
45
+ const fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad
46
46
  // @ts-ignore
47
47
  ).duration;
48
- var totalFrames = frameTimes.length;
49
- var avgFrameTime = frameTimes.reduce(function (prev, curr) {
50
- return prev + curr;
51
- }, 0) / totalFrames / 1000;
52
- var fps = 1 / avgFrameTime;
48
+ const totalFrames = frameTimes.length;
49
+ const avgFrameTime = frameTimes.reduce((prev, curr) => prev + curr, 0) / totalFrames / 1000;
50
+ const fps = 1 / avgFrameTime;
53
51
 
54
52
  // count frames that missed our framerate target
55
- var droppedFrames = frameTimes.filter(function (frameTime) {
56
- return frameTime > frameTimeTarget;
57
- }).reduce(function (acc, curr) {
53
+ const droppedFrames = frameTimes.filter(frameTime => frameTime > frameTimeTarget).reduce((acc, curr) => {
58
54
  return acc + (curr - frameTimeTarget) / frameTimeTarget;
59
55
  }, 0);
60
- var percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
56
+ const percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
61
57
  return {
62
- loadTime: loadTime,
63
- fullLoadTime: fullLoadTime,
64
- fps: fps,
65
- percentDroppedFrames: percentDroppedFrames
58
+ loadTime,
59
+ fullLoadTime,
60
+ fps,
61
+ percentDroppedFrames
66
62
  };
67
63
  }
68
64
  };
@@ -0,0 +1,6 @@
1
+ export default class Frustum {
2
+ static fromInvProjectionMatrix(invProj: Float32Array, worldSize: number, zoom: number): Frustum;
3
+ points: number[][];
4
+ planes: number[][];
5
+ constructor(points: number[][], planes: number[][]);
6
+ }