@antv/l7-component 2.25.5 → 2.25.7

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 (151) hide show
  1. package/package.json +5 -5
  2. package/es/assets/iconfont/iconfont.d.ts +0 -21
  3. package/es/assets/iconfont/iconfont.js +0 -61
  4. package/es/constants/index.d.ts +0 -60
  5. package/es/constants/index.js +0 -60
  6. package/es/control/baseControl/buttonControl.d.ts +0 -60
  7. package/es/control/baseControl/buttonControl.js +0 -142
  8. package/es/control/baseControl/control.d.ts +0 -112
  9. package/es/control/baseControl/control.js +0 -256
  10. package/es/control/baseControl/index.d.ts +0 -4
  11. package/es/control/baseControl/index.js +0 -4
  12. package/es/control/baseControl/popperControl.d.ts +0 -28
  13. package/es/control/baseControl/popperControl.js +0 -92
  14. package/es/control/baseControl/selectControl.d.ts +0 -53
  15. package/es/control/baseControl/selectControl.js +0 -173
  16. package/es/control/exportImage.d.ts +0 -19
  17. package/es/control/exportImage.js +0 -73
  18. package/es/control/fullscreen.d.ts +0 -20
  19. package/es/control/fullscreen.js +0 -88
  20. package/es/control/geoLocate.d.ts +0 -17
  21. package/es/control/geoLocate.js +0 -60
  22. package/es/control/layerSwitch.d.ts +0 -27
  23. package/es/control/layerSwitch.js +0 -155
  24. package/es/control/logo.d.ts +0 -14
  25. package/es/control/logo.js +0 -49
  26. package/es/control/mapTheme.d.ts +0 -11
  27. package/es/control/mapTheme.js +0 -69
  28. package/es/control/mouseLocation.d.ts +0 -16
  29. package/es/control/mouseLocation.js +0 -52
  30. package/es/control/scale.d.ts +0 -35
  31. package/es/control/scale.js +0 -121
  32. package/es/control/swipe.d.ts +0 -66
  33. package/es/control/swipe.js +0 -392
  34. package/es/control/zoom.d.ts +0 -39
  35. package/es/control/zoom.js +0 -100
  36. package/es/css/button.less +0 -77
  37. package/es/css/control.less +0 -82
  38. package/es/css/index.css +0 -653
  39. package/es/css/index.less +0 -13
  40. package/es/css/l7.less +0 -69
  41. package/es/css/layerPopup.less +0 -9
  42. package/es/css/logo.less +0 -21
  43. package/es/css/mouseLocation.less +0 -9
  44. package/es/css/popper.less +0 -74
  45. package/es/css/popup.less +0 -176
  46. package/es/css/scale.less +0 -37
  47. package/es/css/select.less +0 -96
  48. package/es/css/swipe.less +0 -80
  49. package/es/css/variables.less +0 -29
  50. package/es/css/zoom.less +0 -34
  51. package/es/images/layers.png +0 -0
  52. package/es/images/layers.svg +0 -1
  53. package/es/images/logo.png +0 -0
  54. package/es/images/quanping.svg +0 -12
  55. package/es/index.d.ts +0 -19
  56. package/es/index.js +0 -708
  57. package/es/interface.d.ts +0 -29
  58. package/es/interface.js +0 -1
  59. package/es/marker-layer.d.ts +0 -46
  60. package/es/marker-layer.js +0 -509
  61. package/es/marker.d.ts +0 -66
  62. package/es/marker.js +0 -495
  63. package/es/popup/layerPopup.d.ts +0 -105
  64. package/es/popup/layerPopup.js +0 -341
  65. package/es/popup/popup.d.ts +0 -147
  66. package/es/popup/popup.js +0 -587
  67. package/es/utils/anchor.d.ts +0 -22
  68. package/es/utils/anchor.js +0 -31
  69. package/es/utils/eventManager.d.ts +0 -42
  70. package/es/utils/eventManager.js +0 -84
  71. package/es/utils/icon.d.ts +0 -1
  72. package/es/utils/icon.js +0 -12
  73. package/es/utils/popper.d.ts +0 -76
  74. package/es/utils/popper.js +0 -257
  75. package/es/utils/screenfull.d.ts +0 -2
  76. package/es/utils/screenfull.js +0 -106
  77. package/lib/assets/iconfont/iconfont.d.ts +0 -21
  78. package/lib/assets/iconfont/iconfont.js +0 -68
  79. package/lib/constants/index.d.ts +0 -60
  80. package/lib/constants/index.js +0 -66
  81. package/lib/control/baseControl/buttonControl.d.ts +0 -60
  82. package/lib/control/baseControl/buttonControl.js +0 -149
  83. package/lib/control/baseControl/control.d.ts +0 -112
  84. package/lib/control/baseControl/control.js +0 -269
  85. package/lib/control/baseControl/index.d.ts +0 -4
  86. package/lib/control/baseControl/index.js +0 -39
  87. package/lib/control/baseControl/popperControl.d.ts +0 -28
  88. package/lib/control/baseControl/popperControl.js +0 -99
  89. package/lib/control/baseControl/selectControl.d.ts +0 -53
  90. package/lib/control/baseControl/selectControl.js +0 -180
  91. package/lib/control/exportImage.d.ts +0 -19
  92. package/lib/control/exportImage.js +0 -80
  93. package/lib/control/fullscreen.d.ts +0 -20
  94. package/lib/control/fullscreen.js +0 -95
  95. package/lib/control/geoLocate.d.ts +0 -17
  96. package/lib/control/geoLocate.js +0 -67
  97. package/lib/control/layerSwitch.d.ts +0 -27
  98. package/lib/control/layerSwitch.js +0 -162
  99. package/lib/control/logo.d.ts +0 -14
  100. package/lib/control/logo.js +0 -55
  101. package/lib/control/mapTheme.d.ts +0 -11
  102. package/lib/control/mapTheme.js +0 -76
  103. package/lib/control/mouseLocation.d.ts +0 -16
  104. package/lib/control/mouseLocation.js +0 -59
  105. package/lib/control/scale.d.ts +0 -35
  106. package/lib/control/scale.js +0 -128
  107. package/lib/control/swipe.d.ts +0 -66
  108. package/lib/control/swipe.js +0 -399
  109. package/lib/control/zoom.d.ts +0 -39
  110. package/lib/control/zoom.js +0 -107
  111. package/lib/css/button.less +0 -77
  112. package/lib/css/control.less +0 -82
  113. package/lib/css/index.css +0 -653
  114. package/lib/css/index.less +0 -13
  115. package/lib/css/l7.less +0 -69
  116. package/lib/css/layerPopup.less +0 -9
  117. package/lib/css/logo.less +0 -21
  118. package/lib/css/mouseLocation.less +0 -9
  119. package/lib/css/popper.less +0 -74
  120. package/lib/css/popup.less +0 -176
  121. package/lib/css/scale.less +0 -37
  122. package/lib/css/select.less +0 -96
  123. package/lib/css/swipe.less +0 -80
  124. package/lib/css/variables.less +0 -29
  125. package/lib/css/zoom.less +0 -34
  126. package/lib/images/layers.png +0 -0
  127. package/lib/images/layers.svg +0 -1
  128. package/lib/images/logo.png +0 -0
  129. package/lib/images/quanping.svg +0 -12
  130. package/lib/index.d.ts +0 -19
  131. package/lib/index.js +0 -835
  132. package/lib/interface.d.ts +0 -29
  133. package/lib/interface.js +0 -5
  134. package/lib/marker-layer.d.ts +0 -46
  135. package/lib/marker-layer.js +0 -518
  136. package/lib/marker.d.ts +0 -66
  137. package/lib/marker.js +0 -502
  138. package/lib/popup/layerPopup.d.ts +0 -105
  139. package/lib/popup/layerPopup.js +0 -348
  140. package/lib/popup/popup.d.ts +0 -147
  141. package/lib/popup/popup.js +0 -594
  142. package/lib/utils/anchor.d.ts +0 -22
  143. package/lib/utils/anchor.js +0 -38
  144. package/lib/utils/eventManager.d.ts +0 -42
  145. package/lib/utils/eventManager.js +0 -92
  146. package/lib/utils/icon.d.ts +0 -1
  147. package/lib/utils/icon.js +0 -19
  148. package/lib/utils/popper.d.ts +0 -76
  149. package/lib/utils/popper.js +0 -264
  150. package/lib/utils/screenfull.d.ts +0 -2
  151. package/lib/utils/screenfull.js +0 -112
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.MouseLocation = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _l7Core = require("@antv/l7-core");
11
- var _l7Utils = require("@antv/l7-utils");
12
- var _control = _interopRequireDefault(require("./baseControl/control"));
13
- class MouseLocation extends _control.default {
14
- constructor(...args) {
15
- super(...args);
16
- (0, _defineProperty2.default)(this, "location", [0, 0]);
17
- (0, _defineProperty2.default)(this, "onMouseMove", e => {
18
- let position = this.location;
19
- // 适配不同底图,事件返回的数据名称不一致
20
- const lngLat = e.lngLat || e.lnglat;
21
- const {
22
- transform
23
- } = this.controlOption;
24
- if (lngLat) {
25
- position = [lngLat.lng, lngLat.lat];
26
- }
27
- this.location = position;
28
- if (transform) {
29
- position = transform(position);
30
- }
31
- this.insertLocation2HTML(position);
32
- this.emit('locationChange', position);
33
- });
34
- }
35
- getLocation() {
36
- return this.location;
37
- }
38
- getDefault(option) {
39
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
40
- position: _l7Core.PositionType.BOTTOMLEFT,
41
- transform: ([lng, lat]) => {
42
- return [+(+lng).toFixed(6), +(+lat).toFixed(6)];
43
- }
44
- });
45
- }
46
- onAdd() {
47
- const container = _l7Utils.DOM.create('div', 'l7-control-mouse-location');
48
- container.innerHTML = ' ';
49
- this.mapsService.on('mousemove', this.onMouseMove);
50
- return container;
51
- }
52
- onRemove() {
53
- this.mapsService.off('mousemove', this.onMouseMove);
54
- }
55
- insertLocation2HTML(position) {
56
- this.container.innerText = position.join(', ');
57
- }
58
- }
59
- exports.default = exports.MouseLocation = MouseLocation;
@@ -1,35 +0,0 @@
1
- import type { IControlOption } from './baseControl';
2
- import { Control, PositionType } from './baseControl';
3
- export interface IScaleControlOption extends IControlOption {
4
- lockWidth: boolean;
5
- maxWidth: number;
6
- metric: boolean;
7
- updateWhenIdle: boolean;
8
- imperial: boolean;
9
- }
10
- export { Scale };
11
- export default class Scale extends Control<IScaleControlOption> {
12
- private mScale;
13
- private iScale;
14
- getDefault(option: Partial<IScaleControlOption>): {
15
- name: string;
16
- position: PositionType;
17
- maxWidth: number;
18
- metric: boolean;
19
- updateWhenIdle: boolean;
20
- imperial: boolean;
21
- lockWidth: boolean;
22
- className?: string | undefined;
23
- style?: string | undefined;
24
- };
25
- onAdd(): HTMLElement;
26
- onRemove(): void;
27
- setOptions(newOption: Partial<IScaleControlOption>): void;
28
- update: () => void;
29
- updateScales(maxMeters: number): void;
30
- private resetScaleLines;
31
- private updateScale;
32
- private getRoundNum;
33
- private updateMetric;
34
- private updateImperial;
35
- }
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.Scale = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _l7Utils = require("@antv/l7-utils");
11
- var _baseControl = require("./baseControl");
12
- class Scale extends _baseControl.Control {
13
- constructor(...args) {
14
- super(...args);
15
- (0, _defineProperty2.default)(this, "mScale", void 0);
16
- (0, _defineProperty2.default)(this, "iScale", void 0);
17
- (0, _defineProperty2.default)(this, "update", () => {
18
- const mapsService = this.mapsService;
19
- const {
20
- maxWidth
21
- } = this.controlOption;
22
- const y = mapsService.getSize()[1] / 2;
23
- const p1 = mapsService.containerToLngLat([0, y]);
24
- const p2 = mapsService.containerToLngLat([maxWidth, y]);
25
- const maxMeters = (0, _l7Utils.lnglatDistance)([p1.lng, p1.lat], [p2.lng, p2.lat]);
26
- this.updateScales(maxMeters);
27
- });
28
- }
29
- getDefault(option) {
30
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
31
- name: 'scale',
32
- position: _baseControl.PositionType.BOTTOMLEFT,
33
- maxWidth: 100,
34
- metric: true,
35
- updateWhenIdle: false,
36
- imperial: false,
37
- lockWidth: true
38
- });
39
- }
40
- onAdd() {
41
- const className = 'l7-control-scale';
42
- const container = _l7Utils.DOM.create('div', className);
43
- this.resetScaleLines(container);
44
- const {
45
- updateWhenIdle
46
- } = this.controlOption;
47
- this.mapsService.on(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
48
- this.mapsService.on(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
49
- return container;
50
- }
51
- onRemove() {
52
- const {
53
- updateWhenIdle
54
- } = this.controlOption;
55
- this.mapsService.off(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
56
- this.mapsService.off(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
57
- }
58
- setOptions(newOption) {
59
- super.setOptions(newOption);
60
- if (this.checkUpdateOption(newOption, ['lockWidth', 'maxWidth', 'metric', 'updateWhenIdle', 'imperial'])) {
61
- this.resetScaleLines(this.container);
62
- }
63
- }
64
- updateScales(maxMeters) {
65
- const {
66
- metric,
67
- imperial
68
- } = this.controlOption;
69
- if (metric && maxMeters) {
70
- this.updateMetric(maxMeters);
71
- }
72
- if (imperial && maxMeters) {
73
- this.updateImperial(maxMeters);
74
- }
75
- }
76
- resetScaleLines(container) {
77
- _l7Utils.DOM.clearChildren(container);
78
- const {
79
- metric,
80
- imperial,
81
- maxWidth,
82
- lockWidth
83
- } = this.controlOption;
84
- if (lockWidth) {
85
- _l7Utils.DOM.addStyle(container, `width: ${maxWidth}px`);
86
- }
87
- if (metric) {
88
- this.mScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
89
- }
90
- if (imperial) {
91
- this.iScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
92
- }
93
- this.update();
94
- }
95
- updateScale(scale, text, ratio) {
96
- const {
97
- maxWidth
98
- } = this.controlOption;
99
- scale.style.width = Math.round(maxWidth * ratio) + 'px';
100
- scale.innerHTML = text;
101
- }
102
- getRoundNum(num) {
103
- const pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
104
- let d = num / pow10;
105
- d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
106
- return pow10 * d;
107
- }
108
- updateMetric(maxMeters) {
109
- const meters = this.getRoundNum(maxMeters);
110
- const label = meters < 1000 ? meters + ' m' : meters / 1000 + ' km';
111
- this.updateScale(this.mScale, label, meters / maxMeters);
112
- }
113
- updateImperial(maxMeters) {
114
- const maxFeet = maxMeters * 3.2808399;
115
- let maxMiles;
116
- let miles;
117
- let feet;
118
- if (maxFeet > 5280) {
119
- maxMiles = maxFeet / 5280;
120
- miles = this.getRoundNum(maxMiles);
121
- this.updateScale(this.iScale, miles + ' mi', miles / maxMiles);
122
- } else {
123
- feet = this.getRoundNum(maxFeet);
124
- this.updateScale(this.iScale, feet + ' ft', feet / maxFeet);
125
- }
126
- }
127
- }
128
- exports.default = exports.Scale = Scale;
@@ -1,66 +0,0 @@
1
- import type { ILayer, L7Container } from '@antv/l7-core';
2
- import type { IControlOption } from './baseControl';
3
- import { Control } from './baseControl';
4
- export interface ISwipeControlOption extends IControlOption {
5
- /**
6
- * 左侧的图层
7
- */
8
- layers: ILayer[];
9
- /**
10
- * 右侧的图层
11
- */
12
- rightLayers: ILayer[];
13
- /**
14
- * 设置卷帘的位置,值域为 0 到 1, 默认正中间为 0.5
15
- */
16
- ratio?: number;
17
- /**
18
- * 卷帘方向设置('vertical' | 'horizontal'),默认 'vertical'
19
- */
20
- orientation?: 'vertical' | 'horizontal';
21
- }
22
- export { Swipe };
23
- export default class Swipe extends Control<ISwipeControlOption> {
24
- /**
25
- * 是否正在拖动卷帘
26
- */
27
- private isMoving;
28
- /**
29
- * 掩模图层实例
30
- */
31
- private maskLayer;
32
- getDefault(): ISwipeControlOption;
33
- onAdd(): HTMLElement;
34
- addTo(sceneContainer: L7Container): this;
35
- onRemove(): void;
36
- show(): void;
37
- hide(): void;
38
- setOptions(newOptions: Partial<ISwipeControlOption>): void;
39
- private registerEvent;
40
- private unRegisterEvent;
41
- private setOrientationAndRatio;
42
- private setLayers;
43
- private addMaskToLayers;
44
- private removeMaskFromLayers;
45
- private move;
46
- private getMaskGeoData;
47
- private getMaskLayer;
48
- private updateMask;
49
- private getContainerDOMRect;
50
- private getContainerSize;
51
- private getBounds;
52
- /**
53
- * 添加要剪裁的图层
54
- * @param layer 剪裁的图层
55
- * @param addRight 是否添加图层到右侧, 默认添加到左侧.
56
- */
57
- addLayer(layer: ILayer | ILayer[], addRight?: boolean): void;
58
- /**
59
- * 移除剪裁的图层
60
- */
61
- removeLayer(layer: ILayer | ILayer[]): void;
62
- /**
63
- * 清除所有图层
64
- */
65
- removeLayers(): void;
66
- }
@@ -1,399 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.Swipe = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _l7Core = require("@antv/l7-core");
11
- var _l7Layers = require("@antv/l7-layers");
12
- var _l7Utils = require("@antv/l7-utils");
13
- var _baseControl = require("./baseControl");
14
- class Swipe extends _baseControl.Control {
15
- constructor(...args) {
16
- super(...args);
17
- /**
18
- * 是否正在拖动卷帘
19
- */
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 => {
26
- // 阻止事件冒泡到地图上
27
- e.stopPropagation();
28
- switch (e.type) {
29
- case 'touchcancel':
30
- case 'touchend':
31
- case 'mouseup':
32
- {
33
- var _this$scene;
34
- this.isMoving = false;
35
- ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(eventName => {
36
- document.removeEventListener(eventName, this.move);
37
- });
38
- (_this$scene = this.scene) === null || _this$scene === void 0 || _this$scene.render();
39
- break;
40
- }
41
- case 'mousedown':
42
- case 'touchstart':
43
- {
44
- this.isMoving = true;
45
- ['mouseup', 'mousemove', 'touchend', 'touchcancel', 'touchmove'].forEach(eventName => {
46
- document.addEventListener(eventName, this.move);
47
- });
48
- // fallthrough
49
- }
50
- case 'mousemove':
51
- case 'touchmove':
52
- {
53
- if (this.isMoving) {
54
- if (this.controlOption.orientation === 'vertical') {
55
- let pageX;
56
- if ('pageX' in e) {
57
- pageX = e.pageX;
58
- } else if (e.touches && e.touches.length && e.touches[0].pageX) {
59
- pageX = e.touches[0].pageX;
60
- } else if (e.changedTouches && e.changedTouches.length) {
61
- pageX = e.changedTouches[0].pageX;
62
- }
63
- if (!pageX) {
64
- break;
65
- }
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
75
- });
76
- this.emit('moving', {
77
- size: [width, containerSize[1]],
78
- ratio: [ratio, 0]
79
- });
80
- } else {
81
- let pageY;
82
- if ('pageY' in e) {
83
- pageY = e.pageY;
84
- } else if (e.touches && e.touches.length && e.touches[0].pageY) {
85
- pageY = e.touches[0].pageY;
86
- } else if (e.changedTouches && e.changedTouches.length) {
87
- pageY = e.changedTouches[0].pageY;
88
- }
89
- if (!pageY) {
90
- break;
91
- }
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
101
- });
102
- this.emit('moving', {
103
- size: [containerSize[0], height],
104
- ratio: [0, ratio]
105
- });
106
- }
107
- }
108
- break;
109
- }
110
- default:
111
- break;
112
- }
113
- });
114
- (0, _defineProperty2.default)(this, "getMaskLayer", () => {
115
- console.log(this.getMaskGeoData());
116
- return new _l7Layers.PolygonLayer({
117
- visible: false
118
- }).source(this.getMaskGeoData()).shape('fill').color('red').style({
119
- opacity: 0.1
120
- });
121
- });
122
- (0, _defineProperty2.default)(this, "updateMask", () => {
123
- var _this$maskLayer;
124
- if (!this.mapsService) return;
125
- const geoJSON = this.getMaskGeoData();
126
- (_this$maskLayer = this.maskLayer) === null || _this$maskLayer === void 0 || _this$maskLayer.setData(geoJSON);
127
- });
128
- }
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;
164
-
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);
175
- }
176
- if (style) {
177
- this.setStyle(style);
178
- }
179
-
180
- // 将 container 插入容器中
181
- // this.scene.getSceneContainer().appendChild(this.container);
182
- this.mapsService.getMarkerContainer().appendChild(this.container);
183
- this.maskLayer = this.getMaskLayer();
184
- this.registerEvent();
185
-
186
- // 添加掩模图层到 scene
187
- const layerContainer = (0, _l7Core.createLayerContainer)(sceneContainer);
188
- this.maskLayer.setContainer(layerContainer);
189
- this.scene.addLayer(this.maskLayer);
190
-
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);
207
- }
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);
245
- }
246
- if (newOptions.style) {
247
- this.setStyle(newOptions.style);
248
- }
249
- if (newOptions.orientation || newOptions.ratio !== undefined) {
250
- this.setOrientationAndRatio(controlOption.orientation, controlOption.ratio);
251
- }
252
- if (newOptions.layers) {
253
- const newLayers = newOptions.layers;
254
- const oldLayers = this.controlOption.layers;
255
- this.setLayers(newLayers, oldLayers, false);
256
- }
257
- if (newOptions.rightLayers) {
258
- const newLayers = newOptions.rightLayers;
259
- const oldLayers = this.controlOption.rightLayers;
260
- this.setLayers(newLayers, oldLayers, true);
261
- }
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 = '';
285
- }
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
297
- });
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
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]];
328
- }
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
- }
355
-
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);
365
- this.setOptions({
366
- rightLayers
367
- });
368
- } else {
369
- const leftLayers = this.controlOption.layers.concat(...layers);
370
- this.setOptions({
371
- layers: leftLayers
372
- });
373
- }
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;