@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
@@ -0,0 +1,16 @@
1
+ import type { Position } from '@antv/l7-core';
2
+ import type { IControlOption } from './baseControl/control';
3
+ import Control from './baseControl/control';
4
+ export interface IMouseLocationControlOption extends IControlOption {
5
+ transform: (position: Position) => Position;
6
+ }
7
+ export { MouseLocation };
8
+ export default class MouseLocation extends Control<IMouseLocationControlOption> {
9
+ protected location: Position;
10
+ getLocation(): Position;
11
+ getDefault(option?: Partial<IMouseLocationControlOption>): IMouseLocationControlOption;
12
+ onAdd(): HTMLElement;
13
+ onRemove(): void;
14
+ protected onMouseMove: (e: any) => void;
15
+ protected insertLocation2HTML(position: Position): void;
16
+ }
@@ -5,84 +5,54 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.MouseLocation = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
13
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
16
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
10
  var _l7Core = require("@antv/l7-core");
19
11
  var _l7Utils = require("@antv/l7-utils");
20
12
  var _control = _interopRequireDefault(require("./baseControl/control"));
21
- 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); }; }
22
- 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; } }
23
- var MouseLocation = exports.default = exports.MouseLocation = /*#__PURE__*/function (_Control) {
24
- (0, _inherits2.default)(MouseLocation, _Control);
25
- var _super = _createSuper(MouseLocation);
26
- function MouseLocation() {
27
- var _this;
28
- (0, _classCallCheck2.default)(this, MouseLocation);
29
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
- args[_key] = arguments[_key];
31
- }
32
- _this = _super.call.apply(_super, [this].concat(args));
33
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "location", [0, 0]);
34
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseMove", function (e) {
35
- var position = _this.location;
36
- var lngLat = e.lngLat || e.lnglat;
37
- var transform = _this.controlOption.transform;
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
+ const lngLat = e.lngLat || e.lnglat;
20
+ const {
21
+ transform
22
+ } = this.controlOption;
38
23
  if (lngLat) {
39
24
  position = [lngLat.lng, lngLat.lat];
40
25
  }
41
- _this.location = position;
26
+ this.location = position;
42
27
  if (transform) {
43
28
  position = transform(position);
44
29
  }
45
- _this.insertLocation2HTML(position);
46
- _this.emit('locationChange', position);
30
+ this.insertLocation2HTML(position);
31
+ this.emit('locationChange', position);
47
32
  });
48
- return _this;
49
33
  }
50
- (0, _createClass2.default)(MouseLocation, [{
51
- key: "getLocation",
52
- value: function getLocation() {
53
- return this.location;
54
- }
55
- }, {
56
- key: "getDefault",
57
- value: function getDefault(option) {
58
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(MouseLocation.prototype), "getDefault", this).call(this, option)), {}, {
59
- position: _l7Core.PositionType.BOTTOMLEFT,
60
- transform: function transform(_ref) {
61
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
62
- lng = _ref2[0],
63
- lat = _ref2[1];
64
- return [+(+lng).toFixed(6), +(+lat).toFixed(6)];
65
- }
66
- });
67
- }
68
- }, {
69
- key: "onAdd",
70
- value: function onAdd() {
71
- var container = _l7Utils.DOM.create('div', 'l7-control-mouse-location');
72
- container.innerHTML = '&nbsp;';
73
- this.mapsService.on('mousemove', this.onMouseMove);
74
- return container;
75
- }
76
- }, {
77
- key: "onRemove",
78
- value: function onRemove() {
79
- this.mapsService.off('mousemove', this.onMouseMove);
80
- }
81
- }, {
82
- key: "insertLocation2HTML",
83
- value: function insertLocation2HTML(position) {
84
- this.container.innerText = position.join(', ');
85
- }
86
- }]);
87
- return MouseLocation;
88
- }(_control.default);
34
+ getLocation() {
35
+ return this.location;
36
+ }
37
+ getDefault(option) {
38
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
39
+ position: _l7Core.PositionType.BOTTOMLEFT,
40
+ transform: ([lng, lat]) => {
41
+ return [+(+lng).toFixed(6), +(+lat).toFixed(6)];
42
+ }
43
+ });
44
+ }
45
+ onAdd() {
46
+ const container = _l7Utils.DOM.create('div', 'l7-control-mouse-location');
47
+ container.innerHTML = '&nbsp;';
48
+ this.mapsService.on('mousemove', this.onMouseMove);
49
+ return container;
50
+ }
51
+ onRemove() {
52
+ this.mapsService.off('mousemove', this.onMouseMove);
53
+ }
54
+ insertLocation2HTML(position) {
55
+ this.container.innerText = position.join(', ');
56
+ }
57
+ }
58
+ exports.default = exports.MouseLocation = MouseLocation;
@@ -0,0 +1,35 @@
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
+ }
@@ -6,149 +6,123 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.Scale = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
10
  var _l7Utils = require("@antv/l7-utils");
18
11
  var _baseControl = require("./baseControl");
19
- 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); }; }
20
- 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; } }
21
- var Scale = exports.default = exports.Scale = /*#__PURE__*/function (_Control) {
22
- (0, _inherits2.default)(Scale, _Control);
23
- var _super = _createSuper(Scale);
24
- function Scale() {
25
- var _this;
26
- (0, _classCallCheck2.default)(this, Scale);
27
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
28
- args[_key] = arguments[_key];
29
- }
30
- _this = _super.call.apply(_super, [this].concat(args));
31
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "update", function () {
32
- var mapsService = _this.mapsService;
33
- var maxWidth = _this.controlOption.maxWidth;
34
- var y = mapsService.getSize()[1] / 2;
35
- var p1 = mapsService.containerToLngLat([0, y]);
36
- var p2 = mapsService.containerToLngLat([maxWidth, y]);
37
- var maxMeters = (0, _l7Utils.lnglatDistance)([p1.lng, p1.lat], [p2.lng, p2.lat]);
38
- _this.updateScales(maxMeters);
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);
39
27
  });
40
- return _this;
41
28
  }
42
- (0, _createClass2.default)(Scale, [{
43
- key: "getDefault",
44
- value: function getDefault(option) {
45
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _get2.default)((0, _getPrototypeOf2.default)(Scale.prototype), "getDefault", this).call(this, option)), {}, {
46
- name: 'scale',
47
- position: _baseControl.PositionType.BOTTOMLEFT,
48
- maxWidth: 100,
49
- metric: true,
50
- updateWhenIdle: false,
51
- imperial: false,
52
- lockWidth: true
53
- });
54
- }
55
- }, {
56
- key: "onAdd",
57
- value: function onAdd() {
58
- var className = 'l7-control-scale';
59
- var container = _l7Utils.DOM.create('div', className);
60
- this.resetScaleLines(container);
61
- var updateWhenIdle = this.controlOption.updateWhenIdle;
62
- this.mapsService.on(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
63
- this.mapsService.on(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
64
- return container;
65
- }
66
- }, {
67
- key: "onRemove",
68
- value: function onRemove() {
69
- var updateWhenIdle = this.controlOption.updateWhenIdle;
70
- this.mapsService.off(updateWhenIdle ? 'zoomend' : 'zoomchange', this.update);
71
- this.mapsService.off(updateWhenIdle ? 'moveend' : 'mapmove', this.update);
72
- }
73
- }, {
74
- key: "setOptions",
75
- value: function setOptions(newOption) {
76
- (0, _get2.default)((0, _getPrototypeOf2.default)(Scale.prototype), "setOptions", this).call(this, newOption);
77
- if (this.checkUpdateOption(newOption, ['lockWidth', 'maxWidth', 'metric', 'updateWhenIdle', 'imperial'])) {
78
- this.resetScaleLines(this.container);
79
- }
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);
80
62
  }
81
- }, {
82
- key: "updateScales",
83
- value: function updateScales(maxMeters) {
84
- var _this$controlOption = this.controlOption,
85
- metric = _this$controlOption.metric,
86
- imperial = _this$controlOption.imperial;
87
- if (metric && maxMeters) {
88
- this.updateMetric(maxMeters);
89
- }
90
- if (imperial && maxMeters) {
91
- this.updateImperial(maxMeters);
92
- }
63
+ }
64
+ updateScales(maxMeters) {
65
+ const {
66
+ metric,
67
+ imperial
68
+ } = this.controlOption;
69
+ if (metric && maxMeters) {
70
+ this.updateMetric(maxMeters);
93
71
  }
94
- }, {
95
- key: "resetScaleLines",
96
- value: function resetScaleLines(container) {
97
- _l7Utils.DOM.clearChildren(container);
98
- var _this$controlOption2 = this.controlOption,
99
- metric = _this$controlOption2.metric,
100
- imperial = _this$controlOption2.imperial,
101
- maxWidth = _this$controlOption2.maxWidth,
102
- lockWidth = _this$controlOption2.lockWidth;
103
- if (lockWidth) {
104
- _l7Utils.DOM.addStyle(container, "width: ".concat(maxWidth, "px"));
105
- }
106
- if (metric) {
107
- this.mScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
108
- }
109
- if (imperial) {
110
- this.iScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
111
- }
112
- this.update();
72
+ if (imperial && maxMeters) {
73
+ this.updateImperial(maxMeters);
113
74
  }
114
- }, {
115
- key: "updateScale",
116
- value: function updateScale(scale, text, ratio) {
117
- var maxWidth = this.controlOption.maxWidth;
118
- scale.style.width = Math.round(maxWidth * ratio) + 'px';
119
- scale.innerHTML = text;
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`);
120
86
  }
121
- }, {
122
- key: "getRoundNum",
123
- value: function getRoundNum(num) {
124
- var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
125
- var d = num / pow10;
126
- d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
127
- return pow10 * d;
87
+ if (metric) {
88
+ this.mScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
128
89
  }
129
- }, {
130
- key: "updateMetric",
131
- value: function updateMetric(maxMeters) {
132
- var meters = this.getRoundNum(maxMeters);
133
- var label = meters < 1000 ? meters + ' m' : meters / 1000 + ' km';
134
- this.updateScale(this.mScale, label, meters / maxMeters);
90
+ if (imperial) {
91
+ this.iScale = _l7Utils.DOM.create('div', 'l7-control-scale-line', container);
135
92
  }
136
- }, {
137
- key: "updateImperial",
138
- value: function updateImperial(maxMeters) {
139
- var maxFeet = maxMeters * 3.2808399;
140
- var maxMiles;
141
- var miles;
142
- var feet;
143
- if (maxFeet > 5280) {
144
- maxMiles = maxFeet / 5280;
145
- miles = this.getRoundNum(maxMiles);
146
- this.updateScale(this.iScale, miles + ' mi', miles / maxMiles);
147
- } else {
148
- feet = this.getRoundNum(maxFeet);
149
- this.updateScale(this.iScale, feet + ' ft', feet / maxFeet);
150
- }
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);
151
125
  }
152
- }]);
153
- return Scale;
154
- }(_baseControl.Control);
126
+ }
127
+ }
128
+ exports.default = exports.Scale = Scale;
@@ -0,0 +1,66 @@
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
+ }