@antv/l7-component 2.25.7 → 2.25.10
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.
- package/es/assets/iconfont/iconfont.d.ts +21 -0
- package/es/assets/iconfont/iconfont.js +61 -0
- package/es/constants/index.d.ts +60 -0
- package/es/constants/index.js +60 -0
- package/es/control/baseControl/buttonControl.d.ts +60 -0
- package/es/control/baseControl/buttonControl.js +142 -0
- package/es/control/baseControl/control.d.ts +112 -0
- package/es/control/baseControl/control.js +256 -0
- package/es/control/baseControl/index.d.ts +4 -0
- package/es/control/baseControl/index.js +4 -0
- package/es/control/baseControl/popperControl.d.ts +28 -0
- package/es/control/baseControl/popperControl.js +92 -0
- package/es/control/baseControl/selectControl.d.ts +53 -0
- package/es/control/baseControl/selectControl.js +173 -0
- package/es/control/exportImage.d.ts +19 -0
- package/es/control/exportImage.js +73 -0
- package/es/control/fullscreen.d.ts +20 -0
- package/es/control/fullscreen.js +88 -0
- package/es/control/geoLocate.d.ts +17 -0
- package/es/control/geoLocate.js +60 -0
- package/es/control/layerSwitch.d.ts +27 -0
- package/es/control/layerSwitch.js +155 -0
- package/es/control/logo.d.ts +14 -0
- package/es/control/logo.js +49 -0
- package/es/control/mapTheme.d.ts +11 -0
- package/es/control/mapTheme.js +69 -0
- package/es/control/mouseLocation.d.ts +16 -0
- package/es/control/mouseLocation.js +52 -0
- package/es/control/scale.d.ts +35 -0
- package/es/control/scale.js +121 -0
- package/es/control/swipe.d.ts +66 -0
- package/es/control/swipe.js +392 -0
- package/es/control/zoom.d.ts +39 -0
- package/es/control/zoom.js +100 -0
- package/es/css/button.less +77 -0
- package/es/css/control.less +82 -0
- package/es/css/index.css +653 -0
- package/es/css/index.less +13 -0
- package/es/css/l7.less +69 -0
- package/es/css/layerPopup.less +9 -0
- package/es/css/logo.less +21 -0
- package/es/css/mouseLocation.less +9 -0
- package/es/css/popper.less +74 -0
- package/es/css/popup.less +176 -0
- package/es/css/scale.less +37 -0
- package/es/css/select.less +96 -0
- package/es/css/swipe.less +80 -0
- package/es/css/variables.less +29 -0
- package/es/css/zoom.less +34 -0
- package/es/images/layers.png +0 -0
- package/es/images/layers.svg +1 -0
- package/es/images/logo.png +0 -0
- package/es/images/quanping.svg +12 -0
- package/es/index.d.ts +19 -0
- package/es/index.js +717 -0
- package/es/interface.d.ts +29 -0
- package/es/interface.js +1 -0
- package/es/marker-layer.d.ts +46 -0
- package/es/marker-layer.js +509 -0
- package/es/marker.d.ts +66 -0
- package/es/marker.js +495 -0
- package/es/popup/layerPopup.d.ts +105 -0
- package/es/popup/layerPopup.js +341 -0
- package/es/popup/popup.d.ts +147 -0
- package/es/popup/popup.js +587 -0
- package/es/utils/anchor.d.ts +22 -0
- package/es/utils/anchor.js +31 -0
- package/es/utils/eventManager.d.ts +42 -0
- package/es/utils/eventManager.js +84 -0
- package/es/utils/icon.d.ts +1 -0
- package/es/utils/icon.js +12 -0
- package/es/utils/popper.d.ts +76 -0
- package/es/utils/popper.js +257 -0
- package/es/utils/screenfull.d.ts +2 -0
- package/es/utils/screenfull.js +106 -0
- package/lib/assets/iconfont/iconfont.d.ts +21 -0
- package/lib/assets/iconfont/iconfont.js +68 -0
- package/lib/constants/index.d.ts +60 -0
- package/lib/constants/index.js +66 -0
- package/lib/control/baseControl/buttonControl.d.ts +60 -0
- package/lib/control/baseControl/buttonControl.js +149 -0
- package/lib/control/baseControl/control.d.ts +112 -0
- package/lib/control/baseControl/control.js +269 -0
- package/lib/control/baseControl/index.d.ts +4 -0
- package/lib/control/baseControl/index.js +39 -0
- package/lib/control/baseControl/popperControl.d.ts +28 -0
- package/lib/control/baseControl/popperControl.js +99 -0
- package/lib/control/baseControl/selectControl.d.ts +53 -0
- package/lib/control/baseControl/selectControl.js +180 -0
- package/lib/control/exportImage.d.ts +19 -0
- package/lib/control/exportImage.js +80 -0
- package/lib/control/fullscreen.d.ts +20 -0
- package/lib/control/fullscreen.js +95 -0
- package/lib/control/geoLocate.d.ts +17 -0
- package/lib/control/geoLocate.js +67 -0
- package/lib/control/layerSwitch.d.ts +27 -0
- package/lib/control/layerSwitch.js +162 -0
- package/lib/control/logo.d.ts +14 -0
- package/lib/control/logo.js +55 -0
- package/lib/control/mapTheme.d.ts +11 -0
- package/lib/control/mapTheme.js +76 -0
- package/lib/control/mouseLocation.d.ts +16 -0
- package/lib/control/mouseLocation.js +59 -0
- package/lib/control/scale.d.ts +35 -0
- package/lib/control/scale.js +128 -0
- package/lib/control/swipe.d.ts +66 -0
- package/lib/control/swipe.js +399 -0
- package/lib/control/zoom.d.ts +39 -0
- package/lib/control/zoom.js +107 -0
- package/lib/css/button.less +77 -0
- package/lib/css/control.less +82 -0
- package/lib/css/index.css +653 -0
- package/lib/css/index.less +13 -0
- package/lib/css/l7.less +69 -0
- package/lib/css/layerPopup.less +9 -0
- package/lib/css/logo.less +21 -0
- package/lib/css/mouseLocation.less +9 -0
- package/lib/css/popper.less +74 -0
- package/lib/css/popup.less +176 -0
- package/lib/css/scale.less +37 -0
- package/lib/css/select.less +96 -0
- package/lib/css/swipe.less +80 -0
- package/lib/css/variables.less +29 -0
- package/lib/css/zoom.less +34 -0
- package/lib/images/layers.png +0 -0
- package/lib/images/layers.svg +1 -0
- package/lib/images/logo.png +0 -0
- package/lib/images/quanping.svg +12 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +844 -0
- package/lib/interface.d.ts +29 -0
- package/lib/interface.js +5 -0
- package/lib/marker-layer.d.ts +46 -0
- package/lib/marker-layer.js +518 -0
- package/lib/marker.d.ts +66 -0
- package/lib/marker.js +502 -0
- package/lib/popup/layerPopup.d.ts +105 -0
- package/lib/popup/layerPopup.js +348 -0
- package/lib/popup/popup.d.ts +147 -0
- package/lib/popup/popup.js +594 -0
- package/lib/utils/anchor.d.ts +22 -0
- package/lib/utils/anchor.js +38 -0
- package/lib/utils/eventManager.d.ts +42 -0
- package/lib/utils/eventManager.js +92 -0
- package/lib/utils/icon.d.ts +1 -0
- package/lib/utils/icon.js +19 -0
- package/lib/utils/popper.d.ts +76 -0
- package/lib/utils/popper.js +264 -0
- package/lib/utils/screenfull.d.ts +2 -0
- package/lib/utils/screenfull.js +112 -0
- package/package.json +5 -5
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.LayerPopup = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _l7Utils = require("@antv/l7-utils");
|
|
11
|
+
var _popup = _interopRequireDefault(require("./popup"));
|
|
12
|
+
const {
|
|
13
|
+
get
|
|
14
|
+
} = _l7Utils.lodashUtil;
|
|
15
|
+
class LayerPopup extends _popup.default {
|
|
16
|
+
constructor(...args) {
|
|
17
|
+
super(...args);
|
|
18
|
+
/**
|
|
19
|
+
* 用于统计当前帧当中,layer 被点击的次数
|
|
20
|
+
*/
|
|
21
|
+
(0, _defineProperty2.default)(this, "layerClickCountByFrame", 0);
|
|
22
|
+
/**
|
|
23
|
+
* 用于保存图层对应的事件回调以及配置信息
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
(0, _defineProperty2.default)(this, "layerConfigMap", new WeakMap());
|
|
27
|
+
/**
|
|
28
|
+
* 当期正在展示的图层以及对应元素 id 的信息
|
|
29
|
+
* @protected
|
|
30
|
+
*/
|
|
31
|
+
(0, _defineProperty2.default)(this, "displayFeatureInfo", void 0);
|
|
32
|
+
(0, _defineProperty2.default)(this, "onLayerClick", (layer, e) => {
|
|
33
|
+
requestAnimationFrame(() => {
|
|
34
|
+
if (this.popupOption.closeOnClick) {
|
|
35
|
+
this.layerClickCountByFrame++;
|
|
36
|
+
}
|
|
37
|
+
if (this.isShow && this.isSameFeature(layer, e.featureId)) {
|
|
38
|
+
this.hide();
|
|
39
|
+
} else {
|
|
40
|
+
const {
|
|
41
|
+
title,
|
|
42
|
+
content
|
|
43
|
+
} = this.getLayerInfoFrag(layer, e);
|
|
44
|
+
this.setDOMContent(content);
|
|
45
|
+
this.setLnglat(e.lngLat);
|
|
46
|
+
this.setTitle(title);
|
|
47
|
+
this.setDisplayFeatureInfo({
|
|
48
|
+
layer,
|
|
49
|
+
featureId: e.featureId
|
|
50
|
+
});
|
|
51
|
+
this.show();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
(0, _defineProperty2.default)(this, "onSceneClick", () => {
|
|
56
|
+
this.layerClickCountByFrame = 0;
|
|
57
|
+
requestAnimationFrame(() => {
|
|
58
|
+
if (!this.layerClickCountByFrame) {
|
|
59
|
+
this.hide();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
(0, _defineProperty2.default)(this, "onLayerHide", () => {
|
|
64
|
+
this.hide();
|
|
65
|
+
this.setDisplayFeatureInfo(undefined);
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* 覆盖 Popup 中的默认的 closeOnClick 行为
|
|
69
|
+
*/
|
|
70
|
+
// tslint:disable-next-line:no-empty
|
|
71
|
+
(0, _defineProperty2.default)(this, "updateCloseOnClick", () => {});
|
|
72
|
+
}
|
|
73
|
+
get layerConfigItems() {
|
|
74
|
+
var _ref;
|
|
75
|
+
const {
|
|
76
|
+
config,
|
|
77
|
+
items
|
|
78
|
+
} = this.popupOption;
|
|
79
|
+
return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 根据环境获取实际的触发事件
|
|
84
|
+
* 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
87
|
+
getActualTriggerEvent() {
|
|
88
|
+
var _this$popupOption$tri;
|
|
89
|
+
const trigger = (_this$popupOption$tri = this.popupOption.trigger) !== null && _this$popupOption$tri !== void 0 ? _this$popupOption$tri : 'hover';
|
|
90
|
+
if (trigger === 'click') {
|
|
91
|
+
return (0, _l7Utils.isPC)() ? 'click' : 'touchend';
|
|
92
|
+
}
|
|
93
|
+
return trigger;
|
|
94
|
+
}
|
|
95
|
+
addTo(scene) {
|
|
96
|
+
super.addTo(scene);
|
|
97
|
+
this.bindLayerEvent();
|
|
98
|
+
this.hide();
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
remove() {
|
|
102
|
+
super.remove();
|
|
103
|
+
this.unbindLayerEvent();
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
setOptions(option) {
|
|
107
|
+
this.unbindLayerEvent();
|
|
108
|
+
const newOption = (0, _objectSpread2.default)({}, option);
|
|
109
|
+
const trigger = newOption.trigger || this.popupOption.trigger;
|
|
110
|
+
const items = newOption.items || this.popupOption.items;
|
|
111
|
+
const isEmptyItems = (items === null || items === void 0 ? void 0 : items.length) === 0;
|
|
112
|
+
newOption.followCursor = trigger === 'hover' && !isEmptyItems;
|
|
113
|
+
const isShow = this.isShow;
|
|
114
|
+
super.setOptions(newOption);
|
|
115
|
+
this.bindLayerEvent();
|
|
116
|
+
if (isEmptyItems || !isShow) {
|
|
117
|
+
this.hide();
|
|
118
|
+
}
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
getDefault(option) {
|
|
122
|
+
var _option$trigger;
|
|
123
|
+
// trigger 默认值为 'hover'
|
|
124
|
+
const trigger = (_option$trigger = option.trigger) !== null && _option$trigger !== void 0 ? _option$trigger : 'hover';
|
|
125
|
+
const isHoverTrigger = trigger === 'hover';
|
|
126
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
|
|
127
|
+
trigger,
|
|
128
|
+
followCursor: isHoverTrigger,
|
|
129
|
+
lngLat: {
|
|
130
|
+
lng: 0,
|
|
131
|
+
lat: 0
|
|
132
|
+
},
|
|
133
|
+
offsets: [0, 10],
|
|
134
|
+
closeButton: false,
|
|
135
|
+
closeOnClick: true,
|
|
136
|
+
autoClose: false,
|
|
137
|
+
closeOnEsc: false
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 绑定对应的图层事件
|
|
143
|
+
* @protected
|
|
144
|
+
*/
|
|
145
|
+
bindLayerEvent() {
|
|
146
|
+
const {
|
|
147
|
+
trigger,
|
|
148
|
+
closeOnClick
|
|
149
|
+
} = this.popupOption;
|
|
150
|
+
const actualTrigger = this.getActualTriggerEvent();
|
|
151
|
+
this.layerConfigItems.forEach(configItem => {
|
|
152
|
+
var _layer$getSource;
|
|
153
|
+
const layer = this.getLayerByConfig(configItem);
|
|
154
|
+
if (!layer) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const layerInfo = (0, _objectSpread2.default)({}, configItem);
|
|
158
|
+
if (trigger === 'hover') {
|
|
159
|
+
const onMouseMove = this.onLayerMouseMove.bind(this, layer);
|
|
160
|
+
const onMouseOut = this.onLayerMouseOut.bind(this, layer);
|
|
161
|
+
layerInfo.onMouseMove = onMouseMove;
|
|
162
|
+
layerInfo.onMouseOut = onMouseOut;
|
|
163
|
+
layer === null || layer === void 0 || layer.on('mousemove', onMouseMove);
|
|
164
|
+
layer === null || layer === void 0 || layer.on('mouseout', onMouseOut);
|
|
165
|
+
} else {
|
|
166
|
+
var _this$mapsService;
|
|
167
|
+
const onLayerClick = this.onLayerClick.bind(this, layer);
|
|
168
|
+
layerInfo.onClick = onLayerClick;
|
|
169
|
+
layer === null || layer === void 0 || layer.on(actualTrigger, onLayerClick);
|
|
170
|
+
const mapContainer = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getMapContainer();
|
|
171
|
+
if (mapContainer && closeOnClick) {
|
|
172
|
+
mapContainer.addEventListener(actualTrigger, this.onSceneClick);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const source = layer === null || layer === void 0 || (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
|
|
176
|
+
const onSourceUpdate = this.onSourceUpdate.bind(this);
|
|
177
|
+
source === null || source === void 0 || source.on('update', onSourceUpdate);
|
|
178
|
+
layerInfo.onSourceUpdate = onSourceUpdate;
|
|
179
|
+
this.layerConfigMap.set(layer, layerInfo);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 解绑对应的图层事件
|
|
185
|
+
* @protected
|
|
186
|
+
*/
|
|
187
|
+
unbindLayerEvent() {
|
|
188
|
+
const actualTrigger = this.getActualTriggerEvent();
|
|
189
|
+
this.layerConfigItems.forEach(configItem => {
|
|
190
|
+
var _this$mapsService2;
|
|
191
|
+
const layer = this.getLayerByConfig(configItem);
|
|
192
|
+
const layerInfo = layer && this.layerConfigMap.get(layer);
|
|
193
|
+
if (!layerInfo) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const {
|
|
197
|
+
onMouseMove,
|
|
198
|
+
onMouseOut,
|
|
199
|
+
onClick,
|
|
200
|
+
onSourceUpdate
|
|
201
|
+
} = layerInfo;
|
|
202
|
+
if (onMouseMove) {
|
|
203
|
+
layer.off('mousemove', onMouseMove);
|
|
204
|
+
}
|
|
205
|
+
if (onMouseOut) {
|
|
206
|
+
layer.off('mouseout', onMouseOut);
|
|
207
|
+
}
|
|
208
|
+
if (onClick) {
|
|
209
|
+
layer.off(actualTrigger, onClick);
|
|
210
|
+
}
|
|
211
|
+
if (onSourceUpdate) {
|
|
212
|
+
var _layer$getSource2;
|
|
213
|
+
layer === null || layer === void 0 || (_layer$getSource2 = layer.getSource()) === null || _layer$getSource2 === void 0 || _layer$getSource2.off('update', onSourceUpdate);
|
|
214
|
+
}
|
|
215
|
+
const mapContainer = (_this$mapsService2 = this.mapsService) === null || _this$mapsService2 === void 0 ? void 0 : _this$mapsService2.getMapContainer();
|
|
216
|
+
if (mapContainer) {
|
|
217
|
+
mapContainer.removeEventListener(actualTrigger, this.onSceneClick);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
onLayerMouseMove(layer, e) {
|
|
222
|
+
if (!this.isSameFeature(layer, e.featureId)) {
|
|
223
|
+
const {
|
|
224
|
+
title,
|
|
225
|
+
content
|
|
226
|
+
} = this.getLayerInfoFrag(layer, e);
|
|
227
|
+
this.setDOMContent(content);
|
|
228
|
+
this.setTitle(title);
|
|
229
|
+
this.setDisplayFeatureInfo({
|
|
230
|
+
layer,
|
|
231
|
+
featureId: e.featureId
|
|
232
|
+
});
|
|
233
|
+
this.show();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
onLayerMouseOut(layer) {
|
|
237
|
+
this.setDisplayFeatureInfo(undefined);
|
|
238
|
+
if (this.isShow) {
|
|
239
|
+
this.hide();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
onSourceUpdate() {
|
|
243
|
+
this.hide();
|
|
244
|
+
this.setDisplayFeatureInfo(undefined);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 通过当前图层和对应选中的元素获取气泡展示的 HTML 内容
|
|
249
|
+
* @param layer
|
|
250
|
+
* @param e
|
|
251
|
+
* @protected
|
|
252
|
+
*/
|
|
253
|
+
getLayerInfoFrag(layer, e) {
|
|
254
|
+
const layerInfo = this.layerConfigMap.get(layer);
|
|
255
|
+
let titleFrag;
|
|
256
|
+
const contentFrag = document.createDocumentFragment();
|
|
257
|
+
if (layerInfo) {
|
|
258
|
+
let feature = e.feature;
|
|
259
|
+
if (feature.type === 'Feature' && 'properties' in feature && 'geometry' in feature) {
|
|
260
|
+
feature = feature.properties;
|
|
261
|
+
}
|
|
262
|
+
const {
|
|
263
|
+
title,
|
|
264
|
+
fields,
|
|
265
|
+
customContent
|
|
266
|
+
} = layerInfo;
|
|
267
|
+
if (title) {
|
|
268
|
+
titleFrag = document.createDocumentFragment();
|
|
269
|
+
const titleElement = title instanceof Function ? title(feature) : title;
|
|
270
|
+
_l7Utils.DOM.appendElementType(titleFrag, titleElement);
|
|
271
|
+
}
|
|
272
|
+
if (customContent) {
|
|
273
|
+
const content = customContent instanceof Function ? customContent(feature) : customContent;
|
|
274
|
+
_l7Utils.DOM.appendElementType(contentFrag, content);
|
|
275
|
+
} else if (fields !== null && fields !== void 0 && fields.length) {
|
|
276
|
+
fields === null || fields === void 0 || fields.forEach(fieldConfig => {
|
|
277
|
+
var _ref2, _ref3;
|
|
278
|
+
const {
|
|
279
|
+
field,
|
|
280
|
+
formatField,
|
|
281
|
+
formatValue,
|
|
282
|
+
getValue
|
|
283
|
+
} = typeof fieldConfig === 'string' ?
|
|
284
|
+
// tslint:disable-next-line:no-object-literal-type-assertion
|
|
285
|
+
{
|
|
286
|
+
field: fieldConfig
|
|
287
|
+
} : fieldConfig;
|
|
288
|
+
const row = _l7Utils.DOM.create('div', 'l7-layer-popup__row');
|
|
289
|
+
const value = getValue ? getValue(e.feature) : get(feature, field);
|
|
290
|
+
const fieldElement = (_ref2 = formatField instanceof Function ? formatField(field, feature) : formatField) !== null && _ref2 !== void 0 ? _ref2 : field;
|
|
291
|
+
let valueElement = (_ref3 = formatValue instanceof Function ? formatValue(value, feature) : formatValue) !== null && _ref3 !== void 0 ? _ref3 : value;
|
|
292
|
+
const fieldSpan = _l7Utils.DOM.create('span', 'l7-layer-popup__key', row);
|
|
293
|
+
_l7Utils.DOM.appendElementType(fieldSpan, fieldElement);
|
|
294
|
+
_l7Utils.DOM.appendElementType(fieldSpan, document.createTextNode(':'));
|
|
295
|
+
const valueSpan = _l7Utils.DOM.create('span', 'l7-layer-popup__value', row);
|
|
296
|
+
|
|
297
|
+
// 当 value 中每项元素均为基础数据类型时,用逗号隔开
|
|
298
|
+
if (Array.isArray(valueElement) && valueElement.every(item => !(item instanceof Object))) {
|
|
299
|
+
valueElement = valueElement.map(item => String(item)).join(',');
|
|
300
|
+
}
|
|
301
|
+
_l7Utils.DOM.appendElementType(valueSpan, valueElement);
|
|
302
|
+
contentFrag.appendChild(row);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
title: titleFrag,
|
|
308
|
+
content: contentFrag
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 通过 Layer 配置访问到真实的 Layer 实例
|
|
314
|
+
* @param configItem
|
|
315
|
+
* @protected
|
|
316
|
+
*/
|
|
317
|
+
getLayerByConfig(configItem) {
|
|
318
|
+
const layer = configItem.layer;
|
|
319
|
+
if (layer instanceof Object) {
|
|
320
|
+
return layer;
|
|
321
|
+
}
|
|
322
|
+
if (typeof layer === 'string') {
|
|
323
|
+
return this.layerService.getLayer(layer) || this.layerService.getLayerByName(layer);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 判断当前展示的 Feature 是否和上一次查看的一致
|
|
329
|
+
* @param layer
|
|
330
|
+
* @param featureId
|
|
331
|
+
* @protected
|
|
332
|
+
*/
|
|
333
|
+
isSameFeature(layer, featureId) {
|
|
334
|
+
const displayFeatureInfo = this.displayFeatureInfo;
|
|
335
|
+
return displayFeatureInfo && layer === displayFeatureInfo.layer && featureId === displayFeatureInfo.featureId;
|
|
336
|
+
}
|
|
337
|
+
setDisplayFeatureInfo(displayFeatureInfo) {
|
|
338
|
+
const oldDisplayFeatureInfo = this.displayFeatureInfo;
|
|
339
|
+
if (oldDisplayFeatureInfo) {
|
|
340
|
+
oldDisplayFeatureInfo.layer.off('hide', this.onLayerHide);
|
|
341
|
+
}
|
|
342
|
+
if (displayFeatureInfo) {
|
|
343
|
+
displayFeatureInfo.layer.on('hide', this.onLayerHide);
|
|
344
|
+
}
|
|
345
|
+
this.displayFeatureInfo = displayFeatureInfo;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.default = exports.LayerPopup = LayerPopup;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ILayerService, ILngLat, IMapService, IPopup, IPopupOption, ISceneService, L7Container } from '@antv/l7-core';
|
|
2
|
+
import { DOM } from '@antv/l7-utils';
|
|
3
|
+
import { EventEmitter } from 'eventemitter3';
|
|
4
|
+
type ElementType = DOM.ElementType;
|
|
5
|
+
export { Popup };
|
|
6
|
+
export default class Popup<O extends IPopupOption = IPopupOption> extends EventEmitter implements IPopup {
|
|
7
|
+
/**
|
|
8
|
+
* 配置
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
protected popupOption: O;
|
|
12
|
+
protected mapsService: IMapService;
|
|
13
|
+
protected sceneService: ISceneService;
|
|
14
|
+
protected layerService: ILayerService;
|
|
15
|
+
protected scene: L7Container;
|
|
16
|
+
/**
|
|
17
|
+
* 关闭按钮对应的 DOM
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
protected closeButton?: HTMLElement | SVGElement;
|
|
21
|
+
/**
|
|
22
|
+
* Popup 的总容器 DOM,包含 content 和 tip
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
protected container: HTMLElement;
|
|
26
|
+
/**
|
|
27
|
+
* popup 气泡容器
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
protected content: HTMLElement;
|
|
31
|
+
/**
|
|
32
|
+
* popup 气泡标题
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected contentTitle?: HTMLElement;
|
|
36
|
+
/**
|
|
37
|
+
* popup 内容容器
|
|
38
|
+
* @protected
|
|
39
|
+
*/
|
|
40
|
+
protected contentPanel: HTMLElement;
|
|
41
|
+
/**
|
|
42
|
+
* 气泡箭头对应的 DOM
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
protected tip: HTMLElement;
|
|
46
|
+
/**
|
|
47
|
+
* 当前是否展示
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
protected isShow: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* RAF 节流 ID
|
|
53
|
+
* @protected
|
|
54
|
+
*/
|
|
55
|
+
protected rafId: number | null;
|
|
56
|
+
protected get lngLat(): ILngLat;
|
|
57
|
+
protected set lngLat(newLngLat: ILngLat);
|
|
58
|
+
constructor(cfg?: Partial<O>);
|
|
59
|
+
getIsShow(): boolean;
|
|
60
|
+
addTo(scene: L7Container): this;
|
|
61
|
+
remove(): this | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* 获取 option 配置
|
|
64
|
+
*/
|
|
65
|
+
getOptions(): O;
|
|
66
|
+
setOptions(option: Partial<O>): this;
|
|
67
|
+
open(): this;
|
|
68
|
+
close(): this;
|
|
69
|
+
show(): this | undefined;
|
|
70
|
+
hide(): this | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* 设置 HTML 内容
|
|
73
|
+
* @param html
|
|
74
|
+
*/
|
|
75
|
+
setHTML(html: ElementType): this;
|
|
76
|
+
/**
|
|
77
|
+
* 设置 Popup 展示文本
|
|
78
|
+
* @param text
|
|
79
|
+
*/
|
|
80
|
+
setText(text: string): this;
|
|
81
|
+
setTitle(title?: ElementType): void;
|
|
82
|
+
/**
|
|
83
|
+
* 将地图自动平移到气泡位置
|
|
84
|
+
*/
|
|
85
|
+
panToPopup(): this;
|
|
86
|
+
setLngLat(lngLat: ILngLat | [number, number]): this;
|
|
87
|
+
/**
|
|
88
|
+
* 设置 Popup 所在经纬度
|
|
89
|
+
* @param lngLat
|
|
90
|
+
*/
|
|
91
|
+
setLnglat(lngLat: ILngLat | [number, number]): this;
|
|
92
|
+
/**
|
|
93
|
+
* 获取 Popup 所在经纬度
|
|
94
|
+
*/
|
|
95
|
+
getLnglat(): ILngLat;
|
|
96
|
+
/**
|
|
97
|
+
* 设置 Popup 最大宽度
|
|
98
|
+
* @param maxWidth
|
|
99
|
+
*/
|
|
100
|
+
setMaxWidth(maxWidth: string): this;
|
|
101
|
+
isOpen(): boolean;
|
|
102
|
+
protected onMouseMove: (e: MouseEvent) => void;
|
|
103
|
+
/**
|
|
104
|
+
* 将经纬度转换成对应的像素偏移位置
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
protected updateLngLatPosition: () => void;
|
|
108
|
+
protected updateLngLatPositionWhenZoom: (ev: any) => void;
|
|
109
|
+
protected getDefault(option: Partial<O>): O;
|
|
110
|
+
/**
|
|
111
|
+
* 设置 Popup 内容 HTML
|
|
112
|
+
* @param element
|
|
113
|
+
*/
|
|
114
|
+
protected setDOMContent(element: ElementType): this;
|
|
115
|
+
/**
|
|
116
|
+
* 绑定地图点击事件触发销毁 Popup
|
|
117
|
+
* @protected
|
|
118
|
+
*/
|
|
119
|
+
protected updateCloseOnClick(onlyClear?: boolean): void;
|
|
120
|
+
protected updateCloseOnEsc(onlyClear?: boolean): void;
|
|
121
|
+
protected updateFollowCursor(onlyClear?: boolean): void;
|
|
122
|
+
protected onKeyDown: (e: KeyboardEvent) => void;
|
|
123
|
+
/**
|
|
124
|
+
* 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
127
|
+
protected createContent(): void;
|
|
128
|
+
protected onCloseButtonClick: (e: Event) => void;
|
|
129
|
+
private updatePosition;
|
|
130
|
+
protected updateWhenZoom: (ev: any) => void;
|
|
131
|
+
protected update: () => void;
|
|
132
|
+
/**
|
|
133
|
+
* 设置 Popup 相对于地图容器的 Position
|
|
134
|
+
* @param {Number} left
|
|
135
|
+
* @param {Number} top
|
|
136
|
+
* @param {Boolean} [useTransition=false] 是否使用过度效果
|
|
137
|
+
* @protected
|
|
138
|
+
*/
|
|
139
|
+
protected setPopupPosition(left: number, top: number, useTransition?: boolean): void;
|
|
140
|
+
/**
|
|
141
|
+
* 检查当前传入 option 是否包含 keys 字段
|
|
142
|
+
* @param option
|
|
143
|
+
* @param keys
|
|
144
|
+
* @protected
|
|
145
|
+
*/
|
|
146
|
+
protected checkUpdateOption(option: Partial<O>, keys: Array<keyof O>): boolean;
|
|
147
|
+
}
|