@antv/l7-component 2.10.7 → 2.10.9

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,8 +1,8 @@
1
- import { ELType } from '@antv/l7-utils/src/dom';
1
+ import { DOM } from '@antv/l7-utils';
2
2
  import Control, { IControlOption } from './control';
3
3
  export { ButtonControl };
4
4
  export interface IButtonControlOption extends IControlOption {
5
- btnIcon?: ELType | DocumentFragment;
5
+ btnIcon?: DOM.ELType | DocumentFragment;
6
6
  btnText?: string;
7
7
  title?: string;
8
8
  vertical?: boolean;
@@ -27,7 +27,7 @@ export default class ButtonControl<O extends IButtonControlOption = IButtonContr
27
27
  * 按钮中图标对应的 DOM
28
28
  * @protected
29
29
  */
30
- protected buttonIcon?: ELType | DocumentFragment;
30
+ protected buttonIcon?: DOM.ELType | DocumentFragment;
31
31
  /**
32
32
  * 设置当前按钮
33
33
  * @param newIsDisable
@@ -1,16 +1,16 @@
1
1
  import { IPopperControlOption, PopperControl } from './popperControl';
2
- declare type BaseOptionItem = {
2
+ type BaseOptionItem = {
3
3
  value: string;
4
4
  text: string;
5
5
  [key: string]: string;
6
6
  };
7
- declare type NormalOptionItem = BaseOptionItem & {
7
+ type NormalOptionItem = BaseOptionItem & {
8
8
  icon?: HTMLElement;
9
9
  };
10
- declare type ImageOptionItem = BaseOptionItem & {
10
+ type ImageOptionItem = BaseOptionItem & {
11
11
  img: string;
12
12
  };
13
- export declare type ControlOptionItem = ImageOptionItem | NormalOptionItem;
13
+ export type ControlOptionItem = ImageOptionItem | NormalOptionItem;
14
14
  export interface ISelectControlOption extends IPopperControlOption {
15
15
  options: ControlOptionItem[];
16
16
  defaultValue?: string | string[];
@@ -1,10 +1,10 @@
1
1
  import { PositionType } from '@antv/l7-core';
2
- import { ELType } from '@antv/l7-utils/src/dom';
2
+ import { DOM } from '@antv/l7-utils';
3
3
  import { Control, IControlOption } from './baseControl';
4
4
  export interface IZoomControlOption extends IControlOption {
5
- zoomInText: ELType | string;
5
+ zoomInText: DOM.ELType | string;
6
6
  zoomInTitle: string;
7
- zoomOutText: ELType | string;
7
+ zoomOutText: DOM.ELType | string;
8
8
  zoomOutTitle: string;
9
9
  }
10
10
  export { Zoom };
package/es/interface.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type ControlEvent = 'show' | 'hide' | 'add' | 'remove' | string;
1
+ export type ControlEvent = 'show' | 'hide' | 'add' | 'remove' | string;
2
2
  export interface IMarkerStyleOption {
3
3
  element?: (...args: any[]) => any;
4
4
  style: {
@@ -1,21 +1,22 @@
1
1
  import { ILayer, IPopupOption } from '@antv/l7-core';
2
2
  import { Container } from 'inversify';
3
3
  import Popup from './popup';
4
- export declare type LayerField = {
4
+ export type LayerField = {
5
5
  field: string;
6
- formatField?: (field: string) => string;
7
- formatValue?: (value: any) => any;
6
+ formatField?: ((field: string) => string) | string;
7
+ formatValue?: ((value: any) => any) | string;
8
8
  getValue?: (feature: any) => any;
9
9
  };
10
- export declare type LayerPopupConfigItem = {
10
+ export type LayerPopupConfigItem = {
11
11
  layer: ILayer | string;
12
12
  fields: Array<LayerField | string>;
13
13
  };
14
14
  export interface ILayerPopupOption extends IPopupOption {
15
- config: LayerPopupConfigItem[];
15
+ config?: LayerPopupConfigItem[];
16
+ items?: LayerPopupConfigItem[];
16
17
  trigger: 'hover' | 'click';
17
18
  }
18
- declare type LayerMapInfo = {
19
+ type LayerMapInfo = {
19
20
  onMouseMove?: (layer: ILayer, e: any) => void;
20
21
  onMouseOut?: (layer: ILayer, e: any) => void;
21
22
  onClick?: (layer: ILayer, e: any) => void;
@@ -36,6 +37,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
36
37
  layer: ILayer;
37
38
  featureId: number;
38
39
  };
40
+ protected get layerConfigItems(): LayerPopupConfigItem[];
39
41
  addTo(scene: Container): this;
40
42
  remove(): this;
41
43
  setOptions(option: Partial<ILayerPopupOption>): this;
@@ -63,10 +65,10 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
63
65
  protected getLayerInfoFrag(layer: ILayer, e: any): DocumentFragment;
64
66
  /**
65
67
  * 通过 Layer 配置访问到真实的 Layer 实例
66
- * @param config
68
+ * @param configItem
67
69
  * @protected
68
70
  */
69
- protected getLayerByConfig(config: LayerPopupConfigItem): ILayer | undefined;
71
+ protected getLayerByConfig(configItem: LayerPopupConfigItem): ILayer | undefined;
70
72
  /**
71
73
  * 判断当前展示的 Feature 是否和上一次查看的一致
72
74
  * @param layer
@@ -40,6 +40,16 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
40
40
  }
41
41
 
42
42
  _createClass(LayerPopup, [{
43
+ key: "layerConfigItems",
44
+ get: function get() {
45
+ var _ref;
46
+
47
+ var _this$popupOption = this.popupOption,
48
+ config = _this$popupOption.config,
49
+ items = _this$popupOption.items;
50
+ return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
51
+ }
52
+ }, {
43
53
  key: "addTo",
44
54
  value: function addTo(scene) {
45
55
  _get(_getPrototypeOf(LayerPopup.prototype), "addTo", this).call(this, scene);
@@ -94,10 +104,10 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
94
104
  value: function bindLayerEvent() {
95
105
  var _this2 = this;
96
106
 
97
- var _this$popupOption = this.popupOption,
98
- config = _this$popupOption.config,
99
- trigger = _this$popupOption.trigger;
100
- config.forEach(function (configItem) {
107
+ var trigger = this.popupOption.trigger;
108
+ this.layerConfigItems.forEach(function (configItem) {
109
+ var _layer$getSource;
110
+
101
111
  var layer = _this2.getLayerByConfig(configItem);
102
112
 
103
113
  if (!layer) {
@@ -122,7 +132,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
122
132
  layer === null || layer === void 0 ? void 0 : layer.on('click', onClick);
123
133
  }
124
134
 
125
- var source = layer.getSource();
135
+ var source = layer === null || layer === void 0 ? void 0 : (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
126
136
 
127
137
  var onSourceUpdate = _this2.onSourceUpdate.bind(_this2, layer);
128
138
 
@@ -142,8 +152,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
142
152
  value: function unbindLayerEvent() {
143
153
  var _this3 = this;
144
154
 
145
- var config = this.popupOption.config;
146
- config.forEach(function (configItem) {
155
+ this.layerConfigItems.forEach(function (configItem) {
147
156
  var layer = _this3.getLayerByConfig(configItem);
148
157
 
149
158
  var layerInfo = layer && _this3.layerConfigMap.get(layer);
@@ -170,9 +179,9 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
170
179
  }
171
180
 
172
181
  if (onSourceUpdate) {
173
- var _layer$getSource;
182
+ var _layer$getSource2;
174
183
 
175
- layer === null || layer === void 0 ? void 0 : (_layer$getSource = layer.getSource()) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.off('update', onSourceUpdate);
184
+ layer === null || layer === void 0 ? void 0 : (_layer$getSource2 = layer.getSource()) === null || _layer$getSource2 === void 0 ? void 0 : _layer$getSource2.off('update', onSourceUpdate);
176
185
  }
177
186
  });
178
187
  }
@@ -250,17 +259,22 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
250
259
 
251
260
  var fields = layerInfo.fields;
252
261
  fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
253
- var _ref = typeof fieldConfig === 'string' ? {
262
+ var _ref3, _ref4;
263
+
264
+ var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
265
+ {
254
266
  field: fieldConfig
255
267
  } : fieldConfig,
256
- field = _ref.field,
257
- formatField = _ref.formatField,
258
- formatValue = _ref.formatValue,
259
- getValue = _ref.getValue;
268
+ field = _ref2.field,
269
+ formatField = _ref2.formatField,
270
+ formatValue = _ref2.formatValue,
271
+ getValue = _ref2.getValue;
260
272
 
261
273
  var row = DOM.create('div', 'l7-layer-popup__row');
262
274
  var value = getValue ? getValue(e.feature) : get(_feature, field);
263
- row.innerHTML = "".concat(formatField ? formatField(field) : field, ": ").concat(formatValue ? formatValue(value) : value);
275
+ var fieldText = (_ref3 = formatField instanceof Function ? formatField(field) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
276
+ var valueText = (_ref4 = formatValue instanceof Function ? formatValue(value) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
277
+ row.innerHTML = "<span class=\"l7-layer-popup__key\">".concat(fieldText, "</span>: <span class=\"l7-layer-popup__value\">").concat(valueText, "</span>");
264
278
  frag.appendChild(row);
265
279
  });
266
280
  }
@@ -269,14 +283,14 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
269
283
  }
270
284
  /**
271
285
  * 通过 Layer 配置访问到真实的 Layer 实例
272
- * @param config
286
+ * @param configItem
273
287
  * @protected
274
288
  */
275
289
 
276
290
  }, {
277
291
  key: "getLayerByConfig",
278
- value: function getLayerByConfig(config) {
279
- var layer = config.layer;
292
+ value: function getLayerByConfig(configItem) {
293
+ var layer = configItem.layer;
280
294
 
281
295
  if (layer instanceof Object) {
282
296
  return layer;
package/es/popup/popup.js CHANGED
@@ -497,30 +497,49 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
497
497
  }, {
498
498
  key: "updateCloseOnClick",
499
499
  value: function updateCloseOnClick(onlyClear) {
500
- this.mapsService.off('click', this.onCloseButtonClick);
500
+ var _this3 = this;
501
501
 
502
- if (this.popupOption.closeOnClick && !onlyClear) {
503
- this.mapsService.on('click', this.onCloseButtonClick);
502
+ var mapsService = this.mapsService;
503
+
504
+ if (mapsService) {
505
+ this.mapsService.off('click', this.onCloseButtonClick);
506
+
507
+ if (this.popupOption.closeOnClick && !onlyClear) {
508
+ requestAnimationFrame(function () {
509
+ _this3.mapsService.on('click', _this3.onCloseButtonClick);
510
+ });
511
+ }
504
512
  }
505
513
  }
506
514
  }, {
507
515
  key: "updateCloseOnEsc",
508
516
  value: function updateCloseOnEsc(onlyClear) {
517
+ var _this4 = this;
518
+
509
519
  window.removeEventListener('keydown', this.onKeyDown);
510
520
 
511
521
  if (this.popupOption.closeOnEsc && !onlyClear) {
512
- window.addEventListener('keydown', this.onKeyDown);
522
+ requestAnimationFrame(function () {
523
+ window.addEventListener('keydown', _this4.onKeyDown);
524
+ });
513
525
  }
514
526
  }
515
527
  }, {
516
528
  key: "updateFollowCursor",
517
529
  value: function updateFollowCursor(onlyClear) {
518
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
519
- var container = this.mapsService.getContainer();
520
- container.removeEventListener('mousemove', this.onMouseMove);
530
+ var _this$mapsService,
531
+ _this5 = this;
521
532
 
522
- if (this.popupOption.followCursor && !onlyClear) {
523
- container.addEventListener('mousemove', this.onMouseMove);
533
+ var container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
534
+
535
+ if (container) {
536
+ container.removeEventListener('mousemove', this.onMouseMove);
537
+
538
+ if (this.popupOption.followCursor && !onlyClear) {
539
+ requestAnimationFrame(function () {
540
+ container.addEventListener('mousemove', _this5.onMouseMove);
541
+ });
542
+ }
524
543
  }
525
544
  }
526
545
  }, {
@@ -2,15 +2,15 @@ import { EventEmitter } from 'eventemitter3';
2
2
  /**
3
3
  * 气泡位置枚举
4
4
  */
5
- export declare type PopperPlacement = 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'right-start' | 'right' | 'right-end';
5
+ export type PopperPlacement = 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'right-start' | 'right' | 'right-end';
6
6
  /**
7
7
  * 气泡触发类型,当前支持 click 和 hover 两种类型
8
8
  */
9
- export declare type PopperTrigger = 'click' | 'hover';
9
+ export type PopperTrigger = 'click' | 'hover';
10
10
  /**
11
11
  * 气泡内容类型
12
12
  */
13
- export declare type PopperContent = string | HTMLElement | null;
13
+ export type PopperContent = string | HTMLElement | null;
14
14
  export interface IPopperOption {
15
15
  placement: PopperPlacement;
16
16
  trigger: PopperTrigger;
@@ -55,6 +55,16 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
55
55
  }
56
56
 
57
57
  (0, _createClass2.default)(LayerPopup, [{
58
+ key: "layerConfigItems",
59
+ get: function get() {
60
+ var _ref;
61
+
62
+ var _this$popupOption = this.popupOption,
63
+ config = _this$popupOption.config,
64
+ items = _this$popupOption.items;
65
+ return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
66
+ }
67
+ }, {
58
68
  key: "addTo",
59
69
  value: function addTo(scene) {
60
70
  (0, _get2.default)((0, _getPrototypeOf2.default)(LayerPopup.prototype), "addTo", this).call(this, scene);
@@ -105,10 +115,10 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
105
115
  value: function bindLayerEvent() {
106
116
  var _this2 = this;
107
117
 
108
- var _this$popupOption = this.popupOption,
109
- config = _this$popupOption.config,
110
- trigger = _this$popupOption.trigger;
111
- config.forEach(function (configItem) {
118
+ var trigger = this.popupOption.trigger;
119
+ this.layerConfigItems.forEach(function (configItem) {
120
+ var _layer$getSource;
121
+
112
122
  var layer = _this2.getLayerByConfig(configItem);
113
123
 
114
124
  if (!layer) {
@@ -133,7 +143,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
133
143
  layer === null || layer === void 0 ? void 0 : layer.on('click', onClick);
134
144
  }
135
145
 
136
- var source = layer.getSource();
146
+ var source = layer === null || layer === void 0 ? void 0 : (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
137
147
 
138
148
  var onSourceUpdate = _this2.onSourceUpdate.bind(_this2, layer);
139
149
 
@@ -153,8 +163,7 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
153
163
  value: function unbindLayerEvent() {
154
164
  var _this3 = this;
155
165
 
156
- var config = this.popupOption.config;
157
- config.forEach(function (configItem) {
166
+ this.layerConfigItems.forEach(function (configItem) {
158
167
  var layer = _this3.getLayerByConfig(configItem);
159
168
 
160
169
  var layerInfo = layer && _this3.layerConfigMap.get(layer);
@@ -181,9 +190,9 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
181
190
  }
182
191
 
183
192
  if (onSourceUpdate) {
184
- var _layer$getSource;
193
+ var _layer$getSource2;
185
194
 
186
- layer === null || layer === void 0 ? void 0 : (_layer$getSource = layer.getSource()) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.off('update', onSourceUpdate);
195
+ layer === null || layer === void 0 ? void 0 : (_layer$getSource2 = layer.getSource()) === null || _layer$getSource2 === void 0 ? void 0 : _layer$getSource2.off('update', onSourceUpdate);
187
196
  }
188
197
  });
189
198
  }
@@ -261,18 +270,23 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
261
270
 
262
271
  var fields = layerInfo.fields;
263
272
  fields === null || fields === void 0 ? void 0 : fields.forEach(function (fieldConfig) {
264
- var _ref = typeof fieldConfig === 'string' ? {
273
+ var _ref3, _ref4;
274
+
275
+ var _ref2 = typeof fieldConfig === 'string' ? // tslint:disable-next-line:no-object-literal-type-assertion
276
+ {
265
277
  field: fieldConfig
266
278
  } : fieldConfig,
267
- field = _ref.field,
268
- formatField = _ref.formatField,
269
- formatValue = _ref.formatValue,
270
- getValue = _ref.getValue;
279
+ field = _ref2.field,
280
+ formatField = _ref2.formatField,
281
+ formatValue = _ref2.formatValue,
282
+ getValue = _ref2.getValue;
271
283
 
272
284
  var row = _l7Utils.DOM.create('div', 'l7-layer-popup__row');
273
285
 
274
286
  var value = getValue ? getValue(e.feature) : (0, _lodash.get)(_feature, field);
275
- row.innerHTML = "".concat(formatField ? formatField(field) : field, ": ").concat(formatValue ? formatValue(value) : value);
287
+ var fieldText = (_ref3 = formatField instanceof Function ? formatField(field) : formatField) !== null && _ref3 !== void 0 ? _ref3 : field;
288
+ var valueText = (_ref4 = formatValue instanceof Function ? formatValue(value) : formatValue) !== null && _ref4 !== void 0 ? _ref4 : value;
289
+ row.innerHTML = "<span class=\"l7-layer-popup__key\">".concat(fieldText, "</span>: <span class=\"l7-layer-popup__value\">").concat(valueText, "</span>");
276
290
  frag.appendChild(row);
277
291
  });
278
292
  }
@@ -281,14 +295,14 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
281
295
  }
282
296
  /**
283
297
  * 通过 Layer 配置访问到真实的 Layer 实例
284
- * @param config
298
+ * @param configItem
285
299
  * @protected
286
300
  */
287
301
 
288
302
  }, {
289
303
  key: "getLayerByConfig",
290
- value: function getLayerByConfig(config) {
291
- var layer = config.layer;
304
+ value: function getLayerByConfig(configItem) {
305
+ var layer = configItem.layer;
292
306
 
293
307
  if (layer instanceof Object) {
294
308
  return layer;
@@ -511,30 +511,49 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
511
511
  }, {
512
512
  key: "updateCloseOnClick",
513
513
  value: function updateCloseOnClick(onlyClear) {
514
- this.mapsService.off('click', this.onCloseButtonClick);
514
+ var _this3 = this;
515
515
 
516
- if (this.popupOption.closeOnClick && !onlyClear) {
517
- this.mapsService.on('click', this.onCloseButtonClick);
516
+ var mapsService = this.mapsService;
517
+
518
+ if (mapsService) {
519
+ this.mapsService.off('click', this.onCloseButtonClick);
520
+
521
+ if (this.popupOption.closeOnClick && !onlyClear) {
522
+ requestAnimationFrame(function () {
523
+ _this3.mapsService.on('click', _this3.onCloseButtonClick);
524
+ });
525
+ }
518
526
  }
519
527
  }
520
528
  }, {
521
529
  key: "updateCloseOnEsc",
522
530
  value: function updateCloseOnEsc(onlyClear) {
531
+ var _this4 = this;
532
+
523
533
  window.removeEventListener('keydown', this.onKeyDown);
524
534
 
525
535
  if (this.popupOption.closeOnEsc && !onlyClear) {
526
- window.addEventListener('keydown', this.onKeyDown);
536
+ requestAnimationFrame(function () {
537
+ window.addEventListener('keydown', _this4.onKeyDown);
538
+ });
527
539
  }
528
540
  }
529
541
  }, {
530
542
  key: "updateFollowCursor",
531
543
  value: function updateFollowCursor(onlyClear) {
532
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
533
- var container = this.mapsService.getContainer();
534
- container.removeEventListener('mousemove', this.onMouseMove);
544
+ var _this$mapsService,
545
+ _this5 = this;
535
546
 
536
- if (this.popupOption.followCursor && !onlyClear) {
537
- container.addEventListener('mousemove', this.onMouseMove);
547
+ var container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
548
+
549
+ if (container) {
550
+ container.removeEventListener('mousemove', this.onMouseMove);
551
+
552
+ if (this.popupOption.followCursor && !onlyClear) {
553
+ requestAnimationFrame(function () {
554
+ container.addEventListener('mousemove', _this5.onMouseMove);
555
+ });
556
+ }
538
557
  }
539
558
  }
540
559
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-component",
3
- "version": "2.10.7",
3
+ "version": "2.10.9",
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.10.7",
30
- "@antv/l7-utils": "2.10.7",
29
+ "@antv/l7-core": "2.10.9",
30
+ "@antv/l7-utils": "2.10.9",
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.10.7",
39
+ "@antv/l7-test-utils": "2.10.9",
40
40
  "gcoord": "^0.3.2",
41
41
  "less": "^4.1.3"
42
42
  },
43
- "gitHead": "99a4fe9b4f36e5f4bdac1294e83ff756e9a974d1",
43
+ "gitHead": "9fe64ef00875f4d96771542c16842468e61a8ef4",
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  }