@antv/l7-component 2.11.2 → 2.11.4

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.
@@ -1,15 +1,19 @@
1
1
  import { ILayer, IPopupOption } from '@antv/l7-core';
2
+ import { DOM } from '@antv/l7-utils';
2
3
  import { Container } from 'inversify';
3
4
  import Popup from './popup';
5
+ type ElementType = DOM.ElementType;
4
6
  export type LayerField = {
5
7
  field: string;
6
- formatField?: ((field: string) => string) | string;
7
- formatValue?: ((value: any) => any) | string;
8
+ formatField?: ElementType | ((field: string, feature: any) => ElementType);
9
+ formatValue?: ElementType | ((value: any, feature: any) => ElementType);
8
10
  getValue?: (feature: any) => any;
9
11
  };
10
12
  export type LayerPopupConfigItem = {
11
13
  layer: ILayer | string;
12
- fields: Array<LayerField | string>;
14
+ fields?: Array<LayerField | string>;
15
+ title?: ElementType | ((feature: any) => ElementType);
16
+ customContent?: ElementType | ((feature: any) => ElementType);
13
17
  };
14
18
  export interface ILayerPopupOption extends IPopupOption {
15
19
  config?: LayerPopupConfigItem[];
@@ -62,7 +66,10 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
62
66
  * @param e
63
67
  * @protected
64
68
  */
65
- protected getLayerInfoFrag(layer: ILayer, e: any): DocumentFragment;
69
+ protected getLayerInfoFrag(layer: ILayer, e: any): {
70
+ title: DocumentFragment | undefined;
71
+ content: DocumentFragment;
72
+ };
66
73
  /**
67
74
  * 通过 Layer 配置访问到真实的 Layer 实例
68
75
  * @param configItem
@@ -89,6 +89,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
89
89
  },
90
90
  offsets: [0, 10],
91
91
  closeButton: false,
92
+ closeOnClick: false,
92
93
  autoClose: false,
93
94
  closeOnEsc: false
94
95
  });
@@ -188,15 +189,16 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
188
189
  key: "onLayerMouseMove",
189
190
  value: function onLayerMouseMove(layer, e) {
190
191
  if (!this.isSameFeature(layer, e.featureId)) {
191
- var frag = this.getLayerInfoFrag(layer, e);
192
- this.setDOMContent(frag);
192
+ var _this$getLayerInfoFra = this.getLayerInfoFrag(layer, e),
193
+ title = _this$getLayerInfoFra.title,
194
+ content = _this$getLayerInfoFra.content;
195
+
196
+ this.setDOMContent(content);
197
+ this.setTitle(title);
193
198
  this.displayFeatureInfo = {
194
199
  layer: layer,
195
200
  featureId: e.featureId
196
201
  };
197
- }
198
-
199
- if (!this.isShow) {
200
202
  this.show();
201
203
  }
202
204
  } // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -216,14 +218,18 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
216
218
  if (this.isShow && this.isSameFeature(layer, e.featureId)) {
217
219
  this.hide();
218
220
  } else {
219
- var frag = this.getLayerInfoFrag(layer, e);
220
- this.setDOMContent(frag);
221
+ var _this$getLayerInfoFra2 = this.getLayerInfoFrag(layer, e),
222
+ title = _this$getLayerInfoFra2.title,
223
+ content = _this$getLayerInfoFra2.content;
224
+
225
+ this.setDOMContent(content);
221
226
  this.setLnglat(e.lngLat);
222
- this.show();
227
+ this.setTitle(title);
223
228
  this.displayFeatureInfo = {
224
229
  layer: layer,
225
230
  featureId: e.featureId
226
231
  };
232
+ this.show();
227
233
  }
228
234
  }
229
235
  }, {
@@ -247,7 +253,8 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
247
253
  key: "getLayerInfoFrag",
248
254
  value: function getLayerInfoFrag(layer, e) {
249
255
  var layerInfo = this.layerConfigMap.get(layer);
250
- var frag = document.createDocumentFragment();
256
+ var titleFrag;
257
+ var contentFrag = document.createDocumentFragment();
251
258
 
252
259
  if (layerInfo) {
253
260
  var _feature = e.feature;
@@ -256,29 +263,50 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
256
263
  _feature = _feature.properties;
257
264
  }
258
265
 
259
- var fields = layerInfo.fields;
260
- fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
261
- var _ref3, _ref4;
262
-
263
- var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
264
- {
265
- field: fieldConfig
266
- } : fieldConfig,
267
- field = _ref2.field,
268
- formatField = _ref2.formatField,
269
- formatValue = _ref2.formatValue,
270
- getValue = _ref2.getValue;
271
-
272
- var row = DOM.create('div', 'l7-layer-popup__row');
273
- var value = getValue ? getValue(e.feature) : get(_feature, field);
274
- var fieldText = (_ref3 = formatField instanceof Function ? formatField(field) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
275
- var valueText = (_ref4 = formatValue instanceof Function ? formatValue(value) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
276
- row.innerHTML = "<span class=\"l7-layer-popup__key\">".concat(fieldText, "</span>: <span class=\"l7-layer-popup__value\">").concat(valueText, "</span>");
277
- frag.appendChild(row);
278
- });
266
+ var title = layerInfo.title,
267
+ fields = layerInfo.fields,
268
+ customContent = layerInfo.customContent;
269
+
270
+ if (title) {
271
+ titleFrag = document.createDocumentFragment();
272
+ var titleElement = title instanceof Function ? title(_feature) : title;
273
+ DOM.appendElementType(titleFrag, titleElement);
274
+ }
275
+
276
+ if (customContent) {
277
+ var content = customContent instanceof Function ? customContent(_feature) : customContent;
278
+ DOM.appendElementType(contentFrag, content);
279
+ } else if (fields !== null && fields !== void 0 && fields.length) {
280
+ fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
281
+ var _ref3, _ref4;
282
+
283
+ var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
284
+ {
285
+ field: fieldConfig
286
+ } : fieldConfig,
287
+ field = _ref2.field,
288
+ formatField = _ref2.formatField,
289
+ formatValue = _ref2.formatValue,
290
+ getValue = _ref2.getValue;
291
+
292
+ var row = DOM.create('div', 'l7-layer-popup__row');
293
+ var value = getValue ? getValue(e.feature) : get(_feature, field);
294
+ var fieldElement = (_ref3 = formatField instanceof Function ? formatField(field, _feature) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
295
+ var valueElement = (_ref4 = formatValue instanceof Function ? formatValue(value, _feature) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
296
+ var fieldSpan = DOM.create('span', 'l7-layer-popup__key', row);
297
+ DOM.appendElementType(fieldSpan, fieldElement);
298
+ DOM.appendElementType(fieldSpan, document.createTextNode(':'));
299
+ var valueSpan = DOM.create('span', 'l7-layer-popup__value', row);
300
+ DOM.appendElementType(valueSpan, valueElement);
301
+ contentFrag.appendChild(row);
302
+ });
303
+ }
279
304
  }
280
305
 
281
- return frag;
306
+ return {
307
+ title: titleFrag,
308
+ content: contentFrag
309
+ };
282
310
  }
283
311
  /**
284
312
  * 通过 Layer 配置访问到真实的 Layer 实例
@@ -1,6 +1,8 @@
1
- import { ILayerService, ILngLat, IMapService, IPopup, IPopupOption, ISceneService, PopupHTML } from '@antv/l7-core';
1
+ import { ILayerService, ILngLat, IMapService, IPopup, IPopupOption, ISceneService } from '@antv/l7-core';
2
+ import { DOM } from '@antv/l7-utils';
2
3
  import { EventEmitter } from 'eventemitter3';
3
4
  import { Container } from 'inversify';
5
+ type ElementType = DOM.ElementType;
4
6
  export { Popup };
5
7
  export default class Popup<O extends IPopupOption = IPopupOption> extends EventEmitter implements IPopup {
6
8
  /**
@@ -37,11 +39,6 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
37
39
  * @protected
38
40
  */
39
41
  protected contentPanel: HTMLElement;
40
- /**
41
- * popup 内容标题
42
- * @protected
43
- */
44
- protected title: HTMLElement;
45
42
  /**
46
43
  * 气泡箭头对应的 DOM
47
44
  * @protected
@@ -71,12 +68,13 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
71
68
  * 设置 HTML 内容
72
69
  * @param html
73
70
  */
74
- setHTML(html: PopupHTML): this;
71
+ setHTML(html: ElementType): this;
75
72
  /**
76
73
  * 设置 Popup 展示文本
77
74
  * @param text
78
75
  */
79
76
  setText(text: string): this;
77
+ setTitle(title?: ElementType): void;
80
78
  /**
81
79
  * 将地图自动平移到气泡位置
82
80
  */
@@ -106,9 +104,9 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
106
104
  protected getDefault(option: Partial<O>): O;
107
105
  /**
108
106
  * 设置 Popup 内容 HTML
109
- * @param htmlNode
107
+ * @param element
110
108
  */
111
- protected setDOMContent(htmlNode: ChildNode | DocumentFragment): this;
109
+ protected setDOMContent(element: ElementType): this;
112
110
  /**
113
111
  * 绑定地图点击事件触发销毁 Popup
114
112
  * @protected
@@ -138,10 +136,4 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
138
136
  * @protected
139
137
  */
140
138
  protected checkUpdateOption(option: Partial<O>, keys: Array<keyof O>): boolean;
141
- /**
142
- * 根据参数 HTML 片段返回对应的 Fragment
143
- * @param html
144
- * @protected
145
- */
146
- protected getPopupHTMLFragment(html: PopupHTML): DocumentFragment;
147
139
  }
package/es/popup/popup.js CHANGED
@@ -1,4 +1,3 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
@@ -169,11 +168,6 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
169
168
  * @protected
170
169
  */
171
170
 
172
- /**
173
- * popup 内容标题
174
- * @protected
175
- */
176
-
177
171
  /**
178
172
  * 气泡箭头对应的 DOM
179
173
  * @protected
@@ -215,7 +209,8 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
215
209
  this.updateFollowCursor();
216
210
  var _this$popupOption2 = this.popupOption,
217
211
  html = _this$popupOption2.html,
218
- text = _this$popupOption2.text;
212
+ text = _this$popupOption2.text,
213
+ title = _this$popupOption2.title;
219
214
 
220
215
  if (html) {
221
216
  this.setHTML(html);
@@ -223,6 +218,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
223
218
  this.setText(text);
224
219
  }
225
220
 
221
+ if (title) {
222
+ this.setTitle(title);
223
+ }
224
+
226
225
  this.emit('open');
227
226
  return this;
228
227
  } // 移除popup
@@ -273,13 +272,17 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
273
272
  this.show();
274
273
  this.popupOption = _objectSpread(_objectSpread({}, this.popupOption), option);
275
274
 
276
- if (this.checkUpdateOption(option, ['closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets', 'title'])) {
275
+ if (this.checkUpdateOption(option, ['closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
277
276
  if (this.container) {
278
277
  DOM.remove(this.container); // @ts-ignore
279
278
 
280
279
  this.container = undefined;
281
280
  }
282
281
 
282
+ if (this.popupOption.title) {
283
+ this.setTitle(this.popupOption.title);
284
+ }
285
+
283
286
  if (this.popupOption.html) {
284
287
  this.setHTML(this.popupOption.html);
285
288
  } else if (this.popupOption.text) {
@@ -305,6 +308,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
305
308
  this.setText(option.text);
306
309
  }
307
310
 
311
+ if (this.checkUpdateOption(option, ['title'])) {
312
+ this.setTitle(option.title);
313
+ }
314
+
308
315
  if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
309
316
  this.setLnglat(option.lngLat);
310
317
  }
@@ -362,7 +369,7 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
362
369
  key: "setHTML",
363
370
  value: function setHTML(html) {
364
371
  this.popupOption.html = html;
365
- return this.setDOMContent(this.getPopupHTMLFragment(html));
372
+ return this.setDOMContent(html);
366
373
  }
367
374
  /**
368
375
  * 设置 Popup 展示文本
@@ -375,6 +382,29 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
375
382
  this.popupOption.text = text;
376
383
  return this.setDOMContent(window.document.createTextNode(text));
377
384
  }
385
+ }, {
386
+ key: "setTitle",
387
+ value: function setTitle(title) {
388
+ this.show();
389
+
390
+ if (title) {
391
+ if (!this.contentTitle) {
392
+ this.contentTitle = DOM.create('div', 'l7-popup-content__title');
393
+
394
+ if (this.content.firstChild) {
395
+ this.content.insertBefore(this.contentTitle, this.content.firstChild);
396
+ } else {
397
+ this.content.append(this.contentTitle);
398
+ }
399
+ }
400
+
401
+ DOM.clearChildren(this.contentTitle);
402
+ DOM.appendElementType(this.contentTitle, title);
403
+ } else if (this.contentTitle) {
404
+ DOM.remove(this.contentTitle);
405
+ this.contentTitle = undefined;
406
+ }
407
+ }
378
408
  /**
379
409
  * 将地图自动平移到气泡位置
380
410
  */
@@ -481,15 +511,15 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
481
511
  }
482
512
  /**
483
513
  * 设置 Popup 内容 HTML
484
- * @param htmlNode
514
+ * @param element
485
515
  */
486
516
 
487
517
  }, {
488
518
  key: "setDOMContent",
489
- value: function setDOMContent(htmlNode) {
519
+ value: function setDOMContent(element) {
490
520
  this.show();
491
521
  this.createContent();
492
- this.contentPanel.appendChild(htmlNode);
522
+ DOM.appendElementType(this.contentPanel, element);
493
523
  this.update();
494
524
  return this;
495
525
  }
@@ -553,17 +583,9 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
553
583
  DOM.remove(this.content);
554
584
  }
555
585
 
586
+ this.contentTitle = undefined;
556
587
  this.content = DOM.create('div', 'l7-popup-content', this.container);
557
588
 
558
- if (this.popupOption.title) {
559
- var _this$contentTitle;
560
-
561
- this.contentTitle = DOM.create('div', 'l7-popup-content__title', this.content);
562
- (_this$contentTitle = this.contentTitle) === null || _this$contentTitle === void 0 ? void 0 : _this$contentTitle.append(this.getPopupHTMLFragment(this.popupOption.title));
563
- } else {
564
- this.contentTitle = undefined;
565
- }
566
-
567
589
  if (this.popupOption.closeButton) {
568
590
  var closeButton = createL7Icon('l7-icon-guanbi');
569
591
  DOM.addClass(closeButton, 'l7-popup-close-button');
@@ -617,39 +639,6 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
617
639
  return key in option;
618
640
  });
619
641
  }
620
- /**
621
- * 根据参数 HTML 片段返回对应的 Fragment
622
- * @param html
623
- * @protected
624
- */
625
-
626
- }, {
627
- key: "getPopupHTMLFragment",
628
- value: function getPopupHTMLFragment(html) {
629
- var frag = window.document.createDocumentFragment();
630
- var temp = window.document.createElement('body');
631
- var child;
632
-
633
- if (typeof html === 'string') {
634
- temp.innerHTML = html;
635
- } else if (Array.isArray(html)) {
636
- temp.append.apply(temp, _toConsumableArray(html));
637
- } else if (html instanceof HTMLElement) {
638
- temp.append(html);
639
- }
640
-
641
- while (true) {
642
- child = temp.firstChild;
643
-
644
- if (!child) {
645
- break;
646
- }
647
-
648
- frag.appendChild(child);
649
- }
650
-
651
- return frag;
652
- }
653
642
  }]);
654
643
 
655
644
  return Popup;
@@ -100,6 +100,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
100
100
  },
101
101
  offsets: [0, 10],
102
102
  closeButton: false,
103
+ closeOnClick: false,
103
104
  autoClose: false,
104
105
  closeOnEsc: false
105
106
  });
@@ -199,15 +200,16 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
199
200
  key: "onLayerMouseMove",
200
201
  value: function onLayerMouseMove(layer, e) {
201
202
  if (!this.isSameFeature(layer, e.featureId)) {
202
- var frag = this.getLayerInfoFrag(layer, e);
203
- this.setDOMContent(frag);
203
+ var _this$getLayerInfoFra = this.getLayerInfoFrag(layer, e),
204
+ title = _this$getLayerInfoFra.title,
205
+ content = _this$getLayerInfoFra.content;
206
+
207
+ this.setDOMContent(content);
208
+ this.setTitle(title);
204
209
  this.displayFeatureInfo = {
205
210
  layer: layer,
206
211
  featureId: e.featureId
207
212
  };
208
- }
209
-
210
- if (!this.isShow) {
211
213
  this.show();
212
214
  }
213
215
  } // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -227,14 +229,18 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
227
229
  if (this.isShow && this.isSameFeature(layer, e.featureId)) {
228
230
  this.hide();
229
231
  } else {
230
- var frag = this.getLayerInfoFrag(layer, e);
231
- this.setDOMContent(frag);
232
+ var _this$getLayerInfoFra2 = this.getLayerInfoFrag(layer, e),
233
+ title = _this$getLayerInfoFra2.title,
234
+ content = _this$getLayerInfoFra2.content;
235
+
236
+ this.setDOMContent(content);
232
237
  this.setLnglat(e.lngLat);
233
- this.show();
238
+ this.setTitle(title);
234
239
  this.displayFeatureInfo = {
235
240
  layer: layer,
236
241
  featureId: e.featureId
237
242
  };
243
+ this.show();
238
244
  }
239
245
  }
240
246
  }, {
@@ -258,7 +264,8 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
258
264
  key: "getLayerInfoFrag",
259
265
  value: function getLayerInfoFrag(layer, e) {
260
266
  var layerInfo = this.layerConfigMap.get(layer);
261
- var frag = document.createDocumentFragment();
267
+ var titleFrag;
268
+ var contentFrag = document.createDocumentFragment();
262
269
 
263
270
  if (layerInfo) {
264
271
  var _feature = e.feature;
@@ -267,30 +274,59 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
267
274
  _feature = _feature.properties;
268
275
  }
269
276
 
270
- var fields = layerInfo.fields;
271
- fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
272
- var _ref3, _ref4;
273
-
274
- var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
275
- {
276
- field: fieldConfig
277
- } : fieldConfig,
278
- field = _ref2.field,
279
- formatField = _ref2.formatField,
280
- formatValue = _ref2.formatValue,
281
- getValue = _ref2.getValue;
282
-
283
- var row = _l7Utils.DOM.create('div', 'l7-layer-popup__row');
284
-
285
- var value = getValue ? getValue(e.feature) : (0, _lodash.get)(_feature, field);
286
- var fieldText = (_ref3 = formatField instanceof Function ? formatField(field) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
287
- var valueText = (_ref4 = formatValue instanceof Function ? formatValue(value) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
288
- row.innerHTML = "<span class=\"l7-layer-popup__key\">".concat(fieldText, "</span>: <span class=\"l7-layer-popup__value\">").concat(valueText, "</span>");
289
- frag.appendChild(row);
290
- });
277
+ var title = layerInfo.title,
278
+ fields = layerInfo.fields,
279
+ customContent = layerInfo.customContent;
280
+
281
+ if (title) {
282
+ titleFrag = document.createDocumentFragment();
283
+ var titleElement = title instanceof Function ? title(_feature) : title;
284
+
285
+ _l7Utils.DOM.appendElementType(titleFrag, titleElement);
286
+ }
287
+
288
+ if (customContent) {
289
+ var content = customContent instanceof Function ? customContent(_feature) : customContent;
290
+
291
+ _l7Utils.DOM.appendElementType(contentFrag, content);
292
+ } else if (fields !== null && fields !== void 0 && fields.length) {
293
+ fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
294
+ var _ref3, _ref4;
295
+
296
+ var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
297
+ {
298
+ field: fieldConfig
299
+ } : fieldConfig,
300
+ field = _ref2.field,
301
+ formatField = _ref2.formatField,
302
+ formatValue = _ref2.formatValue,
303
+ getValue = _ref2.getValue;
304
+
305
+ var row = _l7Utils.DOM.create('div', 'l7-layer-popup__row');
306
+
307
+ var value = getValue ? getValue(e.feature) : (0, _lodash.get)(_feature, field);
308
+ var fieldElement = (_ref3 = formatField instanceof Function ? formatField(field, _feature) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
309
+ var valueElement = (_ref4 = formatValue instanceof Function ? formatValue(value, _feature) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
310
+
311
+ var fieldSpan = _l7Utils.DOM.create('span', 'l7-layer-popup__key', row);
312
+
313
+ _l7Utils.DOM.appendElementType(fieldSpan, fieldElement);
314
+
315
+ _l7Utils.DOM.appendElementType(fieldSpan, document.createTextNode(':'));
316
+
317
+ var valueSpan = _l7Utils.DOM.create('span', 'l7-layer-popup__value', row);
318
+
319
+ _l7Utils.DOM.appendElementType(valueSpan, valueElement);
320
+
321
+ contentFrag.appendChild(row);
322
+ });
323
+ }
291
324
  }
292
325
 
293
- return frag;
326
+ return {
327
+ title: titleFrag,
328
+ content: contentFrag
329
+ };
294
330
  }
295
331
  /**
296
332
  * 通过 Layer 配置访问到真实的 Layer 实例
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = exports.Popup = void 0;
9
9
 
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
11
 
14
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -181,11 +179,6 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
181
179
  * @protected
182
180
  */
183
181
 
184
- /**
185
- * popup 内容标题
186
- * @protected
187
- */
188
-
189
182
  /**
190
183
  * 气泡箭头对应的 DOM
191
184
  * @protected
@@ -227,7 +220,8 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
227
220
  this.updateFollowCursor();
228
221
  var _this$popupOption2 = this.popupOption,
229
222
  html = _this$popupOption2.html,
230
- text = _this$popupOption2.text;
223
+ text = _this$popupOption2.text,
224
+ title = _this$popupOption2.title;
231
225
 
232
226
  if (html) {
233
227
  this.setHTML(html);
@@ -235,6 +229,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
235
229
  this.setText(text);
236
230
  }
237
231
 
232
+ if (title) {
233
+ this.setTitle(title);
234
+ }
235
+
238
236
  this.emit('open');
239
237
  return this;
240
238
  } // 移除popup
@@ -286,7 +284,7 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
286
284
  this.show();
287
285
  this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.popupOption), option);
288
286
 
289
- if (this.checkUpdateOption(option, ['closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets', 'title'])) {
287
+ if (this.checkUpdateOption(option, ['closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
290
288
  if (this.container) {
291
289
  _l7Utils.DOM.remove(this.container); // @ts-ignore
292
290
 
@@ -294,6 +292,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
294
292
  this.container = undefined;
295
293
  }
296
294
 
295
+ if (this.popupOption.title) {
296
+ this.setTitle(this.popupOption.title);
297
+ }
298
+
297
299
  if (this.popupOption.html) {
298
300
  this.setHTML(this.popupOption.html);
299
301
  } else if (this.popupOption.text) {
@@ -319,6 +321,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
319
321
  this.setText(option.text);
320
322
  }
321
323
 
324
+ if (this.checkUpdateOption(option, ['title'])) {
325
+ this.setTitle(option.title);
326
+ }
327
+
322
328
  if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
323
329
  this.setLnglat(option.lngLat);
324
330
  }
@@ -376,7 +382,7 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
376
382
  key: "setHTML",
377
383
  value: function setHTML(html) {
378
384
  this.popupOption.html = html;
379
- return this.setDOMContent(this.getPopupHTMLFragment(html));
385
+ return this.setDOMContent(html);
380
386
  }
381
387
  /**
382
388
  * 设置 Popup 展示文本
@@ -389,6 +395,31 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
389
395
  this.popupOption.text = text;
390
396
  return this.setDOMContent(window.document.createTextNode(text));
391
397
  }
398
+ }, {
399
+ key: "setTitle",
400
+ value: function setTitle(title) {
401
+ this.show();
402
+
403
+ if (title) {
404
+ if (!this.contentTitle) {
405
+ this.contentTitle = _l7Utils.DOM.create('div', 'l7-popup-content__title');
406
+
407
+ if (this.content.firstChild) {
408
+ this.content.insertBefore(this.contentTitle, this.content.firstChild);
409
+ } else {
410
+ this.content.append(this.contentTitle);
411
+ }
412
+ }
413
+
414
+ _l7Utils.DOM.clearChildren(this.contentTitle);
415
+
416
+ _l7Utils.DOM.appendElementType(this.contentTitle, title);
417
+ } else if (this.contentTitle) {
418
+ _l7Utils.DOM.remove(this.contentTitle);
419
+
420
+ this.contentTitle = undefined;
421
+ }
422
+ }
392
423
  /**
393
424
  * 将地图自动平移到气泡位置
394
425
  */
@@ -495,15 +526,17 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
495
526
  }
496
527
  /**
497
528
  * 设置 Popup 内容 HTML
498
- * @param htmlNode
529
+ * @param element
499
530
  */
500
531
 
501
532
  }, {
502
533
  key: "setDOMContent",
503
- value: function setDOMContent(htmlNode) {
534
+ value: function setDOMContent(element) {
504
535
  this.show();
505
536
  this.createContent();
506
- this.contentPanel.appendChild(htmlNode);
537
+
538
+ _l7Utils.DOM.appendElementType(this.contentPanel, element);
539
+
507
540
  this.update();
508
541
  return this;
509
542
  }
@@ -567,17 +600,9 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
567
600
  _l7Utils.DOM.remove(this.content);
568
601
  }
569
602
 
603
+ this.contentTitle = undefined;
570
604
  this.content = _l7Utils.DOM.create('div', 'l7-popup-content', this.container);
571
605
 
572
- if (this.popupOption.title) {
573
- var _this$contentTitle;
574
-
575
- this.contentTitle = _l7Utils.DOM.create('div', 'l7-popup-content__title', this.content);
576
- (_this$contentTitle = this.contentTitle) === null || _this$contentTitle === void 0 ? void 0 : _this$contentTitle.append(this.getPopupHTMLFragment(this.popupOption.title));
577
- } else {
578
- this.contentTitle = undefined;
579
- }
580
-
581
606
  if (this.popupOption.closeButton) {
582
607
  var closeButton = (0, _icon.createL7Icon)('l7-icon-guanbi');
583
608
 
@@ -633,39 +658,6 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
633
658
  return key in option;
634
659
  });
635
660
  }
636
- /**
637
- * 根据参数 HTML 片段返回对应的 Fragment
638
- * @param html
639
- * @protected
640
- */
641
-
642
- }, {
643
- key: "getPopupHTMLFragment",
644
- value: function getPopupHTMLFragment(html) {
645
- var frag = window.document.createDocumentFragment();
646
- var temp = window.document.createElement('body');
647
- var child;
648
-
649
- if (typeof html === 'string') {
650
- temp.innerHTML = html;
651
- } else if (Array.isArray(html)) {
652
- temp.append.apply(temp, (0, _toConsumableArray2.default)(html));
653
- } else if (html instanceof HTMLElement) {
654
- temp.append(html);
655
- }
656
-
657
- while (true) {
658
- child = temp.firstChild;
659
-
660
- if (!child) {
661
- break;
662
- }
663
-
664
- frag.appendChild(child);
665
- }
666
-
667
- return frag;
668
- }
669
661
  }]);
670
662
  return Popup;
671
663
  }(_eventemitter.EventEmitter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-component",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -26,8 +26,8 @@
26
26
  "author": "lzxue",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
- "@antv/l7-core": "2.11.2",
30
- "@antv/l7-utils": "2.11.2",
29
+ "@antv/l7-core": "2.11.4",
30
+ "@antv/l7-utils": "2.11.4",
31
31
  "@babel/runtime": "^7.7.7",
32
32
  "eventemitter3": "^4.0.0",
33
33
  "inversify": "^5.0.1",
@@ -36,11 +36,11 @@
36
36
  "supercluster": "^7.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@antv/l7-test-utils": "2.11.2",
39
+ "@antv/l7-test-utils": "2.11.4",
40
40
  "gcoord": "^0.3.2",
41
41
  "less": "^4.1.3"
42
42
  },
43
- "gitHead": "736a5ea590dca72c2ac2b0ded9f371ad4c95a72a",
43
+ "gitHead": "ba7891204096a2d565fffdf27210ed98e7d26ebf",
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  }