@antv/l7-component 2.22.7 → 2.23.1

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.
@@ -123,7 +123,11 @@ export default class LayerSwitch extends SelectControl {
123
123
  // 如果是单选模式,则只显示第一个图层
124
124
  handleSingleSelection() {
125
125
  this.layers.forEach((layer, index) => {
126
- index === 0 ? layer.show() : layer.hide();
126
+ if (index === 0) {
127
+ layer.show();
128
+ } else {
129
+ layer.hide();
130
+ }
127
131
  });
128
132
  }
129
133
  onAdd() {
@@ -17,7 +17,7 @@ export type LayerPopupConfigItem = {
17
17
  export interface ILayerPopupOption extends IPopupOption {
18
18
  config?: LayerPopupConfigItem[];
19
19
  items?: LayerPopupConfigItem[];
20
- trigger: 'hover' | 'click';
20
+ trigger: 'hover' | 'click' | 'touchend' | 'touchstart';
21
21
  }
22
22
  type LayerMapInfo = {
23
23
  onMouseMove?: (layer: ILayer, e: any) => void;
@@ -45,6 +45,12 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
45
45
  featureId: number;
46
46
  };
47
47
  protected get layerConfigItems(): LayerPopupConfigItem[];
48
+ /**
49
+ * 根据环境获取实际的触发事件
50
+ * 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
51
+ * @protected
52
+ */
53
+ protected getActualTriggerEvent(): "hover" | "click" | "touchstart" | "touchend";
48
54
  addTo(scene: L7Container): this;
49
55
  remove(): this;
50
56
  setOptions(option: Partial<ILayerPopupOption>): this;
@@ -60,7 +66,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
60
66
  */
61
67
  protected unbindLayerEvent(): void;
62
68
  protected onLayerMouseMove(layer: ILayer, e: any): void;
63
- protected onLayerMouseOut(layer: ILayer, e: any): void;
69
+ protected onLayerMouseOut(layer: ILayer): void;
64
70
  protected onLayerClick: (layer: ILayer, e: any) => void;
65
71
  protected onSceneClick: () => void;
66
72
  protected onSourceUpdate(): void;
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- import { DOM, lodashUtil } from '@antv/l7-utils';
3
+ import { DOM, isPC, lodashUtil } from '@antv/l7-utils';
4
4
  import Popup from "./popup";
5
5
  const {
6
6
  get
@@ -72,6 +72,21 @@ export default class LayerPopup extends Popup {
72
72
  } = this.popupOption;
73
73
  return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
74
74
  }
75
+
76
+ /**
77
+ * 根据环境获取实际的触发事件
78
+ * 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
79
+ * @protected
80
+ */
81
+ getActualTriggerEvent() {
82
+ const {
83
+ trigger
84
+ } = this.popupOption;
85
+ if (trigger === 'click') {
86
+ return isPC() ? 'click' : 'touchend';
87
+ }
88
+ return trigger;
89
+ }
75
90
  addTo(scene) {
76
91
  super.addTo(scene);
77
92
  this.bindLayerEvent();
@@ -99,7 +114,7 @@ export default class LayerPopup extends Popup {
99
114
  return this;
100
115
  }
101
116
  getDefault(option) {
102
- const isHoverTrigger = option.trigger !== 'click';
117
+ const isHoverTrigger = option.trigger === 'hover';
103
118
  return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
104
119
  trigger: 'hover',
105
120
  followCursor: isHoverTrigger,
@@ -124,6 +139,7 @@ export default class LayerPopup extends Popup {
124
139
  trigger,
125
140
  closeOnClick
126
141
  } = this.popupOption;
142
+ const actualTrigger = this.getActualTriggerEvent();
127
143
  this.layerConfigItems.forEach(configItem => {
128
144
  var _layer$getSource;
129
145
  const layer = this.getLayerByConfig(configItem);
@@ -142,10 +158,10 @@ export default class LayerPopup extends Popup {
142
158
  var _this$mapsService;
143
159
  const onLayerClick = this.onLayerClick.bind(this, layer);
144
160
  layerInfo.onClick = onLayerClick;
145
- layer === null || layer === void 0 || layer.on('click', onLayerClick);
161
+ layer === null || layer === void 0 || layer.on(actualTrigger, onLayerClick);
146
162
  const mapContainer = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getMapContainer();
147
163
  if (mapContainer && closeOnClick) {
148
- mapContainer.addEventListener('click', this.onSceneClick);
164
+ mapContainer.addEventListener(actualTrigger, this.onSceneClick);
149
165
  }
150
166
  }
151
167
  const source = layer === null || layer === void 0 || (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
@@ -161,6 +177,7 @@ export default class LayerPopup extends Popup {
161
177
  * @protected
162
178
  */
163
179
  unbindLayerEvent() {
180
+ const actualTrigger = this.getActualTriggerEvent();
164
181
  this.layerConfigItems.forEach(configItem => {
165
182
  var _this$mapsService2;
166
183
  const layer = this.getLayerByConfig(configItem);
@@ -181,7 +198,7 @@ export default class LayerPopup extends Popup {
181
198
  layer.off('mouseout', onMouseOut);
182
199
  }
183
200
  if (onClick) {
184
- layer.off('click', onClick);
201
+ layer.off(actualTrigger, onClick);
185
202
  }
186
203
  if (onSourceUpdate) {
187
204
  var _layer$getSource2;
@@ -189,7 +206,7 @@ export default class LayerPopup extends Popup {
189
206
  }
190
207
  const mapContainer = (_this$mapsService2 = this.mapsService) === null || _this$mapsService2 === void 0 ? void 0 : _this$mapsService2.getMapContainer();
191
208
  if (mapContainer) {
192
- mapContainer.removeEventListener('click', this.onSceneClick);
209
+ mapContainer.removeEventListener(actualTrigger, this.onSceneClick);
193
210
  }
194
211
  });
195
212
  }
@@ -208,9 +225,7 @@ export default class LayerPopup extends Popup {
208
225
  this.show();
209
226
  }
210
227
  }
211
-
212
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
213
- onLayerMouseOut(layer, e) {
228
+ onLayerMouseOut(layer) {
214
229
  this.setDisplayFeatureInfo(undefined);
215
230
  if (this.isShow) {
216
231
  this.hide();
package/es/popup/popup.js CHANGED
@@ -436,7 +436,6 @@ export default class Popup extends EventEmitter {
436
436
  isOpen() {
437
437
  return !!this.mapsService;
438
438
  }
439
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
440
439
  getDefault(option) {
441
440
  // tslint:disable-next-line:no-object-literal-type-assertion
442
441
  return {
@@ -129,7 +129,11 @@ class LayerSwitch extends _selectControl.default {
129
129
  // 如果是单选模式,则只显示第一个图层
130
130
  handleSingleSelection() {
131
131
  this.layers.forEach((layer, index) => {
132
- index === 0 ? layer.show() : layer.hide();
132
+ if (index === 0) {
133
+ layer.show();
134
+ } else {
135
+ layer.hide();
136
+ }
133
137
  });
134
138
  }
135
139
  onAdd() {
@@ -17,7 +17,7 @@ export type LayerPopupConfigItem = {
17
17
  export interface ILayerPopupOption extends IPopupOption {
18
18
  config?: LayerPopupConfigItem[];
19
19
  items?: LayerPopupConfigItem[];
20
- trigger: 'hover' | 'click';
20
+ trigger: 'hover' | 'click' | 'touchend' | 'touchstart';
21
21
  }
22
22
  type LayerMapInfo = {
23
23
  onMouseMove?: (layer: ILayer, e: any) => void;
@@ -45,6 +45,12 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
45
45
  featureId: number;
46
46
  };
47
47
  protected get layerConfigItems(): LayerPopupConfigItem[];
48
+ /**
49
+ * 根据环境获取实际的触发事件
50
+ * 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
51
+ * @protected
52
+ */
53
+ protected getActualTriggerEvent(): "hover" | "click" | "touchstart" | "touchend";
48
54
  addTo(scene: L7Container): this;
49
55
  remove(): this;
50
56
  setOptions(option: Partial<ILayerPopupOption>): this;
@@ -60,7 +66,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
60
66
  */
61
67
  protected unbindLayerEvent(): void;
62
68
  protected onLayerMouseMove(layer: ILayer, e: any): void;
63
- protected onLayerMouseOut(layer: ILayer, e: any): void;
69
+ protected onLayerMouseOut(layer: ILayer): void;
64
70
  protected onLayerClick: (layer: ILayer, e: any) => void;
65
71
  protected onSceneClick: () => void;
66
72
  protected onSourceUpdate(): void;
@@ -78,6 +78,21 @@ class LayerPopup extends _popup.default {
78
78
  } = this.popupOption;
79
79
  return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
80
80
  }
81
+
82
+ /**
83
+ * 根据环境获取实际的触发事件
84
+ * 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
85
+ * @protected
86
+ */
87
+ getActualTriggerEvent() {
88
+ const {
89
+ trigger
90
+ } = this.popupOption;
91
+ if (trigger === 'click') {
92
+ return (0, _l7Utils.isPC)() ? 'click' : 'touchend';
93
+ }
94
+ return trigger;
95
+ }
81
96
  addTo(scene) {
82
97
  super.addTo(scene);
83
98
  this.bindLayerEvent();
@@ -105,7 +120,7 @@ class LayerPopup extends _popup.default {
105
120
  return this;
106
121
  }
107
122
  getDefault(option) {
108
- const isHoverTrigger = option.trigger !== 'click';
123
+ const isHoverTrigger = option.trigger === 'hover';
109
124
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
110
125
  trigger: 'hover',
111
126
  followCursor: isHoverTrigger,
@@ -130,6 +145,7 @@ class LayerPopup extends _popup.default {
130
145
  trigger,
131
146
  closeOnClick
132
147
  } = this.popupOption;
148
+ const actualTrigger = this.getActualTriggerEvent();
133
149
  this.layerConfigItems.forEach(configItem => {
134
150
  var _layer$getSource;
135
151
  const layer = this.getLayerByConfig(configItem);
@@ -148,10 +164,10 @@ class LayerPopup extends _popup.default {
148
164
  var _this$mapsService;
149
165
  const onLayerClick = this.onLayerClick.bind(this, layer);
150
166
  layerInfo.onClick = onLayerClick;
151
- layer === null || layer === void 0 || layer.on('click', onLayerClick);
167
+ layer === null || layer === void 0 || layer.on(actualTrigger, onLayerClick);
152
168
  const mapContainer = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getMapContainer();
153
169
  if (mapContainer && closeOnClick) {
154
- mapContainer.addEventListener('click', this.onSceneClick);
170
+ mapContainer.addEventListener(actualTrigger, this.onSceneClick);
155
171
  }
156
172
  }
157
173
  const source = layer === null || layer === void 0 || (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
@@ -167,6 +183,7 @@ class LayerPopup extends _popup.default {
167
183
  * @protected
168
184
  */
169
185
  unbindLayerEvent() {
186
+ const actualTrigger = this.getActualTriggerEvent();
170
187
  this.layerConfigItems.forEach(configItem => {
171
188
  var _this$mapsService2;
172
189
  const layer = this.getLayerByConfig(configItem);
@@ -187,7 +204,7 @@ class LayerPopup extends _popup.default {
187
204
  layer.off('mouseout', onMouseOut);
188
205
  }
189
206
  if (onClick) {
190
- layer.off('click', onClick);
207
+ layer.off(actualTrigger, onClick);
191
208
  }
192
209
  if (onSourceUpdate) {
193
210
  var _layer$getSource2;
@@ -195,7 +212,7 @@ class LayerPopup extends _popup.default {
195
212
  }
196
213
  const mapContainer = (_this$mapsService2 = this.mapsService) === null || _this$mapsService2 === void 0 ? void 0 : _this$mapsService2.getMapContainer();
197
214
  if (mapContainer) {
198
- mapContainer.removeEventListener('click', this.onSceneClick);
215
+ mapContainer.removeEventListener(actualTrigger, this.onSceneClick);
199
216
  }
200
217
  });
201
218
  }
@@ -214,9 +231,7 @@ class LayerPopup extends _popup.default {
214
231
  this.show();
215
232
  }
216
233
  }
217
-
218
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
219
- onLayerMouseOut(layer, e) {
234
+ onLayerMouseOut(layer) {
220
235
  this.setDisplayFeatureInfo(undefined);
221
236
  if (this.isShow) {
222
237
  this.hide();
@@ -442,7 +442,6 @@ class Popup extends _eventemitter.EventEmitter {
442
442
  isOpen() {
443
443
  return !!this.mapsService;
444
444
  }
445
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
446
445
  getDefault(option) {
447
446
  // tslint:disable-next-line:no-object-literal-type-assertion
448
447
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-component",
3
- "version": "2.22.7",
3
+ "version": "2.23.1",
4
4
  "description": "Component for L7",
5
5
  "license": "MIT",
6
6
  "author": "https://github.com/orgs/antvis/people",
@@ -16,13 +16,13 @@
16
16
  "@babel/runtime": "^7.7.7",
17
17
  "eventemitter3": "^4.0.0",
18
18
  "supercluster": "^7.0.0",
19
- "@antv/l7-core": "2.22.7",
20
- "@antv/l7-layers": "2.22.7",
21
- "@antv/l7-utils": "2.22.7"
19
+ "@antv/l7-core": "2.23.1",
20
+ "@antv/l7-layers": "2.23.1",
21
+ "@antv/l7-utils": "2.23.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "less": "^4.1.3",
25
- "@antv/l7-test-utils": "^2.22.7"
25
+ "@antv/l7-test-utils": "^2.23.1"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public",