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