@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
@@ -6,616 +6,558 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.Popup = 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 _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
10
  var _l7Utils = require("@antv/l7-utils");
17
11
  var _eventemitter = require("eventemitter3");
18
12
  var _icon = require("../utils/icon");
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 Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitter) {
22
- (0, _inherits2.default)(Popup, _EventEmitter);
23
- var _super = _createSuper(Popup);
24
- function Popup(cfg) {
25
- var _this;
26
- (0, _classCallCheck2.default)(this, Popup);
27
- _this = _super.call(this);
13
+ class Popup extends _eventemitter.EventEmitter {
14
+ get lngLat() {
15
+ var _this$popupOption$lng;
16
+ return (_this$popupOption$lng = this.popupOption.lngLat) !== null && _this$popupOption$lng !== void 0 ? _this$popupOption$lng : {
17
+ lng: 0,
18
+ lat: 0
19
+ };
20
+ }
21
+ set lngLat(newLngLat) {
22
+ this.popupOption.lngLat = newLngLat;
23
+ }
24
+ constructor(cfg) {
25
+ super();
28
26
  /**
29
27
  * 配置
30
28
  * @protected
31
29
  */
30
+ (0, _defineProperty2.default)(this, "popupOption", void 0);
31
+ (0, _defineProperty2.default)(this, "mapsService", void 0);
32
+ (0, _defineProperty2.default)(this, "sceneService", void 0);
33
+ (0, _defineProperty2.default)(this, "layerService", void 0);
34
+ (0, _defineProperty2.default)(this, "scene", void 0);
32
35
  /**
33
36
  * 关闭按钮对应的 DOM
34
37
  * @protected
35
38
  */
39
+ (0, _defineProperty2.default)(this, "closeButton", void 0);
36
40
  /**
37
41
  * Popup 的总容器 DOM,包含 content 和 tip
38
42
  * @protected
39
43
  */
44
+ (0, _defineProperty2.default)(this, "container", void 0);
40
45
  /**
41
46
  * popup 气泡容器
42
47
  * @protected
43
48
  */
49
+ (0, _defineProperty2.default)(this, "content", void 0);
44
50
  /**
45
51
  * popup 气泡标题
46
52
  * @protected
47
53
  */
54
+ (0, _defineProperty2.default)(this, "contentTitle", void 0);
48
55
  /**
49
56
  * popup 内容容器
50
57
  * @protected
51
58
  */
59
+ (0, _defineProperty2.default)(this, "contentPanel", void 0);
52
60
  /**
53
61
  * 气泡箭头对应的 DOM
54
62
  * @protected
55
63
  */
64
+ (0, _defineProperty2.default)(this, "tip", void 0);
56
65
  /**
57
66
  * 当前是否展示
58
67
  * @protected
59
68
  */
60
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isShow", true);
61
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseMove", function (e) {
69
+ (0, _defineProperty2.default)(this, "isShow", true);
70
+ (0, _defineProperty2.default)(this, "onMouseMove", e => {
62
71
  var _container$getBoundin;
63
- var container = _this.mapsService.getMapContainer();
64
- var _ref = (_container$getBoundin = container === null || container === void 0 ? void 0 : container.getBoundingClientRect()) !== null && _container$getBoundin !== void 0 ? _container$getBoundin : {},
65
- _ref$left = _ref.left,
66
- left = _ref$left === void 0 ? 0 : _ref$left,
67
- _ref$top = _ref.top,
68
- top = _ref$top === void 0 ? 0 : _ref$top;
69
- _this.setPopupPosition(e.clientX - left, e.clientY - top);
72
+ const container = this.mapsService.getMapContainer();
73
+ const {
74
+ left = 0,
75
+ top = 0
76
+ } = (_container$getBoundin = container === null || container === void 0 ? void 0 : container.getBoundingClientRect()) !== null && _container$getBoundin !== void 0 ? _container$getBoundin : {};
77
+ this.setPopupPosition(e.clientX - left, e.clientY - top);
70
78
  });
71
79
  /**
72
80
  * 将经纬度转换成对应的像素偏移位置
73
81
  * @protected
74
82
  */
75
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateLngLatPosition", function () {
76
- if (!_this.mapsService || _this.popupOption.followCursor) {
83
+ (0, _defineProperty2.default)(this, "updateLngLatPosition", () => {
84
+ if (!this.mapsService || this.popupOption.followCursor) {
77
85
  return;
78
86
  }
79
- var _this$lngLat = _this.lngLat,
80
- lng = _this$lngLat.lng,
81
- lat = _this$lngLat.lat;
82
- var _this$mapsService$lng = _this.mapsService.lngLatToContainer([lng, lat]),
83
- x = _this$mapsService$lng.x,
84
- y = _this$mapsService$lng.y;
85
- _this.setPopupPosition(x, y);
87
+ const {
88
+ lng,
89
+ lat
90
+ } = this.lngLat;
91
+ const {
92
+ x,
93
+ y
94
+ } = this.mapsService.lngLatToContainer([lng, lat]);
95
+ this.setPopupPosition(x, y);
86
96
  });
87
97
  //zoom时计算PopUp的位置并更新
88
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateLngLatPositionWhenZoom", function (ev) {
89
- if (!_this.mapsService || _this.popupOption.followCursor) {
98
+ (0, _defineProperty2.default)(this, "updateLngLatPositionWhenZoom", ev => {
99
+ if (!this.mapsService || this.popupOption.followCursor) {
90
100
  return;
91
101
  }
92
- var map = ev.map;
93
- var viewHalf = map.getSize();
102
+ const map = ev.map;
103
+ const viewHalf = map.getSize();
94
104
  viewHalf.x = viewHalf.x / 2;
95
105
  viewHalf.y = viewHalf.y / 2;
96
- var center = ev.center;
97
- var zoom = ev.zoom;
98
- var projectedCenter = map.DE(_this.lngLat, zoom, center);
106
+ const center = ev.center;
107
+ const zoom = ev.zoom;
108
+ const projectedCenter = map.DE(this.lngLat, zoom, center);
99
109
  projectedCenter.x = Math.round(projectedCenter.x);
100
110
  projectedCenter.y = Math.round(projectedCenter.y);
101
- _this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
111
+ this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
102
112
  });
103
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (e) {
113
+ (0, _defineProperty2.default)(this, "onKeyDown", e => {
104
114
  if (e.keyCode === 27) {
105
- _this.remove();
115
+ this.remove();
106
116
  }
107
117
  });
108
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCloseButtonClick", function (e) {
118
+ (0, _defineProperty2.default)(this, "onCloseButtonClick", e => {
109
119
  if (e.stopPropagation) {
110
120
  e.stopPropagation();
111
121
  }
112
- _this.hide();
122
+ this.hide();
113
123
  });
114
124
  //更新位置 支持zoom时更新
115
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updatePosition", function (ev) {
116
- var zoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
117
- var hasPosition = !!_this.lngLat;
118
- var _this$popupOption = _this.popupOption,
119
- className = _this$popupOption.className,
120
- style = _this$popupOption.style,
121
- maxWidth = _this$popupOption.maxWidth,
122
- anchor = _this$popupOption.anchor,
123
- stopPropagation = _this$popupOption.stopPropagation;
124
- if (!_this.mapsService || !hasPosition || !_this.content) {
125
+ (0, _defineProperty2.default)(this, "updatePosition", (ev, zoom = true) => {
126
+ const hasPosition = !!this.lngLat;
127
+ const {
128
+ className,
129
+ style,
130
+ maxWidth,
131
+ anchor,
132
+ stopPropagation
133
+ } = this.popupOption;
134
+ if (!this.mapsService || !hasPosition || !this.content) {
125
135
  return;
126
136
  }
127
- var popupContainer = _this.mapsService.getMarkerContainer();
137
+ const popupContainer = this.mapsService.getMarkerContainer();
128
138
  // 如果当前没有创建 Popup 容器则创建
129
- if (!_this.container && popupContainer) {
130
- _this.container = _l7Utils.DOM.create('div', "l7-popup ".concat(className !== null && className !== void 0 ? className : '', " ").concat(!_this.isShow ? 'l7-popup-hide' : ''), popupContainer);
139
+ if (!this.container && popupContainer) {
140
+ this.container = _l7Utils.DOM.create('div', `l7-popup ${className !== null && className !== void 0 ? className : ''} ${!this.isShow ? 'l7-popup-hide' : ''}`, popupContainer);
131
141
  if (style) {
132
- _this.container.setAttribute('style', style);
142
+ this.container.setAttribute('style', style);
133
143
  }
134
- _this.tip = _l7Utils.DOM.create('div', 'l7-popup-tip', _this.container);
135
- _this.container.appendChild(_this.content);
144
+ this.tip = _l7Utils.DOM.create('div', 'l7-popup-tip', this.container);
145
+ this.container.appendChild(this.content);
136
146
 
137
147
  // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
138
148
  if (stopPropagation) {
139
- ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
140
- _this.container.addEventListener(type, function (e) {
149
+ ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(type => {
150
+ this.container.addEventListener(type, e => {
141
151
  e.stopPropagation();
142
152
  });
143
153
  });
144
154
  }
145
- _this.container.style.whiteSpace = 'nowrap';
155
+ this.container.style.whiteSpace = 'nowrap';
146
156
  }
147
157
  if (zoom) {
148
- _this.updateLngLatPositionWhenZoom(ev);
158
+ this.updateLngLatPositionWhenZoom(ev);
149
159
  } else {
150
- _this.updateLngLatPosition();
160
+ this.updateLngLatPosition();
151
161
  }
152
- _l7Utils.DOM.setTransform(_this.container, "".concat(_l7Utils.anchorTranslate[anchor]));
153
- (0, _l7Utils.applyAnchorClass)(_this.container, anchor, 'popup');
162
+ _l7Utils.DOM.setTransform(this.container, `${_l7Utils.anchorTranslate[anchor]}`);
163
+ (0, _l7Utils.applyAnchorClass)(this.container, anchor, 'popup');
154
164
  if (maxWidth) {
155
- var _this$container$getBo = _this.container.getBoundingClientRect(),
156
- width = _this$container$getBo.width;
165
+ const {
166
+ width
167
+ } = this.container.getBoundingClientRect();
157
168
  if (width > parseFloat(maxWidth)) {
158
- _this.container.style.width = maxWidth;
169
+ this.container.style.width = maxWidth;
159
170
  }
160
171
  } else {
161
- _this.container.style.removeProperty('width');
172
+ this.container.style.removeProperty('width');
162
173
  }
163
174
  });
164
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateWhenZoom", function (ev) {
165
- _this.updatePosition(ev, true);
175
+ (0, _defineProperty2.default)(this, "updateWhenZoom", ev => {
176
+ this.updatePosition(ev, true);
166
177
  });
167
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "update", function () {
168
- _this.updatePosition(null, false);
178
+ (0, _defineProperty2.default)(this, "update", () => {
179
+ this.updatePosition(null, false);
169
180
  });
170
- _this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
171
- var lngLat = _this.popupOption.lngLat;
181
+ this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
182
+ const {
183
+ lngLat
184
+ } = this.popupOption;
172
185
  if (lngLat) {
173
- _this.lngLat = lngLat;
186
+ this.lngLat = lngLat;
174
187
  }
175
- return _this;
176
188
  }
177
- (0, _createClass2.default)(Popup, [{
178
- key: "lngLat",
179
- get: function get() {
180
- var _this$popupOption$lng;
181
- return (_this$popupOption$lng = this.popupOption.lngLat) !== null && _this$popupOption$lng !== void 0 ? _this$popupOption$lng : {
182
- lng: 0,
183
- lat: 0
184
- };
185
- },
186
- set: function set(newLngLat) {
187
- this.popupOption.lngLat = newLngLat;
189
+ getIsShow() {
190
+ return this.isShow;
191
+ }
192
+ addTo(scene) {
193
+ this.mapsService = scene.mapService;
194
+ this.sceneService = scene.sceneService;
195
+ this.layerService = scene.layerService;
196
+ //天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
197
+ // this.mapsService.on('zoomchange', this.updateWhenZoom);
198
+ this.mapsService.on('camerachange', this.update);
199
+ this.mapsService.on('viewchange', this.update);
200
+ this.scene = scene;
201
+ this.update();
202
+ // 临时关闭
203
+ this.updateCloseOnClick();
204
+ this.updateCloseOnEsc();
205
+ this.updateFollowCursor();
206
+ const {
207
+ html,
208
+ text,
209
+ title
210
+ } = this.popupOption;
211
+ if (html) {
212
+ this.setHTML(html);
213
+ } else if (text) {
214
+ this.setText(text);
188
215
  }
189
- }, {
190
- key: "getIsShow",
191
- value: function getIsShow() {
192
- return this.isShow;
216
+ if (title) {
217
+ this.setTitle(title);
193
218
  }
194
- }, {
195
- key: "addTo",
196
- value: function addTo(scene) {
197
- this.mapsService = scene.mapService;
198
- this.sceneService = scene.sceneService;
199
- this.layerService = scene.layerService;
200
- //天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
201
- // this.mapsService.on('zoomchange', this.updateWhenZoom);
202
- this.mapsService.on('camerachange', this.update);
203
- this.mapsService.on('viewchange', this.update);
204
- this.scene = scene;
205
- this.update();
206
- // 临时关闭
207
- this.updateCloseOnClick();
208
- this.updateCloseOnEsc();
209
- this.updateFollowCursor();
210
- var _this$popupOption2 = this.popupOption,
211
- html = _this$popupOption2.html,
212
- text = _this$popupOption2.text,
213
- title = _this$popupOption2.title;
214
- if (html) {
215
- this.setHTML(html);
216
- } else if (text) {
217
- this.setText(text);
218
- }
219
- if (title) {
220
- this.setTitle(title);
221
- }
222
- this.emit('open');
223
- return this;
219
+ this.emit('open');
220
+ return this;
221
+ }
222
+
223
+ // 移除popup
224
+ remove() {
225
+ if (!(this !== null && this !== void 0 && this.isOpen())) {
226
+ return;
224
227
  }
228
+ if (this.content) {
229
+ _l7Utils.DOM.remove(this.content);
230
+ }
231
+ if (this.container) {
232
+ _l7Utils.DOM.remove(this.container);
233
+ // @ts-ignore
234
+ delete this.container;
235
+ }
236
+ if (this.mapsService) {
237
+ // TODO: mapbox AMap 事件同步
238
+ this.mapsService.off('camerachange', this.update);
239
+ this.mapsService.off('viewchange', this.update);
240
+ //天地图的缩放事件
241
+ // this.mapsService.off('zoomchange', this.updateWhenZoom);
242
+ this.updateCloseOnClick(true);
243
+ this.updateCloseOnEsc(true);
244
+ this.updateFollowCursor(true);
245
+ // @ts-ignore
246
+ delete this.mapsService;
247
+ }
248
+ this.emit('close');
249
+ return this;
250
+ }
225
251
 
226
- // 移除popup
227
- }, {
228
- key: "remove",
229
- value: function remove() {
230
- if (!(this !== null && this !== void 0 && this.isOpen())) {
231
- return;
232
- }
233
- if (this.content) {
234
- _l7Utils.DOM.remove(this.content);
235
- }
252
+ /**
253
+ * 获取 option 配置
254
+ */
255
+ getOptions() {
256
+ return this.popupOption;
257
+ }
258
+ setOptions(option) {
259
+ this.show();
260
+ this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.popupOption), option);
261
+ if (this.checkUpdateOption(option, ['html', 'text', 'title', 'closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
236
262
  if (this.container) {
237
263
  _l7Utils.DOM.remove(this.container);
238
264
  // @ts-ignore
239
- delete this.container;
240
- }
241
- if (this.mapsService) {
242
- // TODO: mapbox AMap 事件同步
243
- this.mapsService.off('camerachange', this.update);
244
- this.mapsService.off('viewchange', this.update);
245
- //天地图的缩放事件
246
- // this.mapsService.off('zoomchange', this.updateWhenZoom);
247
- this.updateCloseOnClick(true);
248
- this.updateCloseOnEsc(true);
249
- this.updateFollowCursor(true);
250
- // @ts-ignore
251
- delete this.mapsService;
252
- }
253
- this.emit('close');
254
- return this;
255
- }
256
-
257
- /**
258
- * 获取 option 配置
259
- */
260
- }, {
261
- key: "getOptions",
262
- value: function getOptions() {
263
- return this.popupOption;
264
- }
265
- }, {
266
- key: "setOptions",
267
- value: function setOptions(option) {
268
- this.show();
269
- this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.popupOption), option);
270
- if (this.checkUpdateOption(option, ['html', 'text', 'title', 'closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
271
- if (this.container) {
272
- _l7Utils.DOM.remove(this.container);
273
- // @ts-ignore
274
- this.container = undefined;
275
- }
276
- if (this.popupOption.html) {
277
- this.setHTML(this.popupOption.html);
278
- } else if (this.popupOption.text) {
279
- this.setText(this.popupOption.text);
280
- }
281
- if (this.popupOption.title) {
282
- this.setTitle(this.popupOption.title);
283
- }
284
- }
285
- if (this.checkUpdateOption(option, ['closeOnEsc'])) {
286
- this.updateCloseOnEsc();
287
- }
288
- if (this.checkUpdateOption(option, ['closeOnClick'])) {
289
- this.updateCloseOnClick();
265
+ this.container = undefined;
290
266
  }
291
- if (this.checkUpdateOption(option, ['followCursor'])) {
292
- this.updateFollowCursor();
267
+ if (this.popupOption.html) {
268
+ this.setHTML(this.popupOption.html);
269
+ } else if (this.popupOption.text) {
270
+ this.setText(this.popupOption.text);
293
271
  }
294
- if (this.checkUpdateOption(option, ['html']) && option.html) {
295
- this.setHTML(option.html);
296
- } else if (this.checkUpdateOption(option, ['text']) && option.text) {
297
- this.setText(option.text);
272
+ if (this.popupOption.title) {
273
+ this.setTitle(this.popupOption.title);
298
274
  }
299
- if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
300
- this.setLnglat(option.lngLat);
301
- }
302
- return this;
303
275
  }
304
- }, {
305
- key: "open",
306
- value: function open() {
307
- this.addTo(this.scene);
308
- return this;
276
+ if (this.checkUpdateOption(option, ['closeOnEsc'])) {
277
+ this.updateCloseOnEsc();
309
278
  }
310
- }, {
311
- key: "close",
312
- value: function close() {
313
- this.remove();
314
- return this;
279
+ if (this.checkUpdateOption(option, ['closeOnClick'])) {
280
+ this.updateCloseOnClick();
315
281
  }
316
- }, {
317
- key: "show",
318
- value: function show() {
319
- if (this.isShow) {
320
- return;
321
- }
322
- if (this.container) {
323
- _l7Utils.DOM.removeClass(this.container, 'l7-popup-hide');
324
- }
325
- this.isShow = true;
326
- this.emit('show');
327
- return this;
282
+ if (this.checkUpdateOption(option, ['followCursor'])) {
283
+ this.updateFollowCursor();
328
284
  }
329
- }, {
330
- key: "hide",
331
- value: function hide() {
332
- if (!this.isShow) {
333
- return;
334
- }
335
- if (this.container) {
336
- _l7Utils.DOM.addClass(this.container, 'l7-popup-hide');
337
- }
338
- this.isShow = false;
339
- this.emit('hide');
340
- return this;
285
+ if (this.checkUpdateOption(option, ['html']) && option.html) {
286
+ this.setHTML(option.html);
287
+ } else if (this.checkUpdateOption(option, ['text']) && option.text) {
288
+ this.setText(option.text);
341
289
  }
342
-
343
- /**
344
- * 设置 HTML 内容
345
- * @param html
346
- */
347
- }, {
348
- key: "setHTML",
349
- value: function setHTML(html) {
350
- this.popupOption.html = html;
351
- return this.setDOMContent(html);
290
+ if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
291
+ this.setLnglat(option.lngLat);
352
292
  }
353
-
354
- /**
355
- * 设置 Popup 展示文本
356
- * @param text
357
- */
358
- }, {
359
- key: "setText",
360
- value: function setText(text) {
361
- this.popupOption.text = text;
362
- return this.setDOMContent(window.document.createTextNode(text));
293
+ return this;
294
+ }
295
+ open() {
296
+ this.addTo(this.scene);
297
+ return this;
298
+ }
299
+ close() {
300
+ this.remove();
301
+ return this;
302
+ }
303
+ show() {
304
+ if (this.isShow) {
305
+ return;
363
306
  }
364
- }, {
365
- key: "setTitle",
366
- value: function setTitle(title) {
367
- this.show();
368
- this.popupOption.title = title;
369
- if (title) {
370
- if (!this.contentTitle) {
371
- this.contentTitle = _l7Utils.DOM.create('div', 'l7-popup-content__title');
372
- if (this.content.firstChild) {
373
- this.content.insertBefore(this.contentTitle, this.content.firstChild);
374
- } else {
375
- this.content.append(this.contentTitle);
376
- }
377
- }
378
- _l7Utils.DOM.clearChildren(this.contentTitle);
379
- _l7Utils.DOM.appendElementType(this.contentTitle, title);
380
- } else if (this.contentTitle) {
381
- _l7Utils.DOM.remove(this.contentTitle);
382
- this.contentTitle = undefined;
383
- }
307
+ if (this.container) {
308
+ _l7Utils.DOM.removeClass(this.container, 'l7-popup-hide');
384
309
  }
385
-
386
- /**
387
- * 将地图自动平移到气泡位置
388
- */
389
- }, {
390
- key: "panToPopup",
391
- value: function panToPopup() {
392
- var _this$lngLat2 = this.lngLat,
393
- lng = _this$lngLat2.lng,
394
- lat = _this$lngLat2.lat;
395
- if (this.popupOption.autoPan) {
396
- this.mapsService.panTo([lng, lat]);
397
- }
398
- return this;
310
+ this.isShow = true;
311
+ this.emit('show');
312
+ return this;
313
+ }
314
+ hide() {
315
+ if (!this.isShow) {
316
+ return;
399
317
  }
400
- }, {
401
- key: "setLngLat",
402
- value: function setLngLat(lngLat) {
403
- return this.setLnglat(lngLat);
318
+ if (this.container) {
319
+ _l7Utils.DOM.addClass(this.container, 'l7-popup-hide');
404
320
  }
321
+ this.isShow = false;
322
+ this.emit('hide');
323
+ return this;
324
+ }
405
325
 
406
- /**
407
- * 设置 Popup 所在经纬度
408
- * @param lngLat
409
- */
410
- }, {
411
- key: "setLnglat",
412
- value: function setLnglat(lngLat) {
413
- var _this2 = this;
414
- this.show();
415
- this.lngLat = lngLat;
416
- if (Array.isArray(lngLat)) {
417
- this.lngLat = {
418
- lng: lngLat[0],
419
- lat: lngLat[1]
420
- };
421
- }
422
- if (this.mapsService) {
423
- // 防止事件重复监听
424
- // this.mapsService.off('zoonanim', this.updateWhenZoom);
425
- this.mapsService.off('camerachange', this.update);
426
- this.mapsService.off('viewchange', this.update);
326
+ /**
327
+ * 设置 HTML 内容
328
+ * @param html
329
+ */
330
+ setHTML(html) {
331
+ this.popupOption.html = html;
332
+ return this.setDOMContent(html);
333
+ }
427
334
 
428
- // this.mapsService.on('zoonanim', this.updateWhenZoom);
429
- this.mapsService.on('camerachange', this.update);
430
- this.mapsService.on('viewchange', this.update);
431
- }
432
- this.update();
433
- if (this.popupOption.autoPan) {
434
- setTimeout(function () {
435
- _this2.panToPopup();
436
- }, 0);
335
+ /**
336
+ * 设置 Popup 展示文本
337
+ * @param text
338
+ */
339
+ setText(text) {
340
+ this.popupOption.text = text;
341
+ return this.setDOMContent(window.document.createTextNode(text));
342
+ }
343
+ setTitle(title) {
344
+ this.show();
345
+ this.popupOption.title = title;
346
+ if (title) {
347
+ if (!this.contentTitle) {
348
+ this.contentTitle = _l7Utils.DOM.create('div', 'l7-popup-content__title');
349
+ if (this.content.firstChild) {
350
+ this.content.insertBefore(this.contentTitle, this.content.firstChild);
351
+ } else {
352
+ this.content.append(this.contentTitle);
353
+ }
437
354
  }
438
- return this;
355
+ _l7Utils.DOM.clearChildren(this.contentTitle);
356
+ _l7Utils.DOM.appendElementType(this.contentTitle, title);
357
+ } else if (this.contentTitle) {
358
+ _l7Utils.DOM.remove(this.contentTitle);
359
+ this.contentTitle = undefined;
439
360
  }
361
+ }
440
362
 
441
- /**
442
- * 获取 Popup 所在经纬度
443
- */
444
- }, {
445
- key: "getLnglat",
446
- value: function getLnglat() {
447
- return this.lngLat;
363
+ /**
364
+ * 将地图自动平移到气泡位置
365
+ */
366
+ panToPopup() {
367
+ const {
368
+ lng,
369
+ lat
370
+ } = this.lngLat;
371
+ if (this.popupOption.autoPan) {
372
+ this.mapsService.panTo([lng, lat]);
448
373
  }
374
+ return this;
375
+ }
376
+ setLngLat(lngLat) {
377
+ return this.setLnglat(lngLat);
378
+ }
449
379
 
450
- /**
451
- * 设置 Popup 最大宽度
452
- * @param maxWidth
453
- */
454
- }, {
455
- key: "setMaxWidth",
456
- value: function setMaxWidth(maxWidth) {
457
- this.popupOption.maxWidth = maxWidth;
458
- this.update();
459
- return this;
460
- }
461
- }, {
462
- key: "isOpen",
463
- value: function isOpen() {
464
- return !!this.mapsService;
465
- }
466
- }, {
467
- key: "getDefault",
468
- value:
469
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
470
- function getDefault(option) {
471
- // tslint:disable-next-line:no-object-literal-type-assertion
472
- return {
473
- closeButton: true,
474
- closeOnClick: false,
475
- maxWidth: '240px',
476
- offsets: [0, 0],
477
- anchor: _l7Utils.anchorType.BOTTOM,
478
- stopPropagation: true,
479
- autoPan: false,
480
- autoClose: true,
481
- closeOnEsc: false,
482
- followCursor: false
380
+ /**
381
+ * 设置 Popup 所在经纬度
382
+ * @param lngLat
383
+ */
384
+ setLnglat(lngLat) {
385
+ this.show();
386
+ this.lngLat = lngLat;
387
+ if (Array.isArray(lngLat)) {
388
+ this.lngLat = {
389
+ lng: lngLat[0],
390
+ lat: lngLat[1]
483
391
  };
484
392
  }
393
+ if (this.mapsService) {
394
+ // 防止事件重复监听
395
+ // this.mapsService.off('zoonanim', this.updateWhenZoom);
396
+ this.mapsService.off('camerachange', this.update);
397
+ this.mapsService.off('viewchange', this.update);
485
398
 
486
- /**
487
- * 设置 Popup 内容 HTML
488
- * @param element
489
- */
490
- }, {
491
- key: "setDOMContent",
492
- value: function setDOMContent(element) {
493
- this.show();
494
- this.createContent();
495
- _l7Utils.DOM.appendElementType(this.contentPanel, element);
496
- this.update();
497
- return this;
399
+ // this.mapsService.on('zoonanim', this.updateWhenZoom);
400
+ this.mapsService.on('camerachange', this.update);
401
+ this.mapsService.on('viewchange', this.update);
402
+ }
403
+ this.update();
404
+ if (this.popupOption.autoPan) {
405
+ setTimeout(() => {
406
+ this.panToPopup();
407
+ }, 0);
498
408
  }
409
+ return this;
410
+ }
499
411
 
500
- /**
501
- * 绑定地图点击事件触发销毁 Popup
502
- * @protected
503
- */
504
- }, {
505
- key: "updateCloseOnClick",
506
- value: function updateCloseOnClick(onlyClear) {
507
- var _this3 = this;
508
- var mapsService = this.mapsService;
509
- if (mapsService) {
510
- mapsService === null || mapsService === void 0 || mapsService.off('click', this.onCloseButtonClick);
511
- if (this.popupOption.closeOnClick && !onlyClear) {
512
- requestAnimationFrame(function () {
513
- mapsService === null || mapsService === void 0 || mapsService.on('click', _this3.onCloseButtonClick);
514
- });
515
- }
412
+ /**
413
+ * 获取 Popup 所在经纬度
414
+ */
415
+ getLnglat() {
416
+ return this.lngLat;
417
+ }
418
+
419
+ /**
420
+ * 设置 Popup 最大宽度
421
+ * @param maxWidth
422
+ */
423
+ setMaxWidth(maxWidth) {
424
+ this.popupOption.maxWidth = maxWidth;
425
+ this.update();
426
+ return this;
427
+ }
428
+ isOpen() {
429
+ return !!this.mapsService;
430
+ }
431
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
432
+ getDefault(option) {
433
+ // tslint:disable-next-line:no-object-literal-type-assertion
434
+ return {
435
+ closeButton: true,
436
+ closeOnClick: false,
437
+ maxWidth: '240px',
438
+ offsets: [0, 0],
439
+ anchor: _l7Utils.anchorType.BOTTOM,
440
+ stopPropagation: true,
441
+ autoPan: false,
442
+ autoClose: true,
443
+ closeOnEsc: false,
444
+ followCursor: false
445
+ };
446
+ }
447
+
448
+ /**
449
+ * 设置 Popup 内容 HTML
450
+ * @param element
451
+ */
452
+ setDOMContent(element) {
453
+ this.show();
454
+ this.createContent();
455
+ _l7Utils.DOM.appendElementType(this.contentPanel, element);
456
+ this.update();
457
+ return this;
458
+ }
459
+
460
+ /**
461
+ * 绑定地图点击事件触发销毁 Popup
462
+ * @protected
463
+ */
464
+ updateCloseOnClick(onlyClear) {
465
+ const mapsService = this.mapsService;
466
+ if (mapsService) {
467
+ mapsService === null || mapsService === void 0 || mapsService.off('click', this.onCloseButtonClick);
468
+ if (this.popupOption.closeOnClick && !onlyClear) {
469
+ requestAnimationFrame(() => {
470
+ mapsService === null || mapsService === void 0 || mapsService.on('click', this.onCloseButtonClick);
471
+ });
516
472
  }
517
473
  }
518
- }, {
519
- key: "updateCloseOnEsc",
520
- value: function updateCloseOnEsc(onlyClear) {
521
- window.removeEventListener('keydown', this.onKeyDown);
522
- if (this.popupOption.closeOnEsc && !onlyClear) {
523
- window.addEventListener('keydown', this.onKeyDown);
524
- }
474
+ }
475
+ updateCloseOnEsc(onlyClear) {
476
+ window.removeEventListener('keydown', this.onKeyDown);
477
+ if (this.popupOption.closeOnEsc && !onlyClear) {
478
+ window.addEventListener('keydown', this.onKeyDown);
525
479
  }
526
- }, {
527
- key: "updateFollowCursor",
528
- value: function updateFollowCursor(onlyClear) {
529
- var _this$mapsService;
530
- var container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
531
- if (container) {
532
- container === null || container === void 0 || container.removeEventListener('mousemove', this.onMouseMove);
533
- if (this.popupOption.followCursor && !onlyClear) {
534
- container === null || container === void 0 || container.addEventListener('mousemove', this.onMouseMove);
535
- }
480
+ }
481
+ updateFollowCursor(onlyClear) {
482
+ var _this$mapsService;
483
+ const container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
484
+ if (container) {
485
+ container === null || container === void 0 || container.removeEventListener('mousemove', this.onMouseMove);
486
+ if (this.popupOption.followCursor && !onlyClear) {
487
+ container === null || container === void 0 || container.addEventListener('mousemove', this.onMouseMove);
536
488
  }
537
489
  }
538
- }, {
539
- key: "createContent",
540
- value:
541
- /**
542
- * 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
543
- * @protected
544
- */
545
- function createContent() {
546
- var _this4 = this;
547
- if (this.content) {
548
- _l7Utils.DOM.remove(this.content);
490
+ }
491
+ /**
492
+ * 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
493
+ * @protected
494
+ */
495
+ createContent() {
496
+ if (this.content) {
497
+ _l7Utils.DOM.remove(this.content);
498
+ }
499
+ this.contentTitle = undefined;
500
+ this.content = _l7Utils.DOM.create('div', 'l7-popup-content', this.container);
501
+ this.setTitle(this.popupOption.title);
502
+ if (this.popupOption.closeButton) {
503
+ const closeButton = (0, _icon.createL7Icon)('l7-icon-guanbi');
504
+ _l7Utils.DOM.addClass(closeButton, 'l7-popup-close-button');
505
+ this.content.appendChild(closeButton);
506
+ if (this.popupOption.closeButtonOffsets) {
507
+ // 关闭按钮的偏移
508
+ closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
509
+ closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
549
510
  }
550
- this.contentTitle = undefined;
551
- this.content = _l7Utils.DOM.create('div', 'l7-popup-content', this.container);
552
- this.setTitle(this.popupOption.title);
553
- if (this.popupOption.closeButton) {
554
- var closeButton = (0, _icon.createL7Icon)('l7-icon-guanbi');
555
- _l7Utils.DOM.addClass(closeButton, 'l7-popup-close-button');
556
- this.content.appendChild(closeButton);
557
- if (this.popupOption.closeButtonOffsets) {
558
- // 关闭按钮的偏移
559
- closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
560
- closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
561
- }
562
511
 
563
- // this.closeButton.type = 'button';
564
- closeButton.setAttribute('aria-label', 'Close popup');
565
- closeButton.addEventListener('click', function () {
566
- _this4.hide();
567
- });
512
+ // this.closeButton.type = 'button';
513
+ closeButton.setAttribute('aria-label', 'Close popup');
514
+ closeButton.addEventListener('click', () => {
515
+ this.hide();
516
+ });
568
517
 
569
- // 防止点击 Popup 关闭按钮时,触发 Layer click 事件
570
- closeButton.addEventListener('pointerup', function (e) {
571
- e.stopPropagation();
572
- });
573
- closeButton.addEventListener('pointerdown', function (e) {
574
- e.stopPropagation();
575
- });
576
- this.closeButton = closeButton;
577
- } else {
578
- this.closeButton = undefined;
579
- }
580
- this.contentPanel = _l7Utils.DOM.create('div', 'l7-popup-content__panel', this.content);
518
+ // 防止点击 Popup 关闭按钮时,触发 Layer click 事件
519
+ closeButton.addEventListener('pointerup', e => {
520
+ e.stopPropagation();
521
+ });
522
+ closeButton.addEventListener('pointerdown', e => {
523
+ e.stopPropagation();
524
+ });
525
+ this.closeButton = closeButton;
526
+ } else {
527
+ this.closeButton = undefined;
581
528
  }
582
- }, {
583
- key: "setPopupPosition",
584
- value:
585
- /**
586
- * 设置 Popup 相对于地图容器的 Position
587
- * @param {Number} left
588
- * @param {Number} top
589
- * @param {Boolean} [useTransition=false] 是否使用过度效果
590
- * @protected
591
- */
592
- function setPopupPosition(left, top) {
593
- var useTransition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
594
- if (this.container) {
595
- var offsets = this.popupOption.offsets;
596
- this.container.style.left = left + offsets[0] + 'px';
597
- this.container.style.top = top - offsets[1] + 'px';
598
- if (useTransition) {
599
- this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
600
- } else {
601
- this.container.style.transition = '';
602
- }
529
+ this.contentPanel = _l7Utils.DOM.create('div', 'l7-popup-content__panel', this.content);
530
+ }
531
+ /**
532
+ * 设置 Popup 相对于地图容器的 Position
533
+ * @param {Number} left
534
+ * @param {Number} top
535
+ * @param {Boolean} [useTransition=false] 是否使用过度效果
536
+ * @protected
537
+ */
538
+ setPopupPosition(left, top, useTransition = false) {
539
+ if (this.container) {
540
+ const {
541
+ offsets
542
+ } = this.popupOption;
543
+ this.container.style.left = left + offsets[0] + 'px';
544
+ this.container.style.top = top - offsets[1] + 'px';
545
+ if (useTransition) {
546
+ this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
547
+ } else {
548
+ this.container.style.transition = '';
603
549
  }
604
550
  }
551
+ }
605
552
 
606
- /**
607
- * 检查当前传入 option 是否包含 keys 字段
608
- * @param option
609
- * @param keys
610
- * @protected
611
- */
612
- }, {
613
- key: "checkUpdateOption",
614
- value: function checkUpdateOption(option, keys) {
615
- return keys.some(function (key) {
616
- return key in option;
617
- });
618
- }
619
- }]);
620
- return Popup;
621
- }(_eventemitter.EventEmitter);
553
+ /**
554
+ * 检查当前传入 option 是否包含 keys 字段
555
+ * @param option
556
+ * @param keys
557
+ * @protected
558
+ */
559
+ checkUpdateOption(option, keys) {
560
+ return keys.some(key => key in option);
561
+ }
562
+ }
563
+ exports.default = exports.Popup = Popup;