@antv/l7-component 2.21.1 → 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 (82) hide show
  1. package/es/assets/iconfont/iconfont.js +6 -6
  2. package/es/constants/index.js +2 -2
  3. package/es/control/baseControl/buttonControl.js +109 -144
  4. package/es/control/baseControl/control.js +212 -258
  5. package/es/control/baseControl/popperControl.js +67 -95
  6. package/es/control/baseControl/selectControl.js +132 -178
  7. package/es/control/exportImage.js +59 -142
  8. package/es/control/fullscreen.js +69 -100
  9. package/es/control/geoLocate.js +37 -84
  10. package/es/control/layerSwitch.js +111 -154
  11. package/es/control/logo.js +43 -69
  12. package/es/control/mapTheme.js +57 -98
  13. package/es/control/mouseLocation.js +37 -69
  14. package/es/control/scale.js +107 -135
  15. package/es/control/swipe.js +297 -389
  16. package/es/control/zoom.js +80 -112
  17. package/es/css/index.css +10 -7
  18. package/es/index.js +667 -1
  19. package/es/marker-layer.js +275 -326
  20. package/es/marker.js +394 -446
  21. package/es/popup/layerPopup.js +277 -321
  22. package/es/popup/popup.js +422 -482
  23. package/es/utils/anchor.js +6 -6
  24. package/es/utils/icon.js +4 -4
  25. package/es/utils/popper.js +180 -196
  26. package/es/utils/screenfull.js +29 -51
  27. package/lib/assets/iconfont/iconfont.js +6 -6
  28. package/lib/constants/index.d.ts +60 -0
  29. package/lib/constants/index.js +2 -2
  30. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  31. package/lib/control/baseControl/buttonControl.js +110 -143
  32. package/lib/control/baseControl/control.d.ts +112 -0
  33. package/lib/control/baseControl/control.js +213 -257
  34. package/lib/control/baseControl/index.d.ts +4 -0
  35. package/lib/control/baseControl/index.js +5 -5
  36. package/lib/control/baseControl/popperControl.d.ts +28 -0
  37. package/lib/control/baseControl/popperControl.js +68 -94
  38. package/lib/control/baseControl/selectControl.d.ts +53 -0
  39. package/lib/control/baseControl/selectControl.js +133 -177
  40. package/lib/control/exportImage.d.ts +19 -0
  41. package/lib/control/exportImage.js +60 -141
  42. package/lib/control/fullscreen.d.ts +20 -0
  43. package/lib/control/fullscreen.js +70 -99
  44. package/lib/control/geoLocate.d.ts +17 -0
  45. package/lib/control/geoLocate.js +38 -83
  46. package/lib/control/layerSwitch.d.ts +27 -0
  47. package/lib/control/layerSwitch.js +112 -153
  48. package/lib/control/logo.d.ts +14 -0
  49. package/lib/control/logo.js +44 -69
  50. package/lib/control/mapTheme.d.ts +11 -0
  51. package/lib/control/mapTheme.js +58 -97
  52. package/lib/control/mouseLocation.d.ts +16 -0
  53. package/lib/control/mouseLocation.js +38 -68
  54. package/lib/control/scale.d.ts +35 -0
  55. package/lib/control/scale.js +108 -134
  56. package/lib/control/swipe.d.ts +66 -0
  57. package/lib/control/swipe.js +298 -388
  58. package/lib/control/zoom.d.ts +39 -0
  59. package/lib/control/zoom.js +81 -111
  60. package/lib/css/index.css +10 -7
  61. package/lib/index.d.ts +19 -0
  62. package/lib/index.js +683 -17
  63. package/lib/interface.d.ts +18 -0
  64. package/lib/marker-layer.d.ts +55 -0
  65. package/lib/marker-layer.js +277 -324
  66. package/lib/marker.d.ts +58 -0
  67. package/lib/marker.js +395 -445
  68. package/lib/popup/layerPopup.d.ts +99 -0
  69. package/lib/popup/layerPopup.js +278 -320
  70. package/lib/popup/popup.d.ts +142 -0
  71. package/lib/popup/popup.js +423 -481
  72. package/lib/utils/anchor.d.ts +22 -0
  73. package/lib/utils/anchor.js +6 -6
  74. package/lib/utils/icon.d.ts +1 -0
  75. package/lib/utils/icon.js +6 -5
  76. package/lib/utils/popper.d.ts +76 -0
  77. package/lib/utils/popper.js +184 -196
  78. package/lib/utils/screenfull.d.ts +2 -0
  79. package/lib/utils/screenfull.js +29 -52
  80. package/package.json +16 -20
  81. package/CHANGELOG.md +0 -325
  82. package/LICENSE.md +0 -21
@@ -5,38 +5,24 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.Swipe = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
14
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
15
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
18
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
10
  var _l7Core = require("@antv/l7-core");
20
11
  var _l7Layers = require("@antv/l7-layers");
21
12
  var _l7Utils = require("@antv/l7-utils");
22
13
  var _baseControl = require("./baseControl");
23
- 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); }; }
24
- 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; } }
25
- var Swipe = exports.default = exports.Swipe = /*#__PURE__*/function (_Control) {
26
- (0, _inherits2.default)(Swipe, _Control);
27
- var _super = _createSuper(Swipe);
28
- function Swipe() {
29
- var _this;
30
- (0, _classCallCheck2.default)(this, Swipe);
31
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
- args[_key] = arguments[_key];
33
- }
34
- _this = _super.call.apply(_super, [this].concat(args));
14
+ class Swipe extends _baseControl.Control {
15
+ constructor(...args) {
16
+ super(...args);
35
17
  /**
36
18
  * 是否正在拖动卷帘
37
19
  */
38
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isMoving", false);
39
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "move", function (e) {
20
+ (0, _defineProperty2.default)(this, "isMoving", false);
21
+ /**
22
+ * 掩膜图层实例
23
+ */
24
+ (0, _defineProperty2.default)(this, "maskLayer", void 0);
25
+ (0, _defineProperty2.default)(this, "move", e => {
40
26
  // 阻止事件冒泡到地图上
41
27
  e.stopPropagation();
42
28
  switch (e.type) {
@@ -45,28 +31,28 @@ var Swipe = exports.default = exports.Swipe = /*#__PURE__*/function (_Control) {
45
31
  case 'mouseup':
46
32
  {
47
33
  var _this$scene;
48
- _this.isMoving = false;
49
- ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(function (eventName) {
50
- document.removeEventListener(eventName, _this.move);
34
+ this.isMoving = false;
35
+ ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(eventName => {
36
+ document.removeEventListener(eventName, this.move);
51
37
  });
52
- (_this$scene = _this.scene) === null || _this$scene === void 0 || _this$scene.render();
38
+ (_this$scene = this.scene) === null || _this$scene === void 0 || _this$scene.render();
53
39
  break;
54
40
  }
55
41
  case 'mousedown':
56
42
  case 'touchstart':
57
43
  {
58
- _this.isMoving = true;
59
- ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(function (eventName) {
60
- document.addEventListener(eventName, _this.move);
44
+ this.isMoving = true;
45
+ ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(eventName => {
46
+ document.addEventListener(eventName, this.move);
61
47
  });
62
48
  // fallthrough
63
49
  }
64
50
  case 'mousemove':
65
51
  case 'touchmove':
66
52
  {
67
- if (_this.isMoving) {
68
- if (_this.controlOption.orientation === 'vertical') {
69
- var pageX;
53
+ if (this.isMoving) {
54
+ if (this.controlOption.orientation === 'vertical') {
55
+ let pageX;
70
56
  if ('pageX' in e) {
71
57
  pageX = e.pageX;
72
58
  } else if (e.touches && e.touches.length && e.touches[0].pageX) {
@@ -77,22 +63,22 @@ var Swipe = exports.default = exports.Swipe = /*#__PURE__*/function (_Control) {
77
63
  if (!pageX) {
78
64
  break;
79
65
  }
80
- var containerRect = _this.getContainerDOMRect();
81
- var containerSize = _this.getContainerSize();
82
- var containerWidth = containerSize[0];
83
- var containerRectLeft = (containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) || 0;
84
- var offsetX = pageX - containerRectLeft + window.scrollX - document.documentElement.clientLeft;
85
- var width = containerWidth - Math.min(Math.max(0, containerWidth - offsetX), containerWidth);
86
- var ratio = width / containerWidth;
87
- _this.setOptions({
88
- ratio: ratio
66
+ const containerRect = this.getContainerDOMRect();
67
+ const containerSize = this.getContainerSize();
68
+ const containerWidth = containerSize[0];
69
+ const containerRectLeft = (containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) || 0;
70
+ const offsetX = pageX - containerRectLeft + window.scrollX - document.documentElement.clientLeft;
71
+ const width = containerWidth - Math.min(Math.max(0, containerWidth - offsetX), containerWidth);
72
+ const ratio = width / containerWidth;
73
+ this.setOptions({
74
+ ratio
89
75
  });
90
- _this.emit('moving', {
76
+ this.emit('moving', {
91
77
  size: [width, containerSize[1]],
92
78
  ratio: [ratio, 0]
93
79
  });
94
80
  } else {
95
- var pageY;
81
+ let pageY;
96
82
  if ('pageY' in e) {
97
83
  pageY = e.pageY;
98
84
  } else if (e.touches && e.touches.length && e.touches[0].pageY) {
@@ -103,19 +89,19 @@ var Swipe = exports.default = exports.Swipe = /*#__PURE__*/function (_Control) {
103
89
  if (!pageY) {
104
90
  break;
105
91
  }
106
- var _containerRect = _this.getContainerDOMRect();
107
- var _containerSize = _this.getContainerSize();
108
- var containerHeight = _containerSize[1];
109
- var _containerRectLeft = (_containerRect === null || _containerRect === void 0 ? void 0 : _containerRect.top) || 0;
110
- var offsetY = pageY - _containerRectLeft + window.scrollY - document.documentElement.clientTop;
111
- var height = containerHeight - Math.min(Math.max(0, containerHeight - offsetY), containerHeight);
112
- var _ratio = height / containerHeight;
113
- _this.setOptions({
114
- ratio: _ratio
92
+ const containerRect = this.getContainerDOMRect();
93
+ const containerSize = this.getContainerSize();
94
+ const containerHeight = containerSize[1];
95
+ const containerRectLeft = (containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) || 0;
96
+ const offsetY = pageY - containerRectLeft + window.scrollY - document.documentElement.clientTop;
97
+ const height = containerHeight - Math.min(Math.max(0, containerHeight - offsetY), containerHeight);
98
+ const ratio = height / containerHeight;
99
+ this.setOptions({
100
+ ratio
115
101
  });
116
- _this.emit('moving', {
117
- size: [_containerSize[0], height],
118
- ratio: [0, _ratio]
102
+ this.emit('moving', {
103
+ size: [containerSize[0], height],
104
+ ratio: [0, ratio]
119
105
  });
120
106
  }
121
107
  }
@@ -125,365 +111,289 @@ var Swipe = exports.default = exports.Swipe = /*#__PURE__*/function (_Control) {
125
111
  break;
126
112
  }
127
113
  });
128
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getMaskLayer", function () {
129
- console.log(_this.getMaskGeoData());
114
+ (0, _defineProperty2.default)(this, "getMaskLayer", () => {
115
+ console.log(this.getMaskGeoData());
130
116
  return new _l7Layers.PolygonLayer({
131
117
  visible: false
132
- }).source(_this.getMaskGeoData()).shape('fill').color('red').style({
118
+ }).source(this.getMaskGeoData()).shape('fill').color('red').style({
133
119
  opacity: 0.1
134
120
  });
135
121
  });
136
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateMask", function () {
122
+ (0, _defineProperty2.default)(this, "updateMask", () => {
137
123
  var _this$maskLayer;
138
- if (!_this.mapsService) return;
139
- var geoJSON = _this.getMaskGeoData();
140
- (_this$maskLayer = _this.maskLayer) === null || _this$maskLayer === void 0 || _this$maskLayer.setData(geoJSON);
124
+ if (!this.mapsService) return;
125
+ const geoJSON = this.getMaskGeoData();
126
+ (_this$maskLayer = this.maskLayer) === null || _this$maskLayer === void 0 || _this$maskLayer.setData(geoJSON);
141
127
  });
142
- return _this;
143
128
  }
144
- (0, _createClass2.default)(Swipe, [{
145
- key: "getDefault",
146
- value:
147
- /**
148
- * 掩膜图层实例
149
- */
129
+ getDefault() {
130
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault()), {}, {
131
+ layers: [],
132
+ rightLayers: [],
133
+ ratio: 0.5,
134
+ orientation: 'vertical'
135
+ });
136
+ }
137
+ onAdd() {
138
+ const container = _l7Utils.DOM.create('div', 'l7-control-swipe');
139
+ _l7Utils.DOM.create('button', 'l7-control-swipe__button', container);
140
+ const {
141
+ orientation = 'vertical',
142
+ ratio = 0.5
143
+ } = this.controlOption;
144
+ if (orientation === 'horizontal') {
145
+ container.style.top = ratio * 100 + '%';
146
+ container.style.left = '';
147
+ } else {
148
+ container.style.left = ratio * 100 + '%';
149
+ container.style.top = '';
150
+ }
151
+ container.classList.add(orientation);
152
+ return container;
153
+ }
154
+ addTo(sceneContainer) {
155
+ // 初始化各个 Service 实例
156
+ this.mapsService = sceneContainer.mapService;
157
+ this.renderService = sceneContainer.rendererService;
158
+ this.layerService = sceneContainer.layerService;
159
+ this.controlService = sceneContainer.controlService;
160
+ this.configService = sceneContainer.globalConfigService;
161
+ this.scene = sceneContainer.sceneService;
162
+ this.sceneContainer = sceneContainer;
163
+ this.isShow = true;
150
164
 
151
- function getDefault() {
152
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(Swipe.prototype), "getDefault", this).call(this)), {}, {
153
- layers: [],
154
- rightLayers: [],
155
- ratio: 0.5,
156
- orientation: 'vertical'
157
- });
165
+ // 初始化 container
166
+ this.container = this.onAdd();
167
+ const {
168
+ className,
169
+ style,
170
+ layers,
171
+ rightLayers
172
+ } = this.controlOption;
173
+ if (className) {
174
+ this.setClassName(className);
158
175
  }
159
- }, {
160
- key: "onAdd",
161
- value: function onAdd() {
162
- var container = _l7Utils.DOM.create('div', 'l7-control-swipe');
163
- _l7Utils.DOM.create('button', 'l7-control-swipe__button', container);
164
- var _this$controlOption = this.controlOption,
165
- _this$controlOption$o = _this$controlOption.orientation,
166
- orientation = _this$controlOption$o === void 0 ? 'vertical' : _this$controlOption$o,
167
- _this$controlOption$r = _this$controlOption.ratio,
168
- ratio = _this$controlOption$r === void 0 ? 0.5 : _this$controlOption$r;
169
- if (orientation === 'horizontal') {
170
- container.style.top = ratio * 100 + '%';
171
- container.style.left = '';
172
- } else {
173
- container.style.left = ratio * 100 + '%';
174
- container.style.top = '';
175
- }
176
- container.classList.add(orientation);
177
- return container;
176
+ if (style) {
177
+ this.setStyle(style);
178
178
  }
179
- }, {
180
- key: "addTo",
181
- value: function addTo(sceneContainer) {
182
- // 初始化各个 Service 实例
183
- this.mapsService = sceneContainer.mapService;
184
- this.renderService = sceneContainer.rendererService;
185
- this.layerService = sceneContainer.layerService;
186
- this.controlService = sceneContainer.controlService;
187
- this.configService = sceneContainer.globalConfigService;
188
- this.scene = sceneContainer.sceneService;
189
- this.sceneContainer = sceneContainer;
190
- this.isShow = true;
191
179
 
192
- // 初始化 container
193
- this.container = this.onAdd();
194
- var _this$controlOption2 = this.controlOption,
195
- className = _this$controlOption2.className,
196
- style = _this$controlOption2.style,
197
- layers = _this$controlOption2.layers,
198
- rightLayers = _this$controlOption2.rightLayers;
199
- if (className) {
200
- this.setClassName(className);
201
- }
202
- if (style) {
203
- this.setStyle(style);
204
- }
180
+ // container 插入容器中
181
+ // this.scene.getSceneContainer().appendChild(this.container);
182
+ this.mapsService.getMarkerContainer().appendChild(this.container);
183
+ this.maskLayer = this.getMaskLayer();
184
+ this.registerEvent();
205
185
 
206
- // container 插入容器中
207
- // this.scene.getSceneContainer().appendChild(this.container);
208
- this.mapsService.getMarkerContainer().appendChild(this.container);
209
- this.maskLayer = this.getMaskLayer();
210
- this.registerEvent();
186
+ // 添加掩膜图层到 scene
187
+ const layerContainer = (0, _l7Core.createLayerContainer)(sceneContainer);
188
+ this.maskLayer.setContainer(layerContainer);
189
+ this.scene.addLayer(this.maskLayer);
211
190
 
212
- // 添加掩膜图层到 scene
213
- var layerContainer = (0, _l7Core.createLayerContainer)(sceneContainer);
214
- this.maskLayer.setContainer(layerContainer);
215
- this.scene.addLayer(this.maskLayer);
216
-
217
- // 给图层挂载掩膜
218
- this.addMaskToLayers(layers, false);
219
- this.addMaskToLayers(rightLayers, true);
220
- this.emit('add', this);
221
- return this;
222
- }
223
- }, {
224
- key: "onRemove",
225
- value: function onRemove() {
226
- if (this.maskLayer) {
227
- var _this$layerService;
228
- var _this$controlOption3 = this.controlOption,
229
- layers = _this$controlOption3.layers,
230
- rightLayers = _this$controlOption3.rightLayers;
231
- this.removeMaskFromLayers(layers);
232
- this.removeMaskFromLayers(rightLayers);
233
- (_this$layerService = this.layerService) === null || _this$layerService === void 0 || _this$layerService.remove(this.maskLayer);
234
- }
235
- this.unRegisterEvent();
236
- this.removeAllListeners();
237
- }
238
- }, {
239
- key: "show",
240
- value: function show() {
241
- var _this$scene2;
242
- var container = this.container;
243
- _l7Utils.DOM.removeClass(container, 'l7-control-swipe_hide');
244
- // 启用掩膜
245
- var _this$controlOption4 = this.controlOption,
246
- layers = _this$controlOption4.layers,
247
- rightLayers = _this$controlOption4.rightLayers;
248
- layers.forEach(function (layer) {
249
- return layer.enableMask();
250
- });
251
- rightLayers.forEach(function (layer) {
252
- return layer.enableMask();
253
- });
254
- (_this$scene2 = this.scene) === null || _this$scene2 === void 0 || _this$scene2.render();
255
- this.isShow = true;
256
- this.emit('show', this);
191
+ // 给图层挂载掩膜
192
+ this.addMaskToLayers(layers, false);
193
+ this.addMaskToLayers(rightLayers, true);
194
+ this.emit('add', this);
195
+ return this;
196
+ }
197
+ onRemove() {
198
+ if (this.maskLayer) {
199
+ var _this$layerService;
200
+ const {
201
+ layers,
202
+ rightLayers
203
+ } = this.controlOption;
204
+ this.removeMaskFromLayers(layers);
205
+ this.removeMaskFromLayers(rightLayers);
206
+ (_this$layerService = this.layerService) === null || _this$layerService === void 0 || _this$layerService.remove(this.maskLayer);
257
207
  }
258
- }, {
259
- key: "hide",
260
- value: function hide() {
261
- var _this$scene3;
262
- var container = this.container;
263
- _l7Utils.DOM.addClass(container, 'l7-control-swipe_hide');
264
- // 禁用掩膜
265
- var _this$controlOption5 = this.controlOption,
266
- layers = _this$controlOption5.layers,
267
- rightLayers = _this$controlOption5.rightLayers;
268
- layers.forEach(function (layer) {
269
- return layer.disableMask();
270
- });
271
- rightLayers.forEach(function (layer) {
272
- return layer.disableMask();
273
- });
274
- (_this$scene3 = this.scene) === null || _this$scene3 === void 0 || _this$scene3.render();
275
- this.isShow = false;
276
- this.emit('hide', this);
208
+ this.unRegisterEvent();
209
+ this.removeAllListeners();
210
+ }
211
+ show() {
212
+ var _this$scene2;
213
+ const container = this.container;
214
+ _l7Utils.DOM.removeClass(container, 'l7-control-swipe_hide');
215
+ // 启用掩膜
216
+ const {
217
+ layers,
218
+ rightLayers
219
+ } = this.controlOption;
220
+ layers.forEach(layer => layer.enableMask());
221
+ rightLayers.forEach(layer => layer.enableMask());
222
+ (_this$scene2 = this.scene) === null || _this$scene2 === void 0 || _this$scene2.render();
223
+ this.isShow = true;
224
+ this.emit('show', this);
225
+ }
226
+ hide() {
227
+ var _this$scene3;
228
+ const container = this.container;
229
+ _l7Utils.DOM.addClass(container, 'l7-control-swipe_hide');
230
+ // 禁用掩膜
231
+ const {
232
+ layers,
233
+ rightLayers
234
+ } = this.controlOption;
235
+ layers.forEach(layer => layer.disableMask());
236
+ rightLayers.forEach(layer => layer.disableMask());
237
+ (_this$scene3 = this.scene) === null || _this$scene3 === void 0 || _this$scene3.render();
238
+ this.isShow = false;
239
+ this.emit('hide', this);
240
+ }
241
+ setOptions(newOptions) {
242
+ const controlOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.controlOption), newOptions);
243
+ if (newOptions.className) {
244
+ this.setClassName(newOptions.className);
277
245
  }
278
- }, {
279
- key: "setOptions",
280
- value: function setOptions(newOptions) {
281
- var controlOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.controlOption), newOptions);
282
- if (newOptions.className) {
283
- this.setClassName(newOptions.className);
284
- }
285
- if (newOptions.style) {
286
- this.setStyle(newOptions.style);
287
- }
288
- if (newOptions.orientation || newOptions.ratio !== undefined) {
289
- this.setOrientationAndRatio(controlOption.orientation, controlOption.ratio);
290
- }
291
- if (newOptions.layers) {
292
- var newLayers = newOptions.layers;
293
- var oldLayers = this.controlOption.layers;
294
- this.setLayers(newLayers, oldLayers, false);
295
- }
296
- if (newOptions.rightLayers) {
297
- var _newLayers = newOptions.rightLayers;
298
- var _oldLayers = this.controlOption.rightLayers;
299
- this.setLayers(_newLayers, _oldLayers, true);
300
- }
301
- this.controlOption = controlOption;
302
- this.updateMask();
246
+ if (newOptions.style) {
247
+ this.setStyle(newOptions.style);
303
248
  }
304
- }, {
305
- key: "registerEvent",
306
- value: function registerEvent() {
307
- this.container.addEventListener('mousedown', this.move);
308
- this.container.addEventListener('touchstart', this.move);
309
- this.mapsService.on('camerachange', this.updateMask);
249
+ if (newOptions.orientation || newOptions.ratio !== undefined) {
250
+ this.setOrientationAndRatio(controlOption.orientation, controlOption.ratio);
310
251
  }
311
- }, {
312
- key: "unRegisterEvent",
313
- value: function unRegisterEvent() {
314
- var _this$mapsService;
315
- this.container.removeEventListener('mousedown', this.move);
316
- this.container.removeEventListener('touchstart', this.move);
317
- (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 || _this$mapsService.off('camerachange', this.updateMask);
252
+ if (newOptions.layers) {
253
+ const newLayers = newOptions.layers;
254
+ const oldLayers = this.controlOption.layers;
255
+ this.setLayers(newLayers, oldLayers, false);
318
256
  }
319
- }, {
320
- key: "setOrientationAndRatio",
321
- value: function setOrientationAndRatio() {
322
- var orientation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'vertical';
323
- var ratio = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.5;
324
- this.container.classList.remove('horizontal', 'vertical');
325
- this.container.classList.add(orientation);
326
- if (orientation === 'horizontal') {
327
- this.container.style.top = ratio * 100 + '%';
328
- this.container.style.left = '';
329
- } else {
330
- this.container.style.left = ratio * 100 + '%';
331
- this.container.style.top = '';
332
- }
257
+ if (newOptions.rightLayers) {
258
+ const newLayers = newOptions.rightLayers;
259
+ const oldLayers = this.controlOption.rightLayers;
260
+ this.setLayers(newLayers, oldLayers, true);
333
261
  }
334
- }, {
335
- key: "setLayers",
336
- value: function setLayers(newLayers, oldLayers) {
337
- var isRightLayer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
338
- var addLayers = newLayers.filter(function (layer) {
339
- return oldLayers.includes(layer) === false;
340
- });
341
- var removeLayers = oldLayers.filter(function (layer) {
342
- return newLayers.includes(layer) === false;
343
- });
344
- this.addMaskToLayers(addLayers, isRightLayer);
345
- this.removeMaskFromLayers(removeLayers);
262
+ this.controlOption = controlOption;
263
+ this.updateMask();
264
+ }
265
+ registerEvent() {
266
+ this.container.addEventListener('mousedown', this.move);
267
+ this.container.addEventListener('touchstart', this.move);
268
+ this.mapsService.on('camerachange', this.updateMask);
269
+ }
270
+ unRegisterEvent() {
271
+ var _this$mapsService;
272
+ this.container.removeEventListener('mousedown', this.move);
273
+ this.container.removeEventListener('touchstart', this.move);
274
+ (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 || _this$mapsService.off('camerachange', this.updateMask);
275
+ }
276
+ setOrientationAndRatio(orientation = 'vertical', ratio = 0.5) {
277
+ this.container.classList.remove('horizontal', 'vertical');
278
+ this.container.classList.add(orientation);
279
+ if (orientation === 'horizontal') {
280
+ this.container.style.top = ratio * 100 + '%';
281
+ this.container.style.left = '';
282
+ } else {
283
+ this.container.style.left = ratio * 100 + '%';
284
+ this.container.style.top = '';
346
285
  }
347
- }, {
348
- key: "addMaskToLayers",
349
- value: function addMaskToLayers(layers, isRightLayer) {
350
- var _this2 = this;
351
- layers.forEach(function (layer) {
352
- layer.updateLayerConfig({
353
- maskInside: isRightLayer ? false : true
354
- });
355
- layer.addMask(_this2.maskLayer);
286
+ }
287
+ setLayers(newLayers, oldLayers, isRightLayer = false) {
288
+ const addLayers = newLayers.filter(layer => oldLayers.includes(layer) === false);
289
+ const removeLayers = oldLayers.filter(layer => newLayers.includes(layer) === false);
290
+ this.addMaskToLayers(addLayers, isRightLayer);
291
+ this.removeMaskFromLayers(removeLayers);
292
+ }
293
+ addMaskToLayers(layers, isRightLayer) {
294
+ layers.forEach(layer => {
295
+ layer.updateLayerConfig({
296
+ maskInside: isRightLayer ? false : true
356
297
  });
357
- }
358
- }, {
359
- key: "removeMaskFromLayers",
360
- value: function removeMaskFromLayers(layers) {
361
- var _this3 = this;
362
- layers.forEach(function (layer) {
363
- // reset default is true
364
- layer.updateLayerConfig({
365
- maskInside: true
366
- });
367
- layer.removeMask(_this3.maskLayer);
298
+ layer.addMask(this.maskLayer);
299
+ });
300
+ }
301
+ removeMaskFromLayers(layers) {
302
+ layers.forEach(layer => {
303
+ // reset default is true
304
+ layer.updateLayerConfig({
305
+ maskInside: true
368
306
  });
307
+ layer.removeMask(this.maskLayer);
308
+ });
309
+ }
310
+ getMaskGeoData() {
311
+ const {
312
+ ratio = 0.5,
313
+ orientation = 'vertical'
314
+ } = this.controlOption;
315
+ const isVertical = orientation === 'vertical';
316
+ const [sw, ne] = this.getBounds();
317
+ const [swLng, swLat] = sw;
318
+ const [neLng, neLat] = ne;
319
+ let coordinate;
320
+ if (isVertical) {
321
+ const centerLng = swLng + (neLng - swLng) * ratio;
322
+ coordinate = [[swLng, neLat], [centerLng, neLat], [centerLng, swLat], sw, [swLng, neLat]];
323
+ } else {
324
+ const size = this.getContainerSize();
325
+ const lngLat = this.mapsService.containerToLngLat([size[0], size[1] * ratio]);
326
+ const centerLat = lngLat.lat;
327
+ coordinate = [[swLng, neLat], ne, [neLng, centerLat], [swLng, centerLat], [swLng, neLat]];
369
328
  }
370
- }, {
371
- key: "getMaskGeoData",
372
- value: function getMaskGeoData() {
373
- var _this$controlOption6 = this.controlOption,
374
- _this$controlOption6$ = _this$controlOption6.ratio,
375
- ratio = _this$controlOption6$ === void 0 ? 0.5 : _this$controlOption6$,
376
- _this$controlOption6$2 = _this$controlOption6.orientation,
377
- orientation = _this$controlOption6$2 === void 0 ? 'vertical' : _this$controlOption6$2;
378
- var isVertical = orientation === 'vertical';
379
- var _this$getBounds = this.getBounds(),
380
- _this$getBounds2 = (0, _slicedToArray2.default)(_this$getBounds, 2),
381
- sw = _this$getBounds2[0],
382
- ne = _this$getBounds2[1];
383
- var _sw = (0, _slicedToArray2.default)(sw, 2),
384
- swLng = _sw[0],
385
- swLat = _sw[1];
386
- var _ne = (0, _slicedToArray2.default)(ne, 2),
387
- neLng = _ne[0],
388
- neLat = _ne[1];
389
- var coordinate;
390
- if (isVertical) {
391
- var centerLng = swLng + (neLng - swLng) * ratio;
392
- coordinate = [[swLng, neLat], [centerLng, neLat], [centerLng, swLat], sw, [swLng, neLat]];
393
- } else {
394
- var size = this.getContainerSize();
395
- var lngLat = this.mapsService.containerToLngLat([size[0], size[1] * ratio]);
396
- var centerLat = lngLat.lat;
397
- coordinate = [[swLng, neLat], ne, [neLng, centerLat], [swLng, centerLat], [swLng, neLat]];
398
- }
399
- var geoJSON = {
400
- type: 'FeatureCollection',
401
- features: [{
402
- type: 'Feature',
403
- properties: {},
404
- geometry: {
405
- type: 'Polygon',
406
- coordinates: [coordinate]
407
- }
408
- }]
409
- };
410
- return geoJSON;
411
- }
412
- }, {
413
- key: "getContainerDOMRect",
414
- value: function getContainerDOMRect() {
415
- var _this$mapsService$get;
416
- var rect = (_this$mapsService$get = this.mapsService.getContainer()) === null || _this$mapsService$get === void 0 ? void 0 : _this$mapsService$get.getBoundingClientRect();
417
- return rect;
418
- }
419
- }, {
420
- key: "getContainerSize",
421
- value: function getContainerSize() {
422
- var size = this.mapsService.getSize();
423
- return size;
424
- }
425
- }, {
426
- key: "getBounds",
427
- value: function getBounds() {
428
- var bounds = this.mapsService.getBounds();
429
- return bounds;
430
- }
431
-
432
- /**
433
- * 添加要剪裁的图层
434
- * @param layer 剪裁的图层
435
- * @param addRight 是否添加图层到右侧, 默认添加到左侧.
436
- */
437
- }, {
438
- key: "addLayer",
439
- value: function addLayer(layer) {
440
- var addRight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
441
- var layers = Array.isArray(layer) ? layer : [layer];
442
- if (addRight) {
443
- var _this$controlOption$r2;
444
- var rightLayers = (_this$controlOption$r2 = this.controlOption.rightLayers).concat.apply(_this$controlOption$r2, (0, _toConsumableArray2.default)(layers));
445
- this.setOptions({
446
- rightLayers: rightLayers
447
- });
448
- } else {
449
- var _this$controlOption$l;
450
- var leftLayers = (_this$controlOption$l = this.controlOption.layers).concat.apply(_this$controlOption$l, (0, _toConsumableArray2.default)(layers));
451
- this.setOptions({
452
- layers: leftLayers
453
- });
454
- }
455
- }
329
+ const geoJSON = {
330
+ type: 'FeatureCollection',
331
+ features: [{
332
+ type: 'Feature',
333
+ properties: {},
334
+ geometry: {
335
+ type: 'Polygon',
336
+ coordinates: [coordinate]
337
+ }
338
+ }]
339
+ };
340
+ return geoJSON;
341
+ }
342
+ getContainerDOMRect() {
343
+ var _this$mapsService$get;
344
+ const rect = (_this$mapsService$get = this.mapsService.getContainer()) === null || _this$mapsService$get === void 0 ? void 0 : _this$mapsService$get.getBoundingClientRect();
345
+ return rect;
346
+ }
347
+ getContainerSize() {
348
+ const size = this.mapsService.getSize();
349
+ return size;
350
+ }
351
+ getBounds() {
352
+ const bounds = this.mapsService.getBounds();
353
+ return bounds;
354
+ }
456
355
 
457
- /**
458
- * 移除剪裁的图层
459
- */
460
- }, {
461
- key: "removeLayer",
462
- value: function removeLayer(layer) {
463
- var layers = Array.isArray(layer) ? layer : [layer];
464
- var leftLayers = this.controlOption.layers.filter(function (layer) {
465
- return layers.includes(layer);
466
- });
467
- var rightLayers = this.controlOption.rightLayers.filter(function (layer) {
468
- return layers.includes(layer);
469
- });
356
+ /**
357
+ * 添加要剪裁的图层
358
+ * @param layer 剪裁的图层
359
+ * @param addRight 是否添加图层到右侧, 默认添加到左侧.
360
+ */
361
+ addLayer(layer, addRight = false) {
362
+ const layers = Array.isArray(layer) ? layer : [layer];
363
+ if (addRight) {
364
+ const rightLayers = this.controlOption.rightLayers.concat(...layers);
470
365
  this.setOptions({
471
- layers: leftLayers,
472
- rightLayers: rightLayers
366
+ rightLayers
473
367
  });
474
- }
475
-
476
- /**
477
- * 清除所有图层
478
- */
479
- }, {
480
- key: "removeLayers",
481
- value: function removeLayers() {
368
+ } else {
369
+ const leftLayers = this.controlOption.layers.concat(...layers);
482
370
  this.setOptions({
483
- layers: [],
484
- rightLayers: []
371
+ layers: leftLayers
485
372
  });
486
373
  }
487
- }]);
488
- return Swipe;
489
- }(_baseControl.Control);
374
+ }
375
+
376
+ /**
377
+ * 移除剪裁的图层
378
+ */
379
+ removeLayer(layer) {
380
+ const layers = Array.isArray(layer) ? layer : [layer];
381
+ const leftLayers = this.controlOption.layers.filter(layer => layers.includes(layer));
382
+ const rightLayers = this.controlOption.rightLayers.filter(layer => layers.includes(layer));
383
+ this.setOptions({
384
+ layers: leftLayers,
385
+ rightLayers
386
+ });
387
+ }
388
+
389
+ /**
390
+ * 清除所有图层
391
+ */
392
+ removeLayers() {
393
+ this.setOptions({
394
+ layers: [],
395
+ rightLayers: []
396
+ });
397
+ }
398
+ }
399
+ exports.default = exports.Swipe = Swipe;