@antv/l7-map 2.9.32 → 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/utils/dom.js CHANGED
@@ -1,159 +1,233 @@
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);
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
21
4
 
22
- // src/utils/dom.ts
23
- var dom_exports = {};
24
- __export(dom_exports, {
25
- default: () => dom_default
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
26
7
  });
27
- module.exports = __toCommonJS(dom_exports);
28
- var import_l7_utils = require("@antv/l7-utils");
29
- var import_point = __toESM(require("../geo/point"));
8
+ exports.default = void 0;
9
+
10
+ var _l7Utils = require("@antv/l7-utils");
11
+
12
+ var _point = _interopRequireDefault(require("../geo/point"));
13
+
14
+ 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; } } }; }
15
+
16
+ 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); }
17
+
18
+ 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; }
19
+
30
20
  var DOM = {};
31
- var dom_default = DOM;
32
- DOM.create = (tagName, className, container) => {
33
- const el = import_l7_utils.$window.document.createElement(tagName);
34
- if (className !== void 0) {
21
+ var _default = DOM;
22
+ exports.default = _default;
23
+
24
+ DOM.create = function (tagName, className, container) {
25
+ var el = _l7Utils.$window.document.createElement(tagName);
26
+
27
+ if (className !== undefined) {
35
28
  el.className = className;
36
29
  }
30
+
37
31
  if (container) {
38
32
  container.appendChild(el);
39
33
  }
34
+
40
35
  return el;
41
36
  };
42
- DOM.createNS = (namespaceURI, tagName) => {
43
- const el = import_l7_utils.$window.document.createElementNS(namespaceURI, tagName);
37
+
38
+ DOM.createNS = function (namespaceURI, tagName) {
39
+ var el = _l7Utils.$window.document.createElementNS(namespaceURI, tagName);
40
+
44
41
  return el;
45
42
  };
46
- var docStyle = import_l7_utils.$window.document && import_l7_utils.$window.document.documentElement.style;
43
+
44
+ var docStyle = _l7Utils.$window.document && _l7Utils.$window.document.documentElement.style;
45
+
47
46
  function testProp(props) {
48
47
  if (!docStyle) {
49
48
  return props[0];
50
49
  }
51
- for (const i of props) {
52
- if (i in docStyle) {
53
- return i;
50
+
51
+ var _iterator = _createForOfIteratorHelper(props),
52
+ _step;
53
+
54
+ try {
55
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
56
+ var i = _step.value;
57
+
58
+ if (i in docStyle) {
59
+ return i;
60
+ }
54
61
  }
62
+ } catch (err) {
63
+ _iterator.e(err);
64
+ } finally {
65
+ _iterator.f();
55
66
  }
67
+
56
68
  return props[0];
57
69
  }
58
- var selectProp = testProp([
59
- "userSelect",
60
- "MozUserSelect",
61
- "WebkitUserSelect",
62
- "msUserSelect"
63
- ]);
70
+
71
+ var selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
64
72
  var userSelect;
65
- DOM.disableDrag = () => {
73
+
74
+ DOM.disableDrag = function () {
66
75
  if (docStyle && selectProp) {
67
76
  userSelect = docStyle[selectProp];
68
- docStyle[selectProp] = "none";
77
+ docStyle[selectProp] = 'none';
69
78
  }
70
79
  };
71
- DOM.enableDrag = () => {
80
+
81
+ DOM.enableDrag = function () {
72
82
  if (docStyle && selectProp) {
73
83
  docStyle[selectProp] = userSelect;
74
84
  }
75
85
  };
76
- var transformProp = testProp(["transform", "WebkitTransform"]);
77
- DOM.setTransform = (el, value) => {
86
+
87
+ var transformProp = testProp(['transform', 'WebkitTransform']);
88
+
89
+ DOM.setTransform = function (el, value) {
90
+ // https://github.com/facebook/flow/issues/7754
91
+ // $FlowFixMe
78
92
  el.style[transformProp] = value;
79
- };
93
+ }; // Feature detection for {passive: false} support in add/removeEventListener.
94
+
95
+
80
96
  var passiveSupported = false;
97
+
81
98
  try {
82
- const options = Object.defineProperty({}, "passive", {
83
- get() {
99
+ // https://github.com/facebook/flow/issues/285
100
+ // $FlowFixMe
101
+ var options = Object.defineProperty({}, 'passive', {
102
+ get: function get() {
103
+ // eslint-disable-line
84
104
  passiveSupported = true;
85
105
  }
86
- });
87
- import_l7_utils.$window.addEventListener("test", options, options);
88
- import_l7_utils.$window.removeEventListener("test", options, options);
106
+ }); // @ts-ignore
107
+
108
+ _l7Utils.$window.addEventListener('test', options, options); // @ts-ignore
109
+
110
+
111
+ _l7Utils.$window.removeEventListener('test', options, options);
89
112
  } catch (err) {
90
113
  passiveSupported = false;
91
114
  }
92
- DOM.addEventListener = (target, type, callback, options = {}) => {
93
- if ("passive" in options && passiveSupported) {
115
+
116
+ DOM.addEventListener = function (target, type, callback) {
117
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
118
+
119
+ if ('passive' in options && passiveSupported) {
94
120
  target.addEventListener(type, callback, options);
95
121
  } else {
96
122
  target.addEventListener(type, callback, options.capture);
97
123
  }
98
124
  };
99
- DOM.removeEventListener = (target, type, callback, options = {}) => {
100
- if ("passive" in options && passiveSupported) {
125
+
126
+ DOM.removeEventListener = function (target, type, callback) {
127
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
128
+
129
+ if ('passive' in options && passiveSupported) {
101
130
  target.removeEventListener(type, callback, options);
102
131
  } else {
103
132
  target.removeEventListener(type, callback, options.capture);
104
133
  }
105
- };
106
- var suppressClick = (e) => {
134
+ }; // Suppress the next click, but only if it's immediate.
135
+
136
+
137
+ var suppressClick = function suppressClick(e) {
107
138
  e.preventDefault();
108
139
  e.stopPropagation();
109
- import_l7_utils.$window.removeEventListener("click", suppressClick, true);
140
+
141
+ _l7Utils.$window.removeEventListener('click', suppressClick, true);
110
142
  };
111
- DOM.suppressClick = () => {
112
- if (import_l7_utils.isMini) {
143
+
144
+ DOM.suppressClick = function () {
145
+ if (_l7Utils.isMini) {
113
146
  return;
114
147
  }
115
- import_l7_utils.$window.addEventListener("click", suppressClick, true);
116
- setTimeout(() => {
117
- import_l7_utils.$window.removeEventListener("click", suppressClick, true);
148
+
149
+ _l7Utils.$window.addEventListener('click', suppressClick, true);
150
+
151
+ setTimeout(function () {
152
+ _l7Utils.$window.removeEventListener('click', suppressClick, true);
118
153
  }, 0);
119
154
  };
120
- DOM.mousePos = (el, e) => {
121
- if (!import_l7_utils.isMini) {
122
- const rect = el.getBoundingClientRect();
123
- return new import_point.default(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
155
+
156
+ DOM.mousePos = function (el, e) {
157
+ // 暂时从 el 上获取 top/left, 后面需要动态获取
158
+ if (!_l7Utils.isMini) {
159
+ var rect = el.getBoundingClientRect();
160
+ return new _point.default(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
124
161
  } else {
125
- return new import_point.default(e.clientX - el.left - 0, e.clientY - el.top - 0);
162
+ return new _point.default( // @ts-ignore
163
+ e.clientX - el.left - 0, // @ts-ignore
164
+ e.clientY - el.top - 0);
126
165
  }
127
166
  };
128
- DOM.touchPos = (el, touches) => {
129
- if (!import_l7_utils.isMini) {
130
- const rect = el.getBoundingClientRect();
131
- const points = [];
132
- for (const touche of touches) {
133
- points.push(new import_point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
167
+
168
+ DOM.touchPos = function (el, touches) {
169
+ // 暂时从 el 上获取 top/left, 后面需要动态获取
170
+ if (!_l7Utils.isMini) {
171
+ var rect = el.getBoundingClientRect();
172
+ var points = [];
173
+
174
+ var _iterator2 = _createForOfIteratorHelper(touches),
175
+ _step2;
176
+
177
+ try {
178
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
179
+ var touche = _step2.value;
180
+ points.push(new _point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
181
+ }
182
+ } catch (err) {
183
+ _iterator2.e(err);
184
+ } finally {
185
+ _iterator2.f();
134
186
  }
187
+
135
188
  return points;
136
189
  } else {
137
- const points = [];
138
- for (const touche of touches) {
139
- points.push(new import_point.default(touche.clientX - el.left, touche.clientY - el.top));
190
+ var _points = [];
191
+
192
+ var _iterator3 = _createForOfIteratorHelper(touches),
193
+ _step3;
194
+
195
+ try {
196
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
197
+ var _touche = _step3.value;
198
+
199
+ _points.push(new _point.default( // @ts-ignore
200
+ _touche.clientX - el.left, // @ts-ignore
201
+ _touche.clientY - el.top));
202
+ }
203
+ } catch (err) {
204
+ _iterator3.e(err);
205
+ } finally {
206
+ _iterator3.f();
140
207
  }
141
- return points;
208
+
209
+ return _points;
142
210
  }
143
211
  };
144
- DOM.mouseButton = (e) => {
145
- if (!import_l7_utils.isMini) {
212
+
213
+ DOM.mouseButton = function (e) {
214
+ if (!_l7Utils.isMini) {
146
215
  return e.button;
147
216
  }
148
- if (typeof import_l7_utils.$window.InstallTrigger !== "undefined" && e.button === 2 && e.ctrlKey && import_l7_utils.$window.navigator.platform.toUpperCase().indexOf("MAC") >= 0) {
217
+
218
+ if ( // @ts-ignore
219
+ typeof _l7Utils.$window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey && _l7Utils.$window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
220
+ // Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
221
+ // Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
222
+ // using Control + left click
149
223
  return 0;
150
224
  }
225
+
151
226
  return e.button;
152
227
  };
153
- DOM.remove = (node) => {
228
+
229
+ DOM.remove = function (node) {
154
230
  if (node.parentNode) {
155
231
  node.parentNode.removeChild(node);
156
232
  }
157
- };
158
- // Annotate the CommonJS export names for ESM import in node:
159
- 0 && (module.exports = {});
233
+ };
@@ -1,80 +1,72 @@
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);
1
+ "use strict";
18
2
 
19
- // src/utils/performance.ts
20
- var performance_exports = {};
21
- __export(performance_exports, {
22
- PerformanceMarkers: () => PerformanceMarkers,
23
- PerformanceUtils: () => PerformanceUtils
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
24
5
  });
25
- module.exports = __toCommonJS(performance_exports);
26
- var import_l7_utils = require("@antv/l7-utils");
6
+ exports.PerformanceUtils = exports.PerformanceMarkers = void 0;
7
+
8
+ var _l7Utils = require("@antv/l7-utils");
9
+
27
10
  var lastFrameTime = null;
28
11
  var frameTimes = [];
29
12
  var minFramerateTarget = 30;
30
- var frameTimeTarget = 1e3 / minFramerateTarget;
31
- var performance = import_l7_utils.$window.performance;
13
+ var frameTimeTarget = 1000 / minFramerateTarget;
14
+ var performance = _l7Utils.$window.performance;
32
15
  var PerformanceMarkers = {
33
- create: "create",
34
- load: "load",
35
- fullLoad: "fullLoad"
16
+ create: 'create',
17
+ load: 'load',
18
+ fullLoad: 'fullLoad'
36
19
  };
20
+ exports.PerformanceMarkers = PerformanceMarkers;
37
21
  var PerformanceUtils = {
38
- mark(marker) {
22
+ mark: function mark(marker) {
39
23
  performance.mark(marker);
40
24
  },
41
- frame(timestamp) {
42
- const currTimestamp = timestamp;
25
+ frame: function frame(timestamp) {
26
+ var currTimestamp = timestamp;
27
+
43
28
  if (lastFrameTime != null) {
44
- const frameTime = currTimestamp - lastFrameTime;
29
+ var frameTime = currTimestamp - lastFrameTime;
45
30
  frameTimes.push(frameTime);
46
31
  }
32
+
47
33
  lastFrameTime = currTimestamp;
48
34
  },
49
- clearMetrics() {
35
+ clearMetrics: function clearMetrics() {
50
36
  lastFrameTime = null;
51
37
  frameTimes = [];
52
- performance.clearMeasures("loadTime");
53
- performance.clearMeasures("fullLoadTime");
54
- for (const marker in PerformanceMarkers) {
38
+ performance.clearMeasures('loadTime');
39
+ performance.clearMeasures('fullLoadTime'); // @ts-ignore
40
+ // tslint:disable-next-line:forin
41
+
42
+ for (var marker in PerformanceMarkers) {
43
+ // @ts-ignore
55
44
  performance.clearMarks(PerformanceMarkers[marker]);
56
45
  }
57
46
  },
58
- getPerformanceMetrics() {
59
- const loadTime = performance.measure("loadTime", PerformanceMarkers.create, PerformanceMarkers.load).duration;
60
- const fullLoadTime = performance.measure("fullLoadTime", PerformanceMarkers.create, PerformanceMarkers.fullLoad).duration;
61
- const totalFrames = frameTimes.length;
62
- const avgFrameTime = frameTimes.reduce((prev, curr) => prev + curr, 0) / totalFrames / 1e3;
63
- const fps = 1 / avgFrameTime;
64
- const droppedFrames = frameTimes.filter((frameTime) => frameTime > frameTimeTarget).reduce((acc, curr) => {
47
+ getPerformanceMetrics: function getPerformanceMetrics() {
48
+ var loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load // @ts-ignore
49
+ ).duration;
50
+ var fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad // @ts-ignore
51
+ ).duration;
52
+ var totalFrames = frameTimes.length;
53
+ var avgFrameTime = frameTimes.reduce(function (prev, curr) {
54
+ return prev + curr;
55
+ }, 0) / totalFrames / 1000;
56
+ var fps = 1 / avgFrameTime; // count frames that missed our framerate target
57
+
58
+ var droppedFrames = frameTimes.filter(function (frameTime) {
59
+ return frameTime > frameTimeTarget;
60
+ }).reduce(function (acc, curr) {
65
61
  return acc + (curr - frameTimeTarget) / frameTimeTarget;
66
62
  }, 0);
67
- const percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
63
+ var percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
68
64
  return {
69
- loadTime,
70
- fullLoadTime,
71
- fps,
72
- percentDroppedFrames
65
+ loadTime: loadTime,
66
+ fullLoadTime: fullLoadTime,
67
+ fps: fps,
68
+ percentDroppedFrames: percentDroppedFrames
73
69
  };
74
70
  }
75
71
  };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- PerformanceMarkers,
79
- PerformanceUtils
80
- });
72
+ exports.PerformanceUtils = PerformanceUtils;
@@ -1,63 +1,57 @@
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/primitives.ts
20
- var primitives_exports = {};
21
- __export(primitives_exports, {
22
- default: () => Frustum
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(primitives_exports);
25
- var import_gl_matrix = require("gl-matrix");
26
- var Frustum = class {
27
- static fromInvProjectionMatrix(invProj, worldSize, zoom) {
28
- const clipSpaceCorners = [
29
- [-1, 1, -1, 1],
30
- [1, 1, -1, 1],
31
- [1, -1, -1, 1],
32
- [-1, -1, -1, 1],
33
- [-1, 1, 1, 1],
34
- [1, 1, 1, 1],
35
- [1, -1, 1, 1],
36
- [-1, -1, 1, 1]
37
- ];
38
- const scale = Math.pow(2, zoom);
39
- const frustumCoords = clipSpaceCorners.map((v) => import_gl_matrix.vec4.transformMat4(new Float32Array([]), v, invProj)).map((v) => import_gl_matrix.vec4.scale(new Float32Array([]), v, 1 / v[3] / worldSize * scale));
40
- const frustumPlanePointIndices = [
41
- [0, 1, 2],
42
- [6, 5, 4],
43
- [0, 3, 7],
44
- [2, 1, 5],
45
- [3, 2, 6],
46
- [0, 4, 5]
47
- ];
48
- const frustumPlanes = frustumPlanePointIndices.map((p) => {
49
- const a = import_gl_matrix.vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[0]]), new Float32Array(frustumCoords[p[1]]));
50
- const b = import_gl_matrix.vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[2]]), new Float32Array(frustumCoords[p[1]]));
51
- const n = import_gl_matrix.vec3.normalize(new Float32Array(3), import_gl_matrix.vec3.cross(new Float32Array(3), a, b));
52
- const d = -import_gl_matrix.vec3.dot(n, new Float32Array(frustumCoords[p[1]]));
53
- return n.concat(d);
54
- });
55
- return new Frustum(frustumCoords, frustumPlanes);
56
- }
57
- constructor(points, planes) {
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
+ var Frustum = /*#__PURE__*/function () {
17
+ function Frustum(points, planes) {
18
+ (0, _classCallCheck2.default)(this, Frustum);
58
19
  this.points = points;
59
20
  this.planes = planes;
60
21
  }
61
- };
62
- // Annotate the CommonJS export names for ESM import in node:
63
- 0 && (module.exports = {});
22
+
23
+ (0, _createClass2.default)(Frustum, null, [{
24
+ key: "fromInvProjectionMatrix",
25
+ value: function fromInvProjectionMatrix(invProj, worldSize, zoom) {
26
+ 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]];
27
+ var scale = Math.pow(2, zoom); // Transform frustum corner points from clip space to tile space
28
+
29
+ var frustumCoords = clipSpaceCorners.map(function (v) {
30
+ return _glMatrix.vec4.transformMat4(new Float32Array([]), v, invProj);
31
+ }).map(function (v) {
32
+ return _glMatrix.vec4.scale(new Float32Array([]), v, 1.0 / v[3] / worldSize * scale);
33
+ });
34
+ var frustumPlanePointIndices = [[0, 1, 2], // near
35
+ [6, 5, 4], // far
36
+ [0, 3, 7], // left
37
+ [2, 1, 5], // right
38
+ [3, 2, 6], // bottom
39
+ [0, 4, 5] // top
40
+ ];
41
+ var frustumPlanes = frustumPlanePointIndices.map(function (p) {
42
+ var a = _glMatrix.vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[0]]), new Float32Array(frustumCoords[p[1]]));
43
+
44
+ var b = _glMatrix.vec3.sub(new Float32Array(3), new Float32Array(frustumCoords[p[2]]), new Float32Array(frustumCoords[p[1]]));
45
+
46
+ var n = _glMatrix.vec3.normalize(new Float32Array(3), _glMatrix.vec3.cross(new Float32Array(3), a, b));
47
+
48
+ var d = -_glMatrix.vec3.dot(n, new Float32Array(frustumCoords[p[1]]));
49
+ return n.concat(d);
50
+ });
51
+ return new Frustum(frustumCoords, frustumPlanes);
52
+ }
53
+ }]);
54
+ return Frustum;
55
+ }();
56
+
57
+ exports.default = Frustum;