@antv/l7-map 2.21.0 → 2.21.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 (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 -6
  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 -43
  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 -7
  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 -42
  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/es/util.js CHANGED
@@ -1,12 +1,9 @@
1
- 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; } } }; }
2
- 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); }
3
- 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; }
4
1
  // @ts-ignore
5
2
  import UnitBezier from '@mapbox/unitbezier';
6
- var reducedMotionQuery;
3
+ let reducedMotionQuery;
7
4
  export function wrap(n, min, max) {
8
- var d = max - min;
9
- var w = ((n - min) % d + d) % d + min;
5
+ const d = max - min;
6
+ const w = ((n - min) % d + d) % d + min;
10
7
  return w === min ? max : w;
11
8
  }
12
9
  export function clamp(n, min, max) {
@@ -16,12 +13,12 @@ export function interpolate(a, b, t) {
16
13
  return a * (1 - t) + b * t;
17
14
  }
18
15
  export function bezier(p1x, p1y, p2x, p2y) {
19
- var bez = new UnitBezier(p1x, p1y, p2x, p2y);
20
- return function (t) {
16
+ const bez = new UnitBezier(p1x, p1y, p2x, p2y);
17
+ return t => {
21
18
  return bez.solve(t);
22
19
  };
23
20
  }
24
- export var ease = bezier(0.25, 0.1, 0.25, 1);
21
+ export const ease = bezier(0.25, 0.1, 0.25, 1);
25
22
  export function prefersReducedMotion() {
26
23
  var _reducedMotionQuery;
27
24
  // Lazily initialize media query
@@ -32,54 +29,38 @@ export function prefersReducedMotion() {
32
29
  return (_reducedMotionQuery = reducedMotionQuery) === null || _reducedMotionQuery === void 0 ? void 0 : _reducedMotionQuery.matches;
33
30
  }
34
31
  export function pick(src, properties) {
35
- var result = {};
36
- var _iterator = _createForOfIteratorHelper(properties),
37
- _step;
38
- try {
39
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
- var name = _step.value;
41
- if (name in src) {
42
- result[name] = src[name];
43
- }
32
+ const result = {};
33
+ for (const name of properties) {
34
+ if (name in src) {
35
+ result[name] = src[name];
44
36
  }
45
- } catch (err) {
46
- _iterator.e(err);
47
- } finally {
48
- _iterator.f();
49
37
  }
50
38
  return result;
51
39
  }
52
- export var now = window.performance && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
53
- export var raf = window.requestAnimationFrame ||
40
+ export const now = window.performance && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
41
+ export const raf = window.requestAnimationFrame ||
54
42
  // @ts-ignore
55
43
  window.mozRequestAnimationFrame ||
56
44
  // @ts-ignore
57
45
  window.webkitRequestAnimationFrame ||
58
46
  // @ts-ignore
59
47
  window.msRequestAnimationFrame;
60
- var _cancel = window.cancelAnimationFrame ||
48
+ export const cancel = window.cancelAnimationFrame ||
61
49
  // @ts-ignore
62
50
  window.mozCancelAnimationFrame ||
63
51
  // @ts-ignore
64
52
  window.webkitCancelAnimationFrame ||
65
53
  // @ts-ignore
66
54
  window.msCancelAnimationFrame;
67
- export { _cancel as cancel };
68
55
  export function renderframe(fn) {
69
- var frame = raf(fn);
56
+ const frame = raf(fn);
70
57
  return {
71
- cancel: function cancel() {
72
- return _cancel(frame);
73
- }
58
+ cancel: () => cancel(frame)
74
59
  };
75
60
  }
76
- export function extend(dest) {
77
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
78
- sources[_key - 1] = arguments[_key];
79
- }
80
- for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
81
- var src = _sources[_i];
82
- for (var k in src) {
61
+ export function extend(dest, ...sources) {
62
+ for (const src of sources) {
63
+ for (const k in src) {
83
64
  if (src[k] !== undefined) {
84
65
  dest[k] = src[k];
85
66
  }
package/es/utils/Aabb.js CHANGED
@@ -1,112 +1,72 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- 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; } } }; }
4
- 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); }
5
- 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; }
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
2
  import { vec3, vec4 } from 'gl-matrix';
7
- var Aabb = /*#__PURE__*/function () {
8
- function Aabb(min, max) {
9
- _classCallCheck(this, Aabb);
3
+ export default class Aabb {
4
+ constructor(min, max) {
5
+ _defineProperty(this, "min", void 0);
6
+ _defineProperty(this, "max", void 0);
7
+ _defineProperty(this, "center", void 0);
10
8
  this.min = min;
11
9
  this.max = max;
12
10
  this.center = vec3.scale(new Float32Array(3), vec3.add(new Float32Array(3), this.min, this.max), 0.5);
13
11
  }
14
- _createClass(Aabb, [{
15
- key: "quadrant",
16
- value: function quadrant(index) {
17
- var split = [index % 2 === 0, index < 2];
18
- var qMin = vec3.clone(this.min);
19
- var qMax = vec3.clone(this.max);
20
- for (var axis = 0; axis < split.length; axis++) {
21
- qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
22
- qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
23
- }
24
- // Elevation is always constant, hence quadrant.max.z = this.max.z
25
- qMax[2] = this.max[2];
26
- return new Aabb(qMin, qMax);
27
- }
28
- }, {
29
- key: "distanceX",
30
- value: function distanceX(point) {
31
- var pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
32
- return pointOnAabb - point[0];
33
- }
34
- }, {
35
- key: "distanceY",
36
- value: function distanceY(point) {
37
- var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
38
- return pointOnAabb - point[1];
12
+ quadrant(index) {
13
+ const split = [index % 2 === 0, index < 2];
14
+ const qMin = vec3.clone(this.min);
15
+ const qMax = vec3.clone(this.max);
16
+ for (let axis = 0; axis < split.length; axis++) {
17
+ qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
18
+ qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
39
19
  }
20
+ // Elevation is always constant, hence quadrant.max.z = this.max.z
21
+ qMax[2] = this.max[2];
22
+ return new Aabb(qMin, qMax);
23
+ }
24
+ distanceX(point) {
25
+ const pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
26
+ return pointOnAabb - point[0];
27
+ }
28
+ distanceY(point) {
29
+ const pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
30
+ return pointOnAabb - point[1];
31
+ }
40
32
 
41
- // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
42
- // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
43
- }, {
44
- key: "intersects",
45
- value: function intersects(frustum) {
46
- // Execute separating axis test between two convex objects to find intersections
47
- // Each frustum plane together with 3 major axes define the separating axes
48
- // Note: test only 4 points as both min and max points have equal elevation
33
+ // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
34
+ // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
35
+ intersects(frustum) {
36
+ // Execute separating axis test between two convex objects to find intersections
37
+ // Each frustum plane together with 3 major axes define the separating axes
38
+ // Note: test only 4 points as both min and max points have equal elevation
49
39
 
50
- 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]];
51
- var fullyInside = true;
52
- var _iterator = _createForOfIteratorHelper(frustum.planes),
53
- _step;
54
- try {
55
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
56
- var plane = _step.value;
57
- var pointsInside = 0;
58
- var _iterator3 = _createForOfIteratorHelper(aabbPoints),
59
- _step3;
60
- try {
61
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
62
- var i = _step3.value;
63
- // @ts-ignore
64
- pointsInside += vec4.dot(plane, i) >= 0;
65
- }
66
- } catch (err) {
67
- _iterator3.e(err);
68
- } finally {
69
- _iterator3.f();
70
- }
71
- if (pointsInside === 0) {
72
- return 0;
73
- }
74
- if (pointsInside !== aabbPoints.length) {
75
- fullyInside = false;
76
- }
77
- }
78
- } catch (err) {
79
- _iterator.e(err);
80
- } finally {
81
- _iterator.f();
40
+ 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]];
41
+ let fullyInside = true;
42
+ for (const plane of frustum.planes) {
43
+ let pointsInside = 0;
44
+ for (const i of aabbPoints) {
45
+ // @ts-ignore
46
+ pointsInside += vec4.dot(plane, i) >= 0;
82
47
  }
83
- if (fullyInside) {
84
- return 2;
48
+ if (pointsInside === 0) {
49
+ return 0;
85
50
  }
86
- for (var axis = 0; axis < 3; axis++) {
87
- var projMin = Number.MAX_VALUE;
88
- var projMax = -Number.MAX_VALUE;
89
- var _iterator2 = _createForOfIteratorHelper(frustum.points),
90
- _step2;
91
- try {
92
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
93
- var p = _step2.value;
94
- var projectedPoint = p[axis] - this.min[axis];
95
- projMin = Math.min(projMin, projectedPoint);
96
- projMax = Math.max(projMax, projectedPoint);
97
- }
98
- } catch (err) {
99
- _iterator2.e(err);
100
- } finally {
101
- _iterator2.f();
102
- }
103
- if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
104
- return 0;
105
- }
51
+ if (pointsInside !== aabbPoints.length) {
52
+ fullyInside = false;
106
53
  }
107
- return 1;
108
54
  }
109
- }]);
110
- return Aabb;
111
- }();
112
- export { Aabb as default };
55
+ if (fullyInside) {
56
+ return 2;
57
+ }
58
+ for (let axis = 0; axis < 3; axis++) {
59
+ let projMin = Number.MAX_VALUE;
60
+ let projMax = -Number.MAX_VALUE;
61
+ for (const p of frustum.points) {
62
+ const projectedPoint = p[axis] - this.min[axis];
63
+ projMin = Math.min(projMin, projectedPoint);
64
+ projMax = Math.max(projMax, projectedPoint);
65
+ }
66
+ if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
67
+ return 0;
68
+ }
69
+ }
70
+ return 1;
71
+ }
72
+ }
package/es/utils/dom.js CHANGED
@@ -1,12 +1,9 @@
1
- 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; } } }; }
2
- 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); }
3
- 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; }
4
1
  // @ts-ignore
5
2
  import Point from "../geo/point";
6
- var DOM = {};
3
+ const DOM = {};
7
4
  export default DOM;
8
- DOM.create = function (tagName, className, container) {
9
- var el = window.document.createElement(tagName);
5
+ DOM.create = (tagName, className, container) => {
6
+ const el = window.document.createElement(tagName);
10
7
  if (className !== undefined) {
11
8
  el.className = className;
12
9
  }
@@ -15,58 +12,49 @@ DOM.create = function (tagName, className, container) {
15
12
  }
16
13
  return el;
17
14
  };
18
- DOM.createNS = function (namespaceURI, tagName) {
19
- var el = window.document.createElementNS(namespaceURI, tagName);
15
+ DOM.createNS = (namespaceURI, tagName) => {
16
+ const el = window.document.createElementNS(namespaceURI, tagName);
20
17
  return el;
21
18
  };
22
- var docStyle = window.document && window.document.documentElement.style;
19
+ const docStyle = window.document && window.document.documentElement.style;
23
20
  function testProp(props) {
24
21
  if (!docStyle) {
25
22
  return props[0];
26
23
  }
27
- var _iterator = _createForOfIteratorHelper(props),
28
- _step;
29
- try {
30
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
31
- var i = _step.value;
32
- if (i in docStyle) {
33
- return i;
34
- }
24
+ for (const i of props) {
25
+ if (i in docStyle) {
26
+ return i;
35
27
  }
36
- } catch (err) {
37
- _iterator.e(err);
38
- } finally {
39
- _iterator.f();
40
28
  }
41
29
  return props[0];
42
30
  }
43
- var selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
44
- var userSelect;
45
- DOM.disableDrag = function () {
31
+ const selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
32
+ let userSelect;
33
+ DOM.disableDrag = () => {
46
34
  if (docStyle && selectProp) {
47
35
  userSelect = docStyle[selectProp];
48
36
  docStyle[selectProp] = 'none';
49
37
  }
50
38
  };
51
- DOM.enableDrag = function () {
39
+ DOM.enableDrag = () => {
52
40
  if (docStyle && selectProp) {
53
41
  docStyle[selectProp] = userSelect;
54
42
  }
55
43
  };
56
- var transformProp = testProp(['transform', 'WebkitTransform']);
57
- DOM.setTransform = function (el, value) {
44
+ const transformProp = testProp(['transform', 'WebkitTransform']);
45
+ DOM.setTransform = (el, value) => {
58
46
  // https://github.com/facebook/flow/issues/7754
59
47
  // $FlowFixMe
60
48
  el.style[transformProp] = value;
61
49
  };
62
50
 
63
51
  // Feature detection for {passive: false} support in add/removeEventListener.
64
- var passiveSupported = false;
52
+ let passiveSupported = false;
65
53
  try {
66
54
  // https://github.com/facebook/flow/issues/285
67
55
  // $FlowFixMe
68
- var options = Object.defineProperty({}, 'passive', {
69
- get: function get() {
56
+ const options = Object.defineProperty({}, 'passive', {
57
+ get() {
70
58
  // eslint-disable-line
71
59
  passiveSupported = true;
72
60
  }
@@ -78,16 +66,14 @@ try {
78
66
  } catch (err) {
79
67
  passiveSupported = false;
80
68
  }
81
- DOM.addEventListener = function (target, type, callback) {
82
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
69
+ DOM.addEventListener = (target, type, callback, options = {}) => {
83
70
  if ('passive' in options && passiveSupported) {
84
71
  target.addEventListener(type, callback, options);
85
72
  } else {
86
73
  target.addEventListener(type, callback, options.capture);
87
74
  }
88
75
  };
89
- DOM.removeEventListener = function (target, type, callback) {
90
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
76
+ DOM.removeEventListener = (target, type, callback, options = {}) => {
91
77
  if ('passive' in options && passiveSupported) {
92
78
  target.removeEventListener(type, callback, options);
93
79
  } else {
@@ -96,44 +82,35 @@ DOM.removeEventListener = function (target, type, callback) {
96
82
  };
97
83
 
98
84
  // Suppress the next click, but only if it's immediate.
99
- var suppressClick = function suppressClick(e) {
85
+ const suppressClick = e => {
100
86
  e.preventDefault();
101
87
  e.stopPropagation();
102
88
  window.removeEventListener('click', suppressClick, true);
103
89
  };
104
- DOM.suppressClick = function () {
90
+ DOM.suppressClick = () => {
105
91
  window.addEventListener('click', suppressClick, true);
106
- setTimeout(function () {
92
+ setTimeout(() => {
107
93
  window.removeEventListener('click', suppressClick, true);
108
94
  }, 0);
109
95
  };
110
- DOM.mousePos = function (el, e) {
96
+ DOM.mousePos = (el, e) => {
111
97
  // 暂时从 el 上获取 top/left, 后面需要动态获取
112
- var rect = el.getBoundingClientRect();
98
+ const rect = el.getBoundingClientRect();
113
99
  return new Point(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
114
100
  };
115
- DOM.touchPos = function (el, touches) {
101
+ DOM.touchPos = (el, touches) => {
116
102
  // 暂时从 el 上获取 top/left, 后面需要动态获取
117
- var rect = el.getBoundingClientRect();
118
- var points = [];
119
- var _iterator2 = _createForOfIteratorHelper(touches),
120
- _step2;
121
- try {
122
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
123
- var touche = _step2.value;
124
- points.push(new Point(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
125
- }
126
- } catch (err) {
127
- _iterator2.e(err);
128
- } finally {
129
- _iterator2.f();
103
+ const rect = el.getBoundingClientRect();
104
+ const points = [];
105
+ for (const touche of touches) {
106
+ points.push(new Point(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
130
107
  }
131
108
  return points;
132
109
  };
133
- DOM.mouseButton = function (e) {
110
+ DOM.mouseButton = e => {
134
111
  return e.button;
135
112
  };
136
- DOM.remove = function (node) {
113
+ DOM.remove = node => {
137
114
  if (node.parentNode) {
138
115
  node.parentNode.removeChild(node);
139
116
  }
@@ -1,62 +1,58 @@
1
- var lastFrameTime = null;
2
- var frameTimes = [];
3
- var minFramerateTarget = 30;
4
- var frameTimeTarget = 1000 / minFramerateTarget;
5
- var performance = window.performance;
6
- export var PerformanceMarkers = {
1
+ let lastFrameTime = null;
2
+ let frameTimes = [];
3
+ const minFramerateTarget = 30;
4
+ const frameTimeTarget = 1000 / minFramerateTarget;
5
+ const performance = window.performance;
6
+ export const PerformanceMarkers = {
7
7
  create: 'create',
8
8
  load: 'load',
9
9
  fullLoad: 'fullLoad'
10
10
  };
11
- export var PerformanceUtils = {
12
- mark: function mark(marker) {
11
+ export const PerformanceUtils = {
12
+ mark(marker) {
13
13
  performance.mark(marker);
14
14
  },
15
- frame: function frame(timestamp) {
16
- var currTimestamp = timestamp;
15
+ frame(timestamp) {
16
+ const currTimestamp = timestamp;
17
17
  if (lastFrameTime != null) {
18
- var frameTime = currTimestamp - lastFrameTime;
18
+ const frameTime = currTimestamp - lastFrameTime;
19
19
  frameTimes.push(frameTime);
20
20
  }
21
21
  lastFrameTime = currTimestamp;
22
22
  },
23
- clearMetrics: function clearMetrics() {
23
+ clearMetrics() {
24
24
  lastFrameTime = null;
25
25
  frameTimes = [];
26
26
  performance.clearMeasures('loadTime');
27
27
  performance.clearMeasures('fullLoadTime');
28
28
  // @ts-ignore
29
29
  // tslint:disable-next-line:forin
30
- for (var marker in PerformanceMarkers) {
30
+ for (const marker in PerformanceMarkers) {
31
31
  // @ts-ignore
32
32
  performance.clearMarks(PerformanceMarkers[marker]);
33
33
  }
34
34
  },
35
- getPerformanceMetrics: function getPerformanceMetrics() {
36
- var loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load
35
+ getPerformanceMetrics() {
36
+ const loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load
37
37
  // @ts-ignore
38
38
  ).duration;
39
- var fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad
39
+ const fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad
40
40
  // @ts-ignore
41
41
  ).duration;
42
- var totalFrames = frameTimes.length;
43
- var avgFrameTime = frameTimes.reduce(function (prev, curr) {
44
- return prev + curr;
45
- }, 0) / totalFrames / 1000;
46
- var fps = 1 / avgFrameTime;
42
+ const totalFrames = frameTimes.length;
43
+ const avgFrameTime = frameTimes.reduce((prev, curr) => prev + curr, 0) / totalFrames / 1000;
44
+ const fps = 1 / avgFrameTime;
47
45
 
48
46
  // count frames that missed our framerate target
49
- var droppedFrames = frameTimes.filter(function (frameTime) {
50
- return frameTime > frameTimeTarget;
51
- }).reduce(function (acc, curr) {
47
+ const droppedFrames = frameTimes.filter(frameTime => frameTime > frameTimeTarget).reduce((acc, curr) => {
52
48
  return acc + (curr - frameTimeTarget) / frameTimeTarget;
53
49
  }, 0);
54
- var percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
50
+ const percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
55
51
  return {
56
- loadTime: loadTime,
57
- fullLoadTime: fullLoadTime,
58
- fps: fps,
59
- percentDroppedFrames: percentDroppedFrames
52
+ loadTime,
53
+ fullLoadTime,
54
+ fps,
55
+ percentDroppedFrames
60
56
  };
61
57
  }
62
58
  };
@@ -1,47 +1,37 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
2
  import { vec3, vec4 } from 'gl-matrix';
4
- var Frustum = /*#__PURE__*/function () {
5
- function Frustum(points, planes) {
6
- _classCallCheck(this, Frustum);
3
+ export default class Frustum {
4
+ static fromInvProjectionMatrix(invProj, worldSize, zoom) {
5
+ const clipSpaceCorners = [[-1, 1, -1, 1], [1, 1, -1, 1], [1, -1, -1, 1], [-1, -1, -1, 1], [-1, 1, 1, 1], [1, 1, 1, 1], [1, -1, 1, 1], [-1, -1, 1, 1]];
6
+ const scale = Math.pow(2, zoom);
7
+
8
+ // Transform frustum corner points from clip space to tile space
9
+ const frustumCoords = clipSpaceCorners.map(v => vec4.transformMat4(new Float32Array([]), v, invProj)).map(v => vec4.scale(new Float32Array([]), v, 1.0 / v[3] / worldSize * scale));
10
+ const frustumPlanePointIndices = [[0, 1, 2],
11
+ // near
12
+ [6, 5, 4],
13
+ // far
14
+ [0, 3, 7],
15
+ // left
16
+ [2, 1, 5],
17
+ // right
18
+ [3, 2, 6],
19
+ // bottom
20
+ [0, 4, 5] // top
21
+ ];
22
+ const frustumPlanes = frustumPlanePointIndices.map(p => {
23
+ const a = vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[0]]), new Float32Array(frustumCoords[p[1]]));
24
+ const b = vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[2]]), new Float32Array(frustumCoords[p[1]]));
25
+ const n = vec3.normalize(new Float32Array(3), vec3.cross(new Float32Array(3), a, b));
26
+ const d = -vec3.dot(n, new Float32Array(frustumCoords[p[1]]));
27
+ return n.concat(d);
28
+ });
29
+ return new Frustum(frustumCoords, frustumPlanes);
30
+ }
31
+ constructor(points, planes) {
32
+ _defineProperty(this, "points", void 0);
33
+ _defineProperty(this, "planes", void 0);
7
34
  this.points = points;
8
35
  this.planes = planes;
9
36
  }
10
- _createClass(Frustum, null, [{
11
- key: "fromInvProjectionMatrix",
12
- value: function fromInvProjectionMatrix(invProj, worldSize, zoom) {
13
- var clipSpaceCorners = [[-1, 1, -1, 1], [1, 1, -1, 1], [1, -1, -1, 1], [-1, -1, -1, 1], [-1, 1, 1, 1], [1, 1, 1, 1], [1, -1, 1, 1], [-1, -1, 1, 1]];
14
- var scale = Math.pow(2, zoom);
15
-
16
- // Transform frustum corner points from clip space to tile space
17
- var frustumCoords = clipSpaceCorners.map(function (v) {
18
- return vec4.transformMat4(new Float32Array([]), v, invProj);
19
- }).map(function (v) {
20
- return vec4.scale(new Float32Array([]), v, 1.0 / v[3] / worldSize * scale);
21
- });
22
- var frustumPlanePointIndices = [[0, 1, 2],
23
- // near
24
- [6, 5, 4],
25
- // far
26
- [0, 3, 7],
27
- // left
28
- [2, 1, 5],
29
- // right
30
- [3, 2, 6],
31
- // bottom
32
- [0, 4, 5] // top
33
- ];
34
-
35
- var frustumPlanes = frustumPlanePointIndices.map(function (p) {
36
- var a = vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[0]]), new Float32Array(frustumCoords[p[1]]));
37
- var b = vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[2]]), new Float32Array(frustumCoords[p[1]]));
38
- var n = vec3.normalize(new Float32Array(3), vec3.cross(new Float32Array(3), a, b));
39
- var d = -vec3.dot(n, new Float32Array(frustumCoords[p[1]]));
40
- return n.concat(d);
41
- });
42
- return new Frustum(frustumCoords, frustumPlanes);
43
- }
44
- }]);
45
- return Frustum;
46
- }();
47
- export { Frustum as default };
37
+ }