@antv/l7-map 2.9.33 → 2.9.34

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 (56) hide show
  1. package/lib/camera.js +766 -508
  2. package/lib/earthmap.js +389 -223
  3. package/lib/geo/edge_insets.js +117 -64
  4. package/lib/geo/lng_lat.js +86 -65
  5. package/lib/geo/lng_lat_bounds.js +162 -123
  6. package/lib/geo/mercator.js +91 -62
  7. package/lib/geo/point.js +234 -171
  8. package/lib/geo/simple.js +93 -61
  9. package/lib/geo/transform.js +982 -472
  10. package/lib/handler/IHandler.js +4 -16
  11. package/lib/handler/blockable_map_event.js +84 -63
  12. package/lib/handler/box_zoom.js +201 -123
  13. package/lib/handler/click_zoom.js +63 -55
  14. package/lib/handler/events/event.js +20 -35
  15. package/lib/handler/events/index.js +28 -35
  16. package/lib/handler/events/map_mouse_event.js +85 -42
  17. package/lib/handler/events/map_touch_event.js +116 -45
  18. package/lib/handler/events/map_wheel_event.js +70 -34
  19. package/lib/handler/events/render_event.js +50 -31
  20. package/lib/handler/handler_inertia.js +158 -114
  21. package/lib/handler/handler_manager.js +640 -381
  22. package/lib/handler/handler_util.js +11 -29
  23. package/lib/handler/keyboard.js +155 -114
  24. package/lib/handler/map_event.js +133 -84
  25. package/lib/handler/mouse/index.js +28 -35
  26. package/lib/handler/mouse/mouse_handler.js +126 -90
  27. package/lib/handler/mouse/mousepan_handler.js +64 -46
  28. package/lib/handler/mouse/mousepitch_hander.js +64 -44
  29. package/lib/handler/mouse/mouserotate_hander.js +64 -44
  30. package/lib/handler/mouse/util.js +22 -40
  31. package/lib/handler/scroll_zoom.js +318 -176
  32. package/lib/handler/shim/dblclick_zoom.js +76 -42
  33. package/lib/handler/shim/drag_pan.js +98 -48
  34. package/lib/handler/shim/drag_rotate.js +82 -43
  35. package/lib/handler/shim/touch_zoom_rotate.js +127 -59
  36. package/lib/handler/tap/single_tap_recognizer.js +113 -84
  37. package/lib/handler/tap/tap_drag_zoom.js +111 -93
  38. package/lib/handler/tap/tap_recognizer.js +72 -60
  39. package/lib/handler/tap/tap_zoom.js +113 -88
  40. package/lib/handler/touch/index.js +36 -38
  41. package/lib/handler/touch/touch_pan.js +126 -98
  42. package/lib/handler/touch/touch_pitch.js +108 -74
  43. package/lib/handler/touch/touch_rotate.js +93 -59
  44. package/lib/handler/touch/touch_zoom.js +71 -49
  45. package/lib/handler/touch/two_touch.js +129 -90
  46. package/lib/hash.js +149 -100
  47. package/lib/index.js +43 -20
  48. package/lib/interface.js +4 -16
  49. package/lib/map.js +420 -240
  50. package/lib/util.js +88 -69
  51. package/lib/utils/Aabb.js +134 -81
  52. package/lib/utils/dom.js +162 -88
  53. package/lib/utils/performance.js +46 -54
  54. package/lib/utils/primitives.js +53 -59
  55. package/lib/utils/task_queue.js +104 -61
  56. package/package.json +3 -3
package/lib/util.js CHANGED
@@ -1,97 +1,116 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
-
22
- // src/util.ts
23
- var util_exports = {};
24
- __export(util_exports, {
25
- bezier: () => bezier,
26
- cancel: () => cancel,
27
- clamp: () => clamp,
28
- ease: () => ease,
29
- interpolate: () => interpolate,
30
- now: () => now,
31
- pick: () => pick,
32
- prefersReducedMotion: () => prefersReducedMotion,
33
- raf: () => raf,
34
- renderframe: () => renderframe,
35
- wrap: () => wrap
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
36
7
  });
37
- module.exports = __toCommonJS(util_exports);
38
- var import_l7_utils = require("@antv/l7-utils");
39
- var import_unitbezier = __toESM(require("@mapbox/unitbezier"));
8
+ exports.bezier = bezier;
9
+ exports.cancel = void 0;
10
+ exports.clamp = clamp;
11
+ exports.ease = void 0;
12
+ exports.interpolate = interpolate;
13
+ exports.now = void 0;
14
+ exports.pick = pick;
15
+ exports.prefersReducedMotion = prefersReducedMotion;
16
+ exports.raf = void 0;
17
+ exports.renderframe = renderframe;
18
+ exports.wrap = wrap;
19
+
20
+ var _l7Utils = require("@antv/l7-utils");
21
+
22
+ var _unitbezier = _interopRequireDefault(require("@mapbox/unitbezier"));
23
+
24
+ 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; } } }; }
25
+
26
+ 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); }
27
+
28
+ 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; }
29
+
40
30
  var reducedMotionQuery;
31
+
41
32
  function wrap(n, min, max) {
42
- const d = max - min;
43
- const w = ((n - min) % d + d) % d + min;
33
+ var d = max - min;
34
+ var w = ((n - min) % d + d) % d + min;
44
35
  return w === min ? max : w;
45
36
  }
37
+
46
38
  function clamp(n, min, max) {
47
39
  return Math.min(max, Math.max(min, n));
48
40
  }
41
+
49
42
  function interpolate(a, b, t) {
50
43
  return a * (1 - t) + b * t;
51
44
  }
45
+
52
46
  function bezier(p1x, p1y, p2x, p2y) {
53
- const bez = new import_unitbezier.default(p1x, p1y, p2x, p2y);
54
- return (t) => {
47
+ var bez = new _unitbezier.default(p1x, p1y, p2x, p2y);
48
+ return function (t) {
55
49
  return bez.solve(t);
56
50
  };
57
51
  }
52
+
58
53
  var ease = bezier(0.25, 0.1, 0.25, 1);
54
+ exports.ease = ease;
55
+
59
56
  function prefersReducedMotion() {
60
- if (import_l7_utils.isMini || !import_l7_utils.$window.matchMedia) {
57
+ // @ts-ignore
58
+ if (_l7Utils.isMini || !_l7Utils.$window.matchMedia) {
61
59
  return false;
62
- }
60
+ } // Lazily initialize media query
61
+
62
+
63
63
  if (reducedMotionQuery == null) {
64
- reducedMotionQuery = import_l7_utils.$window.matchMedia("(prefers-reduced-motion: reduce)");
64
+ // @ts-ignore
65
+ reducedMotionQuery = _l7Utils.$window.matchMedia('(prefers-reduced-motion: reduce)');
65
66
  }
67
+
66
68
  return reducedMotionQuery.matches;
67
69
  }
70
+
68
71
  function pick(src, properties) {
69
- const result = {};
70
- for (const name of properties) {
71
- if (name in src) {
72
- result[name] = src[name];
72
+ var result = {};
73
+
74
+ var _iterator = _createForOfIteratorHelper(properties),
75
+ _step;
76
+
77
+ try {
78
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
79
+ var name = _step.value;
80
+
81
+ if (name in src) {
82
+ result[name] = src[name];
83
+ }
73
84
  }
85
+ } catch (err) {
86
+ _iterator.e(err);
87
+ } finally {
88
+ _iterator.f();
74
89
  }
90
+
75
91
  return result;
76
92
  }
77
- var now = import_l7_utils.isMini ? Date.now.bind(Date) : import_l7_utils.$window.performance && import_l7_utils.$window.performance.now ? import_l7_utils.$window.performance.now.bind(import_l7_utils.$window.performance) : Date.now.bind(Date);
78
- var raf = import_l7_utils.$window.requestAnimationFrame || import_l7_utils.$window.mozRequestAnimationFrame || import_l7_utils.$window.webkitRequestAnimationFrame || import_l7_utils.$window.msRequestAnimationFrame;
79
- var cancel = import_l7_utils.$window.cancelAnimationFrame || import_l7_utils.$window.mozCancelAnimationFrame || import_l7_utils.$window.webkitCancelAnimationFrame || import_l7_utils.$window.msCancelAnimationFrame;
93
+
94
+ var now = _l7Utils.isMini ? Date.now.bind(Date) : _l7Utils.$window.performance && _l7Utils.$window.performance.now ? _l7Utils.$window.performance.now.bind(_l7Utils.$window.performance) : Date.now.bind(Date);
95
+ exports.now = now;
96
+ var raf = _l7Utils.$window.requestAnimationFrame || // @ts-ignore
97
+ _l7Utils.$window.mozRequestAnimationFrame || // @ts-ignore
98
+ _l7Utils.$window.webkitRequestAnimationFrame || // @ts-ignore
99
+ _l7Utils.$window.msRequestAnimationFrame;
100
+ exports.raf = raf;
101
+
102
+ var _cancel = _l7Utils.$window.cancelAnimationFrame || // @ts-ignore
103
+ _l7Utils.$window.mozCancelAnimationFrame || // @ts-ignore
104
+ _l7Utils.$window.webkitCancelAnimationFrame || // @ts-ignore
105
+ _l7Utils.$window.msCancelAnimationFrame;
106
+
107
+ exports.cancel = _cancel;
108
+
80
109
  function renderframe(fn) {
81
- const frame = raf(fn);
82
- return { cancel: () => cancel(frame) };
83
- }
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
86
- bezier,
87
- cancel,
88
- clamp,
89
- ease,
90
- interpolate,
91
- now,
92
- pick,
93
- prefersReducedMotion,
94
- raf,
95
- renderframe,
96
- wrap
97
- });
110
+ var frame = raf(fn);
111
+ return {
112
+ cancel: function cancel() {
113
+ return _cancel(frame);
114
+ }
115
+ };
116
+ }
package/lib/utils/Aabb.js CHANGED
@@ -1,90 +1,143 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/Aabb.ts
20
- var Aabb_exports = {};
21
- __export(Aabb_exports, {
22
- default: () => Aabb
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
23
7
  });
24
- module.exports = __toCommonJS(Aabb_exports);
25
- var import_gl_matrix = require("gl-matrix");
26
- var Aabb = class {
27
- constructor(min, max) {
8
+ exports.default = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _glMatrix = require("gl-matrix");
15
+
16
+ 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; } } }; }
17
+
18
+ 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); }
19
+
20
+ 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; }
21
+
22
+ var Aabb = /*#__PURE__*/function () {
23
+ function Aabb(min, max) {
24
+ (0, _classCallCheck2.default)(this, Aabb);
28
25
  this.min = min;
29
26
  this.max = max;
30
- this.center = import_gl_matrix.vec3.scale(new Float32Array(3), import_gl_matrix.vec3.add(new Float32Array(3), this.min, this.max), 0.5);
27
+ this.center = _glMatrix.vec3.scale(new Float32Array(3), _glMatrix.vec3.add(new Float32Array(3), this.min, this.max), 0.5);
31
28
  }
32
- quadrant(index) {
33
- const split = [index % 2 === 0, index < 2];
34
- const qMin = import_gl_matrix.vec3.clone(this.min);
35
- const qMax = import_gl_matrix.vec3.clone(this.max);
36
- for (let axis = 0; axis < split.length; axis++) {
37
- qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
38
- qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
39
- }
40
- qMax[2] = this.max[2];
41
- return new Aabb(qMin, qMax);
42
- }
43
- distanceX(point) {
44
- const pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
45
- return pointOnAabb - point[0];
46
- }
47
- distanceY(point) {
48
- const pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
49
- return pointOnAabb - point[1];
50
- }
51
- intersects(frustum) {
52
- const aabbPoints = [
53
- [this.min[0], this.min[1], 0, 1],
54
- [this.max[0], this.min[1], 0, 1],
55
- [this.max[0], this.max[1], 0, 1],
56
- [this.min[0], this.max[1], 0, 1]
57
- ];
58
- let fullyInside = true;
59
- for (const plane of frustum.planes) {
60
- let pointsInside = 0;
61
- for (const i of aabbPoints) {
62
- pointsInside += import_gl_matrix.vec4.dot(plane, i) >= 0;
63
- }
64
- if (pointsInside === 0) {
65
- return 0;
66
- }
67
- if (pointsInside !== aabbPoints.length) {
68
- fullyInside = false;
69
- }
29
+
30
+ (0, _createClass2.default)(Aabb, [{
31
+ key: "quadrant",
32
+ value: function quadrant(index) {
33
+ var split = [index % 2 === 0, index < 2];
34
+
35
+ var qMin = _glMatrix.vec3.clone(this.min);
36
+
37
+ var qMax = _glMatrix.vec3.clone(this.max);
38
+
39
+ for (var axis = 0; axis < split.length; axis++) {
40
+ qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
41
+ qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
42
+ } // Elevation is always constant, hence quadrant.max.z = this.max.z
43
+
44
+
45
+ qMax[2] = this.max[2];
46
+ return new Aabb(qMin, qMax);
70
47
  }
71
- if (fullyInside) {
72
- return 2;
48
+ }, {
49
+ key: "distanceX",
50
+ value: function distanceX(point) {
51
+ var pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
52
+ return pointOnAabb - point[0];
73
53
  }
74
- for (let axis = 0; axis < 3; axis++) {
75
- let projMin = Number.MAX_VALUE;
76
- let projMax = -Number.MAX_VALUE;
77
- for (const p of frustum.points) {
78
- const projectedPoint = p[axis] - this.min[axis];
79
- projMin = Math.min(projMin, projectedPoint);
80
- projMax = Math.max(projMax, projectedPoint);
54
+ }, {
55
+ key: "distanceY",
56
+ value: function distanceY(point) {
57
+ var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
58
+ return pointOnAabb - point[1];
59
+ } // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
60
+ // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
61
+
62
+ }, {
63
+ key: "intersects",
64
+ value: function intersects(frustum) {
65
+ // Execute separating axis test between two convex objects to find intersections
66
+ // Each frustum plane together with 3 major axes define the separating axes
67
+ // Note: test only 4 points as both min and max points have equal elevation
68
+ 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]];
69
+ var fullyInside = true;
70
+
71
+ var _iterator = _createForOfIteratorHelper(frustum.planes),
72
+ _step;
73
+
74
+ try {
75
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
76
+ var plane = _step.value;
77
+ var pointsInside = 0;
78
+
79
+ var _iterator3 = _createForOfIteratorHelper(aabbPoints),
80
+ _step3;
81
+
82
+ try {
83
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
84
+ var i = _step3.value;
85
+ // @ts-ignore
86
+ pointsInside += _glMatrix.vec4.dot(plane, i) >= 0;
87
+ }
88
+ } catch (err) {
89
+ _iterator3.e(err);
90
+ } finally {
91
+ _iterator3.f();
92
+ }
93
+
94
+ if (pointsInside === 0) {
95
+ return 0;
96
+ }
97
+
98
+ if (pointsInside !== aabbPoints.length) {
99
+ fullyInside = false;
100
+ }
101
+ }
102
+ } catch (err) {
103
+ _iterator.e(err);
104
+ } finally {
105
+ _iterator.f();
81
106
  }
82
- if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
83
- return 0;
107
+
108
+ if (fullyInside) {
109
+ return 2;
84
110
  }
111
+
112
+ for (var axis = 0; axis < 3; axis++) {
113
+ var projMin = Number.MAX_VALUE;
114
+ var projMax = -Number.MAX_VALUE;
115
+
116
+ var _iterator2 = _createForOfIteratorHelper(frustum.points),
117
+ _step2;
118
+
119
+ try {
120
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
121
+ var p = _step2.value;
122
+ var projectedPoint = p[axis] - this.min[axis];
123
+ projMin = Math.min(projMin, projectedPoint);
124
+ projMax = Math.max(projMax, projectedPoint);
125
+ }
126
+ } catch (err) {
127
+ _iterator2.e(err);
128
+ } finally {
129
+ _iterator2.f();
130
+ }
131
+
132
+ if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
133
+ return 0;
134
+ }
135
+ }
136
+
137
+ return 1;
85
138
  }
86
- return 1;
87
- }
88
- };
89
- // Annotate the CommonJS export names for ESM import in node:
90
- 0 && (module.exports = {});
139
+ }]);
140
+ return Aabb;
141
+ }();
142
+
143
+ exports.default = Aabb;