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