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