@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,156 +1,73 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
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
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
12
- import _regeneratorRuntime from "@babel/runtime/regenerator";
13
- 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); }; }
14
- 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; } }
15
4
  import { createL7Icon } from "../utils/icon";
16
5
  import ButtonControl from "./baseControl/buttonControl";
17
6
  export { ExportImage };
18
- var ExportImage = /*#__PURE__*/function (_ButtonControl) {
19
- _inherits(ExportImage, _ButtonControl);
20
- var _super = _createSuper(ExportImage);
21
- function ExportImage() {
7
+ export default class ExportImage extends ButtonControl {
8
+ constructor(...args) {
22
9
  var _this;
23
- _classCallCheck(this, ExportImage);
24
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
25
- args[_key] = arguments[_key];
26
- }
27
- _this = _super.call.apply(_super, [this].concat(args));
28
- _defineProperty(_assertThisInitialized(_this), "onClick", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
29
- var onExport;
30
- return _regeneratorRuntime.wrap(function _callee$(_context) {
31
- while (1) switch (_context.prev = _context.next) {
32
- case 0:
33
- onExport = _this.controlOption.onExport;
34
- _context.t0 = onExport === null || onExport === void 0;
35
- if (_context.t0) {
36
- _context.next = 8;
37
- break;
38
- }
39
- _context.t1 = onExport;
40
- _context.next = 6;
41
- return _this.getImage();
42
- case 6:
43
- _context.t2 = _context.sent;
44
- (0, _context.t1)(_context.t2);
45
- case 8:
46
- case "end":
47
- return _context.stop();
48
- }
49
- }, _callee);
50
- })));
10
+ super(...args);
11
+ _this = this;
12
+ _defineProperty(this, "onClick", /*#__PURE__*/_asyncToGenerator(function* () {
13
+ const {
14
+ onExport
15
+ } = _this.controlOption;
16
+ onExport === null || onExport === void 0 || onExport(yield _this.getImage());
17
+ }));
51
18
  /**
52
19
  * 将多张图片合并为一张图片
53
20
  * @protected
54
21
  * @param base64List
55
22
  */
56
- _defineProperty(_assertThisInitialized(_this), "mergeImage", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
23
+ _defineProperty(this, "mergeImage", /*#__PURE__*/_asyncToGenerator(function* (...base64List) {
57
24
  var _this$mapsService$get, _this$mapsService$get2;
58
- var imageType,
59
- _ref3,
60
- _ref3$width,
61
- width,
62
- _ref3$height,
63
- height,
64
- canvas,
65
- context,
66
- _len2,
67
- base64List,
68
- _key2,
69
- imgList,
70
- _args2 = arguments;
71
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
72
- while (1) switch (_context2.prev = _context2.next) {
73
- case 0:
74
- imageType = _this.controlOption.imageType;
75
- _ref3 = (_this$mapsService$get = (_this$mapsService$get2 = _this.mapsService.getContainer()) === null || _this$mapsService$get2 === void 0 ? void 0 : _this$mapsService$get2.getBoundingClientRect()) !== null && _this$mapsService$get !== void 0 ? _this$mapsService$get : {}, _ref3$width = _ref3.width, width = _ref3$width === void 0 ? 0 : _ref3$width, _ref3$height = _ref3.height, height = _ref3$height === void 0 ? 0 : _ref3$height;
76
- canvas = document.createElement('canvas');
77
- canvas.width = width;
78
- canvas.height = height;
79
- context = canvas.getContext('2d');
80
- for (_len2 = _args2.length, base64List = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
81
- base64List[_key2] = _args2[_key2];
82
- }
83
- _context2.next = 9;
84
- return Promise.all(base64List.map(function (base64) {
85
- return new Promise(function (resolve) {
86
- var img = new Image();
87
- img.onload = function () {
88
- resolve(img);
89
- };
90
- img.src = base64;
91
- });
92
- }));
93
- case 9:
94
- imgList = _context2.sent;
95
- imgList.forEach(function (img) {
96
- context === null || context === void 0 || context.drawImage(img, 0, 0, width, height);
97
- });
98
- return _context2.abrupt("return", canvas.toDataURL("image/".concat(imageType)));
99
- case 12:
100
- case "end":
101
- return _context2.stop();
102
- }
103
- }, _callee2);
104
- })));
105
- return _this;
106
- }
107
- _createClass(ExportImage, [{
108
- key: "onAdd",
109
- value: function onAdd() {
110
- var button = _get(_getPrototypeOf(ExportImage.prototype), "onAdd", this).call(this);
111
- button.addEventListener('click', this.onClick);
112
- return button;
113
- }
114
- }, {
115
- key: "getDefault",
116
- value: function getDefault(option) {
117
- return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(ExportImage.prototype), "getDefault", this).call(this, option)), {}, {
118
- title: '导出图片',
119
- btnIcon: createL7Icon('l7-icon-export-picture'),
120
- imageType: 'png'
121
- });
122
- }
123
- }, {
124
- key: "getImage",
125
- value: function () {
126
- var _getImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
127
- var mapImage, layerImage;
128
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
129
- while (1) switch (_context3.prev = _context3.next) {
130
- case 0:
131
- _context3.next = 2;
132
- return this.mapsService.exportMap('png');
133
- case 2:
134
- mapImage = _context3.sent;
135
- _context3.next = 5;
136
- return this.scene.exportPng('png');
137
- case 5:
138
- layerImage = _context3.sent;
139
- return _context3.abrupt("return", this.mergeImage.apply(this, _toConsumableArray([mapImage, layerImage].filter(function (base64) {
140
- return base64;
141
- }))));
142
- case 7:
143
- case "end":
144
- return _context3.stop();
145
- }
146
- }, _callee3, this);
25
+ const {
26
+ imageType
27
+ } = _this.controlOption;
28
+ const {
29
+ width = 0,
30
+ height = 0
31
+ } = (_this$mapsService$get = (_this$mapsService$get2 = _this.mapsService.getContainer()) === null || _this$mapsService$get2 === void 0 ? void 0 : _this$mapsService$get2.getBoundingClientRect()) !== null && _this$mapsService$get !== void 0 ? _this$mapsService$get : {};
32
+ const canvas = document.createElement('canvas');
33
+ canvas.width = width;
34
+ canvas.height = height;
35
+ const context = canvas.getContext('2d');
36
+ const imgList = yield Promise.all(base64List.map(base64 => {
37
+ return new Promise(resolve => {
38
+ const img = new Image();
39
+ img.onload = () => {
40
+ resolve(img);
41
+ };
42
+ img.src = base64;
43
+ });
147
44
  }));
148
- function getImage() {
149
- return _getImage.apply(this, arguments);
150
- }
151
- return getImage;
152
- }()
153
- }]);
154
- return ExportImage;
155
- }(ButtonControl);
156
- export { ExportImage as default };
45
+ imgList.forEach(img => {
46
+ context === null || context === void 0 || context.drawImage(img, 0, 0, width, height);
47
+ });
48
+ return canvas.toDataURL(`image/${imageType}`);
49
+ }));
50
+ }
51
+ onAdd() {
52
+ const button = super.onAdd();
53
+ button.addEventListener('click', this.onClick);
54
+ return button;
55
+ }
56
+ getDefault(option) {
57
+ return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
58
+ title: '导出图片',
59
+ btnIcon: createL7Icon('l7-icon-export-picture'),
60
+ imageType: 'png'
61
+ });
62
+ }
63
+ getImage() {
64
+ var _this2 = this;
65
+ return _asyncToGenerator(function* () {
66
+ const mapImage = yield _this2.mapsService.exportMap('png');
67
+ const layerImage = yield _this2.scene.exportPng('png');
68
+ return _this2.mergeImage(
69
+ // 在 Map 底图模式下 mapImage 为 undefined
70
+ ...[mapImage, layerImage].filter(base64 => base64));
71
+ })();
72
+ }
73
+ }
@@ -1,119 +1,88 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/esm/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import _get from "@babel/runtime/helpers/esm/get";
7
- import _inherits from "@babel/runtime/helpers/esm/inherits";
8
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
9
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
10
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
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
4
  import { DOM } from '@antv/l7-utils';
15
5
  import { createL7Icon } from "../utils/icon";
16
6
  import ScreenFull from "../utils/screenfull";
17
7
  import ButtonControl from "./baseControl/buttonControl";
18
8
  export { Fullscreen };
19
- var Fullscreen = /*#__PURE__*/function (_ButtonControl) {
20
- _inherits(Fullscreen, _ButtonControl);
21
- var _super = _createSuper(Fullscreen);
22
- function Fullscreen(option) {
9
+ export default class Fullscreen extends ButtonControl {
10
+ constructor(option) {
23
11
  var _this;
24
- _classCallCheck(this, Fullscreen);
25
- _this = _super.call(this, option);
26
- _defineProperty(_assertThisInitialized(_this), "isFullscreen", false);
27
- _defineProperty(_assertThisInitialized(_this), "toggleFullscreen", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
28
- return _regeneratorRuntime.wrap(function _callee$(_context) {
29
- while (1) switch (_context.prev = _context.next) {
30
- case 0:
31
- if (!ScreenFull.isEnabled) {
32
- _context.next = 3;
33
- break;
34
- }
35
- _context.next = 3;
36
- return ScreenFull.toggle(_this.mapContainer);
37
- case 3:
38
- case "end":
39
- return _context.stop();
40
- }
41
- }, _callee);
42
- })));
43
- _defineProperty(_assertThisInitialized(_this), "onClick", function () {
44
- _this.toggleFullscreen();
12
+ super(option);
13
+ _this = this;
14
+ _defineProperty(this, "isFullscreen", false);
15
+ _defineProperty(this, "mapContainer", void 0);
16
+ _defineProperty(this, "toggleFullscreen", /*#__PURE__*/_asyncToGenerator(function* () {
17
+ if (ScreenFull.isEnabled) {
18
+ yield ScreenFull.toggle(_this.mapContainer);
19
+ }
20
+ }));
21
+ _defineProperty(this, "onClick", () => {
22
+ this.toggleFullscreen();
45
23
  });
46
- _defineProperty(_assertThisInitialized(_this), "onFullscreenChange", function () {
47
- _this.isFullscreen = !!document.fullscreenElement;
48
- var _this$controlOption = _this.controlOption,
49
- btnText = _this$controlOption.btnText,
50
- btnIcon = _this$controlOption.btnIcon,
51
- title = _this$controlOption.title,
52
- exitBtnText = _this$controlOption.exitBtnText,
53
- exitBtnIcon = _this$controlOption.exitBtnIcon,
54
- exitTitle = _this$controlOption.exitTitle;
55
- if (_this.isFullscreen) {
56
- _this.setBtnTitle(exitTitle);
57
- _this.setBtnText(exitBtnText);
58
- _this.setBtnIcon(exitBtnIcon);
24
+ _defineProperty(this, "onFullscreenChange", () => {
25
+ this.isFullscreen = !!document.fullscreenElement;
26
+ const {
27
+ btnText,
28
+ btnIcon,
29
+ title,
30
+ exitBtnText,
31
+ exitBtnIcon,
32
+ exitTitle
33
+ } = this.controlOption;
34
+ if (this.isFullscreen) {
35
+ this.setBtnTitle(exitTitle);
36
+ this.setBtnText(exitBtnText);
37
+ this.setBtnIcon(exitBtnIcon);
59
38
  } else {
60
- _this.setBtnTitle(title);
61
- _this.setBtnText(btnText);
62
- _this.setBtnIcon(btnIcon);
39
+ this.setBtnTitle(title);
40
+ this.setBtnText(btnText);
41
+ this.setBtnIcon(btnIcon);
63
42
  }
64
- _this.emit('fullscreenChange', _this.isFullscreen);
43
+ this.emit('fullscreenChange', this.isFullscreen);
65
44
  });
66
45
  if (!ScreenFull.isEnabled) {
67
46
  console.warn('当前浏览器环境不支持对地图全屏化');
68
47
  }
69
- return _this;
70
48
  }
71
- _createClass(Fullscreen, [{
72
- key: "setOptions",
73
- value: function setOptions(newOptions) {
74
- var exitBtnText = newOptions.exitBtnText,
75
- exitBtnIcon = newOptions.exitBtnIcon,
76
- exitTitle = newOptions.exitTitle;
77
- if (this.isFullscreen) {
78
- if (this.checkUpdateOption(newOptions, ['exitBtnIcon'])) {
79
- this.setBtnIcon(exitBtnIcon);
80
- }
81
- if (this.checkUpdateOption(newOptions, ['exitBtnText'])) {
82
- this.setBtnText(exitBtnText);
83
- }
84
- if (this.checkUpdateOption(newOptions, ['exitTitle'])) {
85
- this.setBtnTitle(exitTitle);
86
- }
49
+ setOptions(newOptions) {
50
+ const {
51
+ exitBtnText,
52
+ exitBtnIcon,
53
+ exitTitle
54
+ } = newOptions;
55
+ if (this.isFullscreen) {
56
+ if (this.checkUpdateOption(newOptions, ['exitBtnIcon'])) {
57
+ this.setBtnIcon(exitBtnIcon);
58
+ }
59
+ if (this.checkUpdateOption(newOptions, ['exitBtnText'])) {
60
+ this.setBtnText(exitBtnText);
61
+ }
62
+ if (this.checkUpdateOption(newOptions, ['exitTitle'])) {
63
+ this.setBtnTitle(exitTitle);
87
64
  }
88
- _get(_getPrototypeOf(Fullscreen.prototype), "setOptions", this).call(this, newOptions);
89
- }
90
- }, {
91
- key: "onAdd",
92
- value: function onAdd() {
93
- var button = _get(_getPrototypeOf(Fullscreen.prototype), "onAdd", this).call(this);
94
- button.addEventListener('click', this.onClick);
95
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
- this.mapContainer = DOM.getContainer(this.scene.getSceneConfig().id);
97
- this.mapContainer.addEventListener('fullscreenchange', this.onFullscreenChange);
98
- return button;
99
- }
100
- }, {
101
- key: "onRemove",
102
- value: function onRemove() {
103
- _get(_getPrototypeOf(Fullscreen.prototype), "onRemove", this).call(this);
104
- this.mapContainer.removeEventListener('fullscreenchange', this.onFullscreenChange);
105
- }
106
- }, {
107
- key: "getDefault",
108
- value: function getDefault(option) {
109
- return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(Fullscreen.prototype), "getDefault", this).call(this, option)), {}, {
110
- title: '全屏',
111
- btnIcon: createL7Icon('l7-icon-fullscreen'),
112
- exitTitle: '退出全屏',
113
- exitBtnIcon: createL7Icon('l7-icon-exit-fullscreen')
114
- });
115
65
  }
116
- }]);
117
- return Fullscreen;
118
- }(ButtonControl);
119
- export { Fullscreen as default };
66
+ super.setOptions(newOptions);
67
+ }
68
+ onAdd() {
69
+ const button = super.onAdd();
70
+ button.addEventListener('click', this.onClick);
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ this.mapContainer = DOM.getContainer(this.scene.getSceneConfig().id);
73
+ this.mapContainer.addEventListener('fullscreenchange', this.onFullscreenChange);
74
+ return button;
75
+ }
76
+ onRemove() {
77
+ super.onRemove();
78
+ this.mapContainer.removeEventListener('fullscreenchange', this.onFullscreenChange);
79
+ }
80
+ getDefault(option) {
81
+ return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
82
+ title: '全屏',
83
+ btnIcon: createL7Icon('l7-icon-fullscreen'),
84
+ exitTitle: '退出全屏',
85
+ exitBtnIcon: createL7Icon('l7-icon-exit-fullscreen')
86
+ });
87
+ }
88
+ }
@@ -1,107 +1,60 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/esm/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import _get from "@babel/runtime/helpers/esm/get";
7
- import _inherits from "@babel/runtime/helpers/esm/inherits";
8
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
9
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
10
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
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
4
  import { createL7Icon } from "../utils/icon";
15
5
  import ButtonControl from "./baseControl/buttonControl";
16
6
  export { GeoLocate };
17
- var GeoLocate = /*#__PURE__*/function (_ButtonControl) {
18
- _inherits(GeoLocate, _ButtonControl);
19
- var _super = _createSuper(GeoLocate);
20
- function GeoLocate(option) {
7
+ export default class GeoLocate extends ButtonControl {
8
+ constructor(option) {
21
9
  var _this;
22
- _classCallCheck(this, GeoLocate);
23
- _this = _super.call(this, option);
10
+ super(option);
11
+ _this = this;
24
12
  /**
25
13
  * 通过浏览器 API 获取当前所在经纬度
26
14
  */
27
- _defineProperty(_assertThisInitialized(_this), "getGeoLocation", function () {
28
- return new Promise(function (resolve, reject) {
29
- window.navigator.geolocation.getCurrentPosition(function (_ref) {
30
- var coords = _ref.coords;
31
- var _ref2 = coords !== null && coords !== void 0 ? coords : {},
32
- longitude = _ref2.longitude,
33
- latitude = _ref2.latitude;
15
+ _defineProperty(this, "getGeoLocation", () => {
16
+ return new Promise((resolve, reject) => {
17
+ window.navigator.geolocation.getCurrentPosition(({
18
+ coords
19
+ }) => {
20
+ const {
21
+ longitude,
22
+ latitude
23
+ } = coords !== null && coords !== void 0 ? coords : {};
34
24
  if (!isNaN(longitude) && !isNaN(latitude)) {
35
25
  resolve([longitude, latitude]);
36
26
  } else {
37
27
  reject();
38
28
  }
39
- }, function (e) {
29
+ }, e => {
40
30
  reject(e);
41
31
  });
42
32
  });
43
33
  });
44
- _defineProperty(_assertThisInitialized(_this), "onClick", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
45
- var transform, position, currentZoom;
46
- return _regeneratorRuntime.wrap(function _callee$(_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- if (window.navigator.geolocation) {
50
- _context.next = 2;
51
- break;
52
- }
53
- return _context.abrupt("return");
54
- case 2:
55
- transform = _this.controlOption.transform;
56
- _context.next = 5;
57
- return _this.getGeoLocation();
58
- case 5:
59
- position = _context.sent;
60
- currentZoom = _this.mapsService.getZoom();
61
- _context.t0 = _this.mapsService;
62
- _context.t1 = currentZoom > 15 ? currentZoom : 15;
63
- if (!transform) {
64
- _context.next = 15;
65
- break;
66
- }
67
- _context.next = 12;
68
- return transform(position);
69
- case 12:
70
- _context.t2 = _context.sent;
71
- _context.next = 16;
72
- break;
73
- case 15:
74
- _context.t2 = position;
75
- case 16:
76
- _context.t3 = _context.t2;
77
- _context.t0.setZoomAndCenter.call(_context.t0, _context.t1, _context.t3);
78
- case 18:
79
- case "end":
80
- return _context.stop();
81
- }
82
- }, _callee);
83
- })));
34
+ _defineProperty(this, "onClick", /*#__PURE__*/_asyncToGenerator(function* () {
35
+ if (!window.navigator.geolocation) {
36
+ return;
37
+ }
38
+ const {
39
+ transform
40
+ } = _this.controlOption;
41
+ const position = yield _this.getGeoLocation();
42
+ const currentZoom = _this.mapsService.getZoom();
43
+ _this.mapsService.setZoomAndCenter(currentZoom > 15 ? currentZoom : 15, transform ? yield transform(position) : position);
44
+ }));
84
45
  if (!window.navigator.geolocation) {
85
46
  console.warn('当前浏览器环境不支持获取地理定位');
86
47
  }
87
- return _this;
88
48
  }
89
- _createClass(GeoLocate, [{
90
- key: "getDefault",
91
- value: function getDefault(option) {
92
- return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(GeoLocate.prototype), "getDefault", this).call(this, option)), {}, {
93
- title: '定位',
94
- btnIcon: createL7Icon('l7-icon-reposition')
95
- });
96
- }
97
- }, {
98
- key: "onAdd",
99
- value: function onAdd() {
100
- var button = _get(_getPrototypeOf(GeoLocate.prototype), "onAdd", this).call(this);
101
- button.addEventListener('click', this.onClick);
102
- return button;
103
- }
104
- }]);
105
- return GeoLocate;
106
- }(ButtonControl);
107
- export { GeoLocate as default };
49
+ getDefault(option) {
50
+ return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
51
+ title: '定位',
52
+ btnIcon: createL7Icon('l7-icon-reposition')
53
+ });
54
+ }
55
+ onAdd() {
56
+ const button = super.onAdd();
57
+ button.addEventListener('click', this.onClick);
58
+ return button;
59
+ }
60
+ }