@antv/l7-map 2.17.10 → 2.17.12

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 (103) hide show
  1. package/es/camera.js +148 -90
  2. package/es/earthmap.js +65 -13
  3. package/es/geo/edge_insets.js +14 -4
  4. package/es/geo/lng_lat.js +13 -5
  5. package/es/geo/lng_lat_bounds.js +17 -4
  6. package/es/geo/mercator.js +10 -2
  7. package/es/geo/point.js +7 -0
  8. package/es/geo/simple.js +11 -6
  9. package/es/geo/transform.js +132 -127
  10. package/es/handler/blockable_map_event.js +12 -7
  11. package/es/handler/box_zoom.js +30 -10
  12. package/es/handler/click_zoom.js +5 -0
  13. package/es/handler/events/event.js +2 -0
  14. package/es/handler/events/map_mouse_event.js +12 -0
  15. package/es/handler/events/map_touch_event.js +12 -2
  16. package/es/handler/events/map_wheel_event.js +12 -1
  17. package/es/handler/events/render_event.js +13 -0
  18. package/es/handler/handler_inertia.js +34 -6
  19. package/es/handler/handler_manager.js +147 -55
  20. package/es/handler/handler_util.js +2 -1
  21. package/es/handler/keyboard.js +20 -1
  22. package/es/handler/map_event.js +9 -3
  23. package/es/handler/mouse/mouse_handler.js +24 -11
  24. package/es/handler/mouse/mousepan_handler.js +11 -1
  25. package/es/handler/mouse/mousepitch_hander.js +11 -1
  26. package/es/handler/mouse/mouserotate_hander.js +11 -1
  27. package/es/handler/mouse/util.js +3 -2
  28. package/es/handler/scroll_zoom.js +71 -43
  29. package/es/handler/shim/dblclick_zoom.js +9 -4
  30. package/es/handler/shim/drag_pan.js +11 -4
  31. package/es/handler/shim/drag_rotate.js +10 -4
  32. package/es/handler/shim/touch_zoom_rotate.js +16 -6
  33. package/es/handler/tap/single_tap_recognizer.js +31 -8
  34. package/es/handler/tap/tap_drag_zoom.js +15 -7
  35. package/es/handler/tap/tap_recognizer.js +11 -3
  36. package/es/handler/tap/tap_zoom.js +7 -1
  37. package/es/handler/touch/touch_pan.js +22 -4
  38. package/es/handler/touch/touch_pitch.js +27 -10
  39. package/es/handler/touch/touch_rotate.js +19 -8
  40. package/es/handler/touch/touch_zoom.js +18 -5
  41. package/es/handler/touch/two_touch.js +32 -19
  42. package/es/hash.js +31 -9
  43. package/es/map.js +78 -16
  44. package/es/util.js +26 -18
  45. package/es/utils/Aabb.js +31 -10
  46. package/es/utils/dom.js +58 -24
  47. package/es/utils/performance.js +7 -8
  48. package/es/utils/primitives.js +11 -13
  49. package/es/utils/task_queue.js +23 -6
  50. package/lib/camera.js +169 -91
  51. package/lib/earthmap.js +80 -12
  52. package/lib/geo/edge_insets.js +18 -3
  53. package/lib/geo/lng_lat.js +18 -5
  54. package/lib/geo/lng_lat_bounds.js +20 -4
  55. package/lib/geo/mercator.js +22 -1
  56. package/lib/geo/point.js +8 -0
  57. package/lib/geo/simple.js +24 -5
  58. package/lib/geo/transform.js +164 -127
  59. package/lib/handler/blockable_map_event.js +14 -6
  60. package/lib/handler/box_zoom.js +39 -8
  61. package/lib/handler/click_zoom.js +6 -0
  62. package/lib/handler/events/event.js +5 -0
  63. package/lib/handler/events/index.js +4 -0
  64. package/lib/handler/events/map_mouse_event.js +20 -2
  65. package/lib/handler/events/map_touch_event.js +21 -2
  66. package/lib/handler/events/map_wheel_event.js +16 -1
  67. package/lib/handler/events/render_event.js +19 -0
  68. package/lib/handler/handler_inertia.js +37 -5
  69. package/lib/handler/handler_manager.js +171 -56
  70. package/lib/handler/handler_util.js +3 -1
  71. package/lib/handler/keyboard.js +22 -1
  72. package/lib/handler/map_event.js +11 -2
  73. package/lib/handler/mouse/index.js +4 -0
  74. package/lib/handler/mouse/mouse_handler.js +27 -10
  75. package/lib/handler/mouse/mousepan_handler.js +18 -1
  76. package/lib/handler/mouse/mousepitch_hander.js +17 -1
  77. package/lib/handler/mouse/mouserotate_hander.js +17 -1
  78. package/lib/handler/mouse/util.js +6 -2
  79. package/lib/handler/scroll_zoom.js +77 -43
  80. package/lib/handler/shim/dblclick_zoom.js +10 -4
  81. package/lib/handler/shim/drag_pan.js +13 -4
  82. package/lib/handler/shim/drag_rotate.js +11 -4
  83. package/lib/handler/shim/touch_zoom_rotate.js +18 -6
  84. package/lib/handler/tap/single_tap_recognizer.js +33 -8
  85. package/lib/handler/tap/tap_drag_zoom.js +18 -6
  86. package/lib/handler/tap/tap_recognizer.js +17 -2
  87. package/lib/handler/tap/tap_zoom.js +9 -0
  88. package/lib/handler/touch/index.js +5 -0
  89. package/lib/handler/touch/touch_pan.js +25 -4
  90. package/lib/handler/touch/touch_pitch.js +32 -10
  91. package/lib/handler/touch/touch_rotate.js +25 -8
  92. package/lib/handler/touch/touch_zoom.js +24 -5
  93. package/lib/handler/touch/two_touch.js +35 -18
  94. package/lib/hash.js +35 -8
  95. package/lib/index.js +8 -0
  96. package/lib/map.js +95 -15
  97. package/lib/util.js +38 -16
  98. package/lib/utils/Aabb.js +34 -10
  99. package/lib/utils/dom.js +64 -22
  100. package/lib/utils/performance.js +9 -8
  101. package/lib/utils/primitives.js +16 -13
  102. package/lib/utils/task_queue.js +24 -6
  103. package/package.json +3 -3
package/lib/map.js CHANGED
@@ -1,66 +1,98 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.Map = void 0;
9
+
8
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
9
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
10
14
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
11
16
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
12
18
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
13
20
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
14
22
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
15
24
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
16
26
  var _l7Utils = require("@antv/l7-utils");
27
+
17
28
  var _lodash = require("lodash");
29
+
18
30
  var _camera = _interopRequireDefault(require("./camera"));
31
+
19
32
  var _lng_lat = _interopRequireDefault(require("./geo/lng_lat"));
33
+
20
34
  var _lng_lat_bounds = _interopRequireDefault(require("./geo/lng_lat_bounds"));
35
+
21
36
  var _point = _interopRequireDefault(require("./geo/point"));
37
+
22
38
  var _handler_manager = _interopRequireDefault(require("./handler/handler_manager"));
39
+
23
40
  var _hash = _interopRequireDefault(require("./hash"));
41
+
24
42
  var _util = require("./util");
43
+
25
44
  var _performance = require("./utils/performance");
45
+
26
46
  var _task_queue = _interopRequireDefault(require("./utils/task_queue"));
47
+
27
48
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
49
+
28
50
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
+
29
52
  function loadStyles(css, doc) {
30
53
  var isMiniAli = typeof my !== 'undefined' && !!my && typeof my.showToast === 'function' && my.isFRM !== true;
31
54
  var isWeChatMiniProgram = typeof wx !== 'undefined' && wx !== null && (typeof wx.request !== 'undefined' || typeof wx.miniProgram !== 'undefined');
55
+
32
56
  if (isMiniAli || isWeChatMiniProgram) {
33
57
  return;
34
58
  }
59
+
35
60
  if (!doc) doc = document;
61
+
36
62
  if (!doc) {
37
63
  return;
38
64
  }
65
+
39
66
  var head = doc.head || doc.getElementsByTagName('head')[0];
67
+
40
68
  if (!head) {
41
69
  head = doc.createElement('head');
42
70
  var body = doc.body || doc.getElementsByTagName('body')[0];
71
+
43
72
  if (body) {
44
73
  body.parentNode.insertBefore(head, body);
45
74
  } else {
46
75
  doc.documentElement.appendChild(head);
47
76
  }
48
77
  }
78
+
49
79
  var style = doc.createElement('style');
50
80
  style.type = 'text/css';
81
+
51
82
  if (style.styleSheet) {
52
83
  style.styleSheet.cssText = css;
53
84
  } else {
54
85
  style.appendChild(doc.createTextNode(css));
55
86
  }
87
+
56
88
  head.appendChild(style);
57
89
  return style;
58
90
  }
59
- loadStyles(".l7-map {\n font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;\n overflow: hidden;\n position: relative;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n}\n\n.l7-canvas {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.l7-map:-webkit-full-screen {\n width: 100%;\n height: 100%;\n}\n\n.l7-canary {\n background-color: salmon;\n}\n\n.l7-canvas-container.l7-interactive,\n.l7-ctrl-group button.l7-ctrl-compass {\n cursor: -webkit-grab;\n cursor: grab;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.l7-canvas-container.l7-interactive.l7-track-pointer {\n cursor: pointer;\n}\n\n.l7-canvas-container.l7-interactive:active,\n.l7-ctrl-group button.l7-ctrl-compass:active {\n cursor: -webkit-grabbing;\n cursor: grabbing;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate,\n.l7-canvas-container.l7-touch-zoom-rotate .l7-canvas {\n -ms-touch-action: pan-x pan-y;\n touch-action: pan-x pan-y;\n}\n\n.l7-canvas-container.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: pinch-zoom;\n touch-action: pinch-zoom;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: none;\n touch-action: none;\n}\n\n.l7-ctrl-top-left,\n.l7-ctrl-top-right,\n.l7-ctrl-bottom-left,\n.l7-ctrl-bottom-right { position: absolute; pointer-events: none; z-index: 2; }\n.l7-ctrl-top-left { top: 0; left: 0; }\n.l7-ctrl-top-right { top: 0; right: 0; }\n.l7-ctrl-bottom-left { bottom: 0; left: 0; }\n.l7-ctrl-bottom-right { right: 0; bottom: 0; }\n\n.l7-ctrl {\n clear: both;\n pointer-events: auto;\n\n /* workaround for a Safari bug https://github.com/mapbox/mapbox-gl-js/issues/8185 */\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0);\n}\n.l7-ctrl-top-left .l7-ctrl { margin: 10px 0 0 10px; float: left; }\n.l7-ctrl-top-right .l7-ctrl { margin: 10px 10px 0 0; float: right; }\n.l7-ctrl-bottom-left .l7-ctrl { margin: 0 0 10px 10px; float: left; }\n.l7-ctrl-bottom-right .l7-ctrl { margin: 0 10px 10px 0; float: right; }\n\n\n.l7-crosshair,\n.l7-crosshair .l7-interactive,\n.l7-crosshair .l7-interactive:active {\n cursor: crosshair;\n}\n\n.l7-boxzoom {\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n background: #fff;\n border: 2px dotted #202020;\n opacity: 0.5;\n z-index: 10;\n}\n"); // @ts-ignore
91
+
92
+ loadStyles(".l7-map {\n font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;\n overflow: hidden;\n position: relative;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n}\n\n.l7-canvas {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.l7-map:-webkit-full-screen {\n width: 100%;\n height: 100%;\n}\n\n.l7-canary {\n background-color: salmon;\n}\n\n.l7-canvas-container.l7-interactive,\n.l7-ctrl-group button.l7-ctrl-compass {\n cursor: -webkit-grab;\n cursor: grab;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.l7-canvas-container.l7-interactive.l7-track-pointer {\n cursor: pointer;\n}\n\n.l7-canvas-container.l7-interactive:active,\n.l7-ctrl-group button.l7-ctrl-compass:active {\n cursor: -webkit-grabbing;\n cursor: grabbing;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate,\n.l7-canvas-container.l7-touch-zoom-rotate .l7-canvas {\n -ms-touch-action: pan-x pan-y;\n touch-action: pan-x pan-y;\n}\n\n.l7-canvas-container.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: pinch-zoom;\n touch-action: pinch-zoom;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: none;\n touch-action: none;\n}\n\n.l7-ctrl-top-left,\n.l7-ctrl-top-right,\n.l7-ctrl-bottom-left,\n.l7-ctrl-bottom-right { position: absolute; pointer-events: none; z-index: 2; }\n.l7-ctrl-top-left { top: 0; left: 0; }\n.l7-ctrl-top-right { top: 0; right: 0; }\n.l7-ctrl-bottom-left { bottom: 0; left: 0; }\n.l7-ctrl-bottom-right { right: 0; bottom: 0; }\n\n.l7-ctrl {\n clear: both;\n pointer-events: auto;\n\n /* workaround for a Safari bug https://github.com/mapbox/mapbox-gl-js/issues/8185 */\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0);\n}\n.l7-ctrl-top-left .l7-ctrl { margin: 10px 0 0 10px; float: left; }\n.l7-ctrl-top-right .l7-ctrl { margin: 10px 10px 0 0; float: right; }\n.l7-ctrl-bottom-left .l7-ctrl { margin: 0 0 10px 10px; float: left; }\n.l7-ctrl-bottom-right .l7-ctrl { margin: 0 10px 10px 0; float: right; }\n\n\n.l7-crosshair,\n.l7-crosshair .l7-interactive,\n.l7-crosshair .l7-interactive:active {\n cursor: crosshair;\n}\n\n.l7-boxzoom {\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n background: #fff;\n border: 2px dotted #202020;\n opacity: 0.5;\n z-index: 10;\n}\n");
60
93
  var defaultMinZoom = -2;
61
- var defaultMaxZoom = 22;
94
+ var defaultMaxZoom = 22; // the default values, but also the valid range
62
95
 
63
- // the default values, but also the valid range
64
96
  var defaultMinPitch = 0;
65
97
  var defaultMaxPitch = 60;
66
98
  var DefaultOptions = {
@@ -90,11 +122,15 @@ var DefaultOptions = {
90
122
  pitchEnabled: true,
91
123
  rotateEnabled: true
92
124
  };
125
+
93
126
  var Map = /*#__PURE__*/function (_Camera) {
94
127
  (0, _inherits2.default)(Map, _Camera);
128
+
95
129
  var _super = _createSuper(Map);
130
+
96
131
  function Map(options) {
97
132
  var _this;
133
+
98
134
  (0, _classCallCheck2.default)(this, Map);
99
135
  _this = _super.call(this, (0, _lodash.merge)({}, DefaultOptions, options));
100
136
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderTaskQueue", new _task_queue.default());
@@ -109,26 +145,32 @@ var Map = /*#__PURE__*/function (_Camera) {
109
145
  }).update();
110
146
  }
111
147
  });
148
+
112
149
  if (_l7Utils.isMini) {
113
150
  _this.initMiniContainer();
114
151
  } else {
115
152
  _this.initContainer();
116
153
  }
154
+
117
155
  _this.resize();
156
+
118
157
  _this.handlers = new _handler_manager.default((0, _assertThisInitialized2.default)(_this), _this.options);
158
+
119
159
  if (typeof window !== 'undefined') {
120
160
  window.addEventListener('online', _this.onWindowOnline, false);
121
161
  window.addEventListener('resize', _this.onWindowResize, false);
122
162
  window.addEventListener('orientationchange', _this.onWindowResize, false);
123
163
  }
164
+
124
165
  if (!_l7Utils.isMini) {
125
166
  var hashName = typeof options.hash === 'string' && options.hash || undefined;
167
+
126
168
  if (options.hash) {
127
169
  _this.hash = new _hash.default(hashName).addTo((0, _assertThisInitialized2.default)(_this));
128
170
  }
129
- }
171
+ } // don't set position from options if set through hash
172
+
130
173
 
131
- // don't set position from options if set through hash
132
174
  if (!_this.hash || !_this.hash.onHashChange()) {
133
175
  _this.jumpTo({
134
176
  center: options.center,
@@ -136,37 +178,47 @@ var Map = /*#__PURE__*/function (_Camera) {
136
178
  bearing: options.bearing,
137
179
  pitch: options.pitch
138
180
  });
181
+
139
182
  if (options.bounds) {
140
183
  _this.resize();
184
+
141
185
  _this.fitBounds(options.bounds, (0, _lodash.merge)({}, options.fitBoundsOptions, {
142
186
  duration: 0
143
187
  }));
144
188
  }
145
189
  }
190
+
146
191
  return _this;
147
192
  }
193
+
148
194
  (0, _createClass2.default)(Map, [{
149
195
  key: "resize",
150
196
  value: function resize(eventData) {
151
197
  var _this$containerDimens = this.containerDimensions(),
152
- _this$containerDimens2 = (0, _slicedToArray2.default)(_this$containerDimens, 2),
153
- width = _this$containerDimens2[0],
154
- height = _this$containerDimens2[1];
155
- this.transform.resize(width, height);
156
- // 小程序环境不需要执行后续动作
198
+ _this$containerDimens2 = (0, _slicedToArray2.default)(_this$containerDimens, 2),
199
+ width = _this$containerDimens2[0],
200
+ height = _this$containerDimens2[1];
201
+
202
+ this.transform.resize(width, height); // 小程序环境不需要执行后续动作
203
+
157
204
  if (_l7Utils.isMini) {
158
205
  return this;
159
206
  }
207
+
160
208
  var fireMoving = !this.moving;
209
+
161
210
  if (fireMoving) {
162
211
  this.stop();
163
212
  this.emit('movestart', new _l7Utils.$window.Event('movestart', eventData));
164
213
  this.emit('move', new _l7Utils.$window.Event('move', eventData));
165
214
  }
215
+
166
216
  this.emit('resize', new _l7Utils.$window.Event('resize', eventData));
217
+
167
218
  if (fireMoving) {
168
219
  this.emit('moveend', new _l7Utils.$window.Event('moveend', eventData));
169
220
  }
221
+
170
222
  return this;
171
223
  }
172
224
  }, {
@@ -208,9 +260,8 @@ var Map = /*#__PURE__*/function (_Camera) {
208
260
  key: "setMaxBounds",
209
261
  value: function setMaxBounds(bounds) {
210
262
  this.transform.setMaxBounds(_lng_lat_bounds.default.convert(bounds));
211
- }
263
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
212
264
 
213
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
214
265
  }, {
215
266
  key: "setStyle",
216
267
  value: function setStyle(style) {
@@ -220,11 +271,14 @@ var Map = /*#__PURE__*/function (_Camera) {
220
271
  key: "setMinZoom",
221
272
  value: function setMinZoom(minZoom) {
222
273
  minZoom = minZoom === null || minZoom === undefined ? defaultMinZoom : minZoom;
274
+
223
275
  if (minZoom >= defaultMinZoom && minZoom <= this.transform.maxZoom) {
224
276
  this.transform.minZoom = minZoom;
277
+
225
278
  if (this.getZoom() < minZoom) {
226
279
  this.setZoom(minZoom);
227
280
  }
281
+
228
282
  return this;
229
283
  } else {
230
284
  throw new Error("minZoom must be between ".concat(defaultMinZoom, " and the current maxZoom, inclusive"));
@@ -239,11 +293,14 @@ var Map = /*#__PURE__*/function (_Camera) {
239
293
  key: "setMaxZoom",
240
294
  value: function setMaxZoom(maxZoom) {
241
295
  maxZoom = maxZoom === null || maxZoom === undefined ? defaultMaxZoom : maxZoom;
296
+
242
297
  if (maxZoom >= this.transform.minZoom) {
243
298
  this.transform.maxZoom = maxZoom;
299
+
244
300
  if (this.getZoom() > maxZoom) {
245
301
  this.setZoom(maxZoom);
246
302
  }
303
+
247
304
  return this;
248
305
  } else {
249
306
  throw new Error('maxZoom must be greater than the current minZoom');
@@ -258,14 +315,18 @@ var Map = /*#__PURE__*/function (_Camera) {
258
315
  key: "setMinPitch",
259
316
  value: function setMinPitch(minPitch) {
260
317
  minPitch = minPitch === null || minPitch === undefined ? defaultMinPitch : minPitch;
318
+
261
319
  if (minPitch < defaultMinPitch) {
262
320
  throw new Error("minPitch must be greater than or equal to ".concat(defaultMinPitch));
263
321
  }
322
+
264
323
  if (minPitch >= defaultMinPitch && minPitch <= this.transform.maxPitch) {
265
324
  this.transform.minPitch = minPitch;
325
+
266
326
  if (this.getPitch() < minPitch) {
267
327
  this.setPitch(minPitch);
268
328
  }
329
+
269
330
  return this;
270
331
  } else {
271
332
  throw new Error("minPitch must be between ".concat(defaultMinPitch, " and the current maxPitch, inclusive"));
@@ -280,14 +341,18 @@ var Map = /*#__PURE__*/function (_Camera) {
280
341
  key: "setMaxPitch",
281
342
  value: function setMaxPitch(maxPitch) {
282
343
  maxPitch = maxPitch === null || maxPitch === undefined ? defaultMaxPitch : maxPitch;
344
+
283
345
  if (maxPitch > defaultMaxPitch) {
284
346
  throw new Error("maxPitch must be less than or equal to ".concat(defaultMaxPitch));
285
347
  }
348
+
286
349
  if (maxPitch >= this.transform.minPitch) {
287
350
  this.transform.maxPitch = maxPitch;
351
+
288
352
  if (this.getPitch() > maxPitch) {
289
353
  this.setPitch(maxPitch);
290
354
  }
355
+
291
356
  return this;
292
357
  } else {
293
358
  throw new Error('maxPitch must be greater than the current minPitch');
@@ -311,13 +376,15 @@ var Map = /*#__PURE__*/function (_Camera) {
311
376
  }, {
312
377
  key: "remove",
313
378
  value: function remove() {
314
- this.container.removeChild(this.canvasContainer);
315
- // @ts-ignore
379
+ this.container.removeChild(this.canvasContainer); // @ts-ignore
380
+
316
381
  this.canvasContainer = null;
382
+
317
383
  if (this.frame) {
318
384
  this.frame.cancel();
319
385
  this.frame = null;
320
386
  }
387
+
321
388
  this.renderTaskQueue.clear();
322
389
  }
323
390
  }, {
@@ -335,10 +402,13 @@ var Map = /*#__PURE__*/function (_Camera) {
335
402
  key: "triggerRepaint",
336
403
  value: function triggerRepaint() {
337
404
  var _this2 = this;
405
+
338
406
  if (!this.frame) {
339
407
  this.frame = (0, _util.renderframe)(function (paintStartTimeStamp) {
340
408
  _performance.PerformanceUtils.frame(paintStartTimeStamp);
409
+
341
410
  _this2.frame = null;
411
+
342
412
  _this2.update(paintStartTimeStamp);
343
413
  });
344
414
  }
@@ -347,10 +417,13 @@ var Map = /*#__PURE__*/function (_Camera) {
347
417
  key: "update",
348
418
  value: function update(time) {
349
419
  var _this3 = this;
420
+
350
421
  if (!this.frame) {
351
422
  this.frame = (0, _util.renderframe)(function (paintStartTimeStamp) {
352
423
  _performance.PerformanceUtils.frame(paintStartTimeStamp);
424
+
353
425
  _this3.frame = null;
426
+
354
427
  _this3.renderTaskQueue.run(time);
355
428
  });
356
429
  }
@@ -360,6 +433,7 @@ var Map = /*#__PURE__*/function (_Camera) {
360
433
  value: function initContainer() {
361
434
  if (typeof this.options.container === 'string') {
362
435
  this.container = window.document.getElementById(this.options.container);
436
+
363
437
  if (!this.container) {
364
438
  throw new Error("Container '".concat(this.options.container, "' not found."));
365
439
  }
@@ -368,17 +442,20 @@ var Map = /*#__PURE__*/function (_Camera) {
368
442
  } else {
369
443
  throw new Error("Invalid type: 'container' must be a String or HTMLElement.");
370
444
  }
445
+
371
446
  var container = this.container;
372
447
  container.classList.add('l7-map');
448
+
373
449
  var canvasContainer = this.canvasContainer = _l7Utils.DOM.create('div', 'l7-canvas-container', container);
450
+
374
451
  if (this.options.interactive) {
375
452
  canvasContainer.classList.add('l7-interactive');
376
453
  }
377
454
  }
378
-
379
455
  /**
380
456
  * 小程序环境构建容器
381
457
  */
458
+
382
459
  }, {
383
460
  key: "initMiniContainer",
384
461
  value: function initMiniContainer() {
@@ -390,6 +467,7 @@ var Map = /*#__PURE__*/function (_Camera) {
390
467
  value: function containerDimensions() {
391
468
  var width = 0;
392
469
  var height = 0;
470
+
393
471
  if (this.container) {
394
472
  if (_l7Utils.isMini) {
395
473
  width = this.container.width / _l7Utils.$window.devicePixelRatio;
@@ -401,9 +479,11 @@ var Map = /*#__PURE__*/function (_Camera) {
401
479
  height = height === 0 ? 300 : height;
402
480
  }
403
481
  }
482
+
404
483
  return [width, height];
405
484
  }
406
485
  }]);
407
486
  return Map;
408
487
  }(_camera.default);
488
+
409
489
  exports.Map = Map;
package/lib/util.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
@@ -16,50 +17,68 @@ exports.prefersReducedMotion = prefersReducedMotion;
16
17
  exports.raf = void 0;
17
18
  exports.renderframe = renderframe;
18
19
  exports.wrap = wrap;
20
+
19
21
  var _l7Utils = require("@antv/l7-utils");
22
+
20
23
  var _unitbezier = _interopRequireDefault(require("@mapbox/unitbezier"));
24
+
21
25
  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; } } }; }
26
+
22
27
  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); }
23
- 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
28
+
29
+ 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; }
30
+
24
31
  var reducedMotionQuery;
32
+
25
33
  function wrap(n, min, max) {
26
34
  var d = max - min;
27
35
  var w = ((n - min) % d + d) % d + min;
28
36
  return w === min ? max : w;
29
37
  }
38
+
30
39
  function clamp(n, min, max) {
31
40
  return Math.min(max, Math.max(min, n));
32
41
  }
42
+
33
43
  function interpolate(a, b, t) {
34
44
  return a * (1 - t) + b * t;
35
45
  }
46
+
36
47
  function bezier(p1x, p1y, p2x, p2y) {
37
48
  var bez = new _unitbezier.default(p1x, p1y, p2x, p2y);
38
49
  return function (t) {
39
50
  return bez.solve(t);
40
51
  };
41
52
  }
53
+
42
54
  var ease = bezier(0.25, 0.1, 0.25, 1);
43
55
  exports.ease = ease;
56
+
44
57
  function prefersReducedMotion() {
45
58
  // @ts-ignore
46
59
  if (_l7Utils.isMini || !_l7Utils.$window.matchMedia) {
47
60
  return false;
48
- }
49
- // Lazily initialize media query
61
+ } // Lazily initialize media query
62
+
63
+
50
64
  if (reducedMotionQuery == null) {
51
65
  // @ts-ignore
52
66
  reducedMotionQuery = _l7Utils.$window.matchMedia('(prefers-reduced-motion: reduce)');
53
67
  }
68
+
54
69
  return reducedMotionQuery.matches;
55
70
  }
71
+
56
72
  function pick(src, properties) {
57
73
  var result = {};
74
+
58
75
  var _iterator = _createForOfIteratorHelper(properties),
59
- _step;
76
+ _step;
77
+
60
78
  try {
61
79
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
62
80
  var name = _step.value;
81
+
63
82
  if (name in src) {
64
83
  result[name] = src[name];
65
84
  }
@@ -69,26 +88,25 @@ function pick(src, properties) {
69
88
  } finally {
70
89
  _iterator.f();
71
90
  }
91
+
72
92
  return result;
73
93
  }
94
+
74
95
  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);
75
96
  exports.now = now;
76
- var raf = _l7Utils.$window.requestAnimationFrame ||
77
- // @ts-ignore
78
- _l7Utils.$window.mozRequestAnimationFrame ||
79
- // @ts-ignore
80
- _l7Utils.$window.webkitRequestAnimationFrame ||
81
- // @ts-ignore
97
+ var raf = _l7Utils.$window.requestAnimationFrame || // @ts-ignore
98
+ _l7Utils.$window.mozRequestAnimationFrame || // @ts-ignore
99
+ _l7Utils.$window.webkitRequestAnimationFrame || // @ts-ignore
82
100
  _l7Utils.$window.msRequestAnimationFrame;
83
101
  exports.raf = raf;
84
- var _cancel = _l7Utils.$window.cancelAnimationFrame ||
85
- // @ts-ignore
86
- _l7Utils.$window.mozCancelAnimationFrame ||
87
- // @ts-ignore
88
- _l7Utils.$window.webkitCancelAnimationFrame ||
89
- // @ts-ignore
102
+
103
+ var _cancel = _l7Utils.$window.cancelAnimationFrame || // @ts-ignore
104
+ _l7Utils.$window.mozCancelAnimationFrame || // @ts-ignore
105
+ _l7Utils.$window.webkitCancelAnimationFrame || // @ts-ignore
90
106
  _l7Utils.$window.msCancelAnimationFrame;
107
+
91
108
  exports.cancel = _cancel;
109
+
92
110
  function renderframe(fn) {
93
111
  var frame = raf(fn);
94
112
  return {
@@ -97,17 +115,21 @@ function renderframe(fn) {
97
115
  }
98
116
  };
99
117
  }
118
+
100
119
  function extend(dest) {
101
120
  for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
102
121
  sources[_key - 1] = arguments[_key];
103
122
  }
123
+
104
124
  for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
105
125
  var src = _sources[_i];
126
+
106
127
  for (var k in src) {
107
128
  if (src[k] !== undefined) {
108
129
  dest[k] = src[k];
109
130
  }
110
131
  }
111
132
  }
133
+
112
134
  return dest;
113
135
  }
package/lib/utils/Aabb.js CHANGED
@@ -1,16 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = void 0;
9
+
8
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
9
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _glMatrix = require("gl-matrix");
15
+
11
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
+
12
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); }
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; }
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
+
14
22
  var Aabb = /*#__PURE__*/function () {
15
23
  function Aabb(min, max) {
16
24
  (0, _classCallCheck2.default)(this, Aabb);
@@ -18,17 +26,22 @@ var Aabb = /*#__PURE__*/function () {
18
26
  this.max = max;
19
27
  this.center = _glMatrix.vec3.scale(new Float32Array(3), _glMatrix.vec3.add(new Float32Array(3), this.min, this.max), 0.5);
20
28
  }
29
+
21
30
  (0, _createClass2.default)(Aabb, [{
22
31
  key: "quadrant",
23
32
  value: function quadrant(index) {
24
33
  var split = [index % 2 === 0, index < 2];
34
+
25
35
  var qMin = _glMatrix.vec3.clone(this.min);
36
+
26
37
  var qMax = _glMatrix.vec3.clone(this.max);
38
+
27
39
  for (var axis = 0; axis < split.length; axis++) {
28
40
  qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
29
41
  qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
30
- }
31
- // Elevation is always constant, hence quadrant.max.z = this.max.z
42
+ } // Elevation is always constant, hence quadrant.max.z = this.max.z
43
+
44
+
32
45
  qMax[2] = this.max[2];
33
46
  return new Aabb(qMin, qMax);
34
47
  }
@@ -43,27 +56,29 @@ var Aabb = /*#__PURE__*/function () {
43
56
  value: function distanceY(point) {
44
57
  var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
45
58
  return pointOnAabb - point[1];
46
- }
47
-
48
- // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
59
+ } // Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
49
60
  // 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
61
+
50
62
  }, {
51
63
  key: "intersects",
52
64
  value: function intersects(frustum) {
53
65
  // Execute separating axis test between two convex objects to find intersections
54
66
  // Each frustum plane together with 3 major axes define the separating axes
55
67
  // Note: test only 4 points as both min and max points have equal elevation
56
-
57
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]];
58
69
  var fullyInside = true;
70
+
59
71
  var _iterator = _createForOfIteratorHelper(frustum.planes),
60
- _step;
72
+ _step;
73
+
61
74
  try {
62
75
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
76
  var plane = _step.value;
64
77
  var pointsInside = 0;
78
+
65
79
  var _iterator3 = _createForOfIteratorHelper(aabbPoints),
66
- _step3;
80
+ _step3;
81
+
67
82
  try {
68
83
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
69
84
  var i = _step3.value;
@@ -75,9 +90,11 @@ var Aabb = /*#__PURE__*/function () {
75
90
  } finally {
76
91
  _iterator3.f();
77
92
  }
93
+
78
94
  if (pointsInside === 0) {
79
95
  return 0;
80
96
  }
97
+
81
98
  if (pointsInside !== aabbPoints.length) {
82
99
  fullyInside = false;
83
100
  }
@@ -87,14 +104,18 @@ var Aabb = /*#__PURE__*/function () {
87
104
  } finally {
88
105
  _iterator.f();
89
106
  }
107
+
90
108
  if (fullyInside) {
91
109
  return 2;
92
110
  }
111
+
93
112
  for (var axis = 0; axis < 3; axis++) {
94
113
  var projMin = Number.MAX_VALUE;
95
114
  var projMax = -Number.MAX_VALUE;
115
+
96
116
  var _iterator2 = _createForOfIteratorHelper(frustum.points),
97
- _step2;
117
+ _step2;
118
+
98
119
  try {
99
120
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
100
121
  var p = _step2.value;
@@ -107,13 +128,16 @@ var Aabb = /*#__PURE__*/function () {
107
128
  } finally {
108
129
  _iterator2.f();
109
130
  }
131
+
110
132
  if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
111
133
  return 0;
112
134
  }
113
135
  }
136
+
114
137
  return 1;
115
138
  }
116
139
  }]);
117
140
  return Aabb;
118
141
  }();
142
+
119
143
  exports.default = Aabb;