@antv/l7-component 2.21.1 → 2.21.3

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