@antv/l7-component 2.9.37-alpha.2 → 2.9.37-alpha.3
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.js +53 -0
- package/es/constants/index.d.ts +60 -0
- package/es/constants/index.js +60 -0
- package/es/control/baseControl/buttonControl.d.ts +59 -0
- package/es/control/baseControl/buttonControl.js +191 -0
- package/es/control/baseControl/control.d.ts +113 -0
- package/es/control/baseControl/control.js +313 -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 +26 -0
- package/es/control/baseControl/popperControl.js +131 -0
- package/es/control/baseControl/selectControl.d.ts +46 -0
- package/es/control/baseControl/selectControl.js +232 -0
- package/es/control/exportImage.d.ts +18 -0
- package/es/control/exportImage.js +163 -0
- package/es/control/fullscreen.d.ts +19 -0
- package/es/control/fullscreen.js +151 -0
- package/es/control/geoLocate.d.ts +16 -0
- package/es/control/geoLocate.js +139 -0
- package/es/control/layerSwitch.d.ts +21 -0
- package/es/control/layerSwitch.js +193 -0
- package/es/control/logo.d.ts +13 -0
- package/es/control/logo.js +87 -0
- package/es/control/mapTheme.d.ts +10 -0
- package/es/control/mapTheme.js +135 -0
- package/es/control/mouseLocation.d.ts +15 -0
- package/es/control/mouseLocation.js +104 -0
- package/es/control/scale.d.ts +34 -0
- package/es/control/scale.js +172 -0
- package/es/control/zoom.d.ts +35 -0
- package/es/control/zoom.js +146 -0
- package/es/css/button.less +70 -0
- package/es/css/control.less +71 -0
- package/es/css/index.css +567 -0
- package/es/css/index.less +12 -0
- package/es/css/l7.less +60 -0
- package/es/css/layerPopup.less +8 -0
- package/es/css/logo.less +18 -0
- package/es/css/mouseLocation.less +9 -0
- package/es/css/popper.less +64 -0
- package/es/css/popup.less +169 -0
- package/es/css/scale.less +34 -0
- package/es/css/select.less +86 -0
- package/es/css/variables.less +28 -0
- package/es/css/zoom.less +21 -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 +18 -0
- package/es/index.js +59 -0
- package/es/interface.d.ts +18 -0
- package/es/interface.js +1 -0
- package/es/marker-layer.d.ts +53 -0
- package/es/marker-layer.js +363 -0
- package/es/marker.d.ts +49 -0
- package/es/marker.js +434 -0
- package/es/popup/layerPopup.d.ts +78 -0
- package/es/popup/layerPopup.js +308 -0
- package/es/popup/popup.d.ts +147 -0
- package/es/popup/popup.js +636 -0
- package/es/utils/anchor.d.ts +22 -0
- package/es/utils/anchor.js +35 -0
- package/es/utils/icon.d.ts +1 -0
- package/es/utils/icon.js +9 -0
- package/es/utils/popper.d.ts +75 -0
- package/es/utils/popper.js +286 -0
- package/es/utils/screenfull.d.ts +2 -0
- package/es/utils/screenfull.js +157 -0
- package/lib/assets/iconfont/iconfont.js +55 -0
- package/lib/constants/index.js +68 -0
- package/lib/control/baseControl/buttonControl.js +207 -0
- package/lib/control/baseControl/control.js +340 -0
- package/lib/control/baseControl/index.js +57 -0
- package/lib/control/baseControl/popperControl.js +142 -0
- package/lib/control/baseControl/selectControl.js +253 -0
- package/lib/control/exportImage.js +177 -0
- package/lib/control/fullscreen.js +164 -0
- package/lib/control/geoLocate.js +154 -0
- package/lib/control/layerSwitch.js +203 -0
- package/lib/control/logo.js +105 -0
- package/lib/control/mapTheme.js +151 -0
- package/lib/control/mouseLocation.js +120 -0
- package/lib/control/scale.js +189 -0
- package/lib/control/zoom.js +162 -0
- package/lib/css/button.less +70 -0
- package/lib/css/control.less +71 -0
- package/lib/css/index.css +567 -0
- package/lib/css/index.less +12 -0
- package/lib/css/l7.less +60 -0
- package/lib/css/layerPopup.less +8 -0
- package/lib/css/logo.less +18 -0
- package/lib/css/mouseLocation.less +9 -0
- package/lib/css/popper.less +64 -0
- package/lib/css/popup.less +169 -0
- package/lib/css/scale.less +34 -0
- package/lib/css/select.less +86 -0
- package/lib/css/variables.less +28 -0
- package/lib/css/zoom.less +21 -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.js +254 -0
- package/lib/interface.js +5 -0
- package/lib/marker-layer.js +381 -0
- package/lib/marker.js +449 -0
- package/lib/popup/layerPopup.js +317 -0
- package/lib/popup/popup.js +651 -0
- package/lib/utils/anchor.js +45 -0
- package/lib/utils/icon.js +18 -0
- package/lib/utils/popper.js +297 -0
- package/lib/utils/screenfull.js +167 -0
- package/package.json +5 -5
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
|
|
11
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
|
|
13
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
+
|
|
15
|
+
import { TYPES } from '@antv/l7-core';
|
|
16
|
+
import { anchorTranslate, anchorType, applyAnchorClass, DOM } from '@antv/l7-utils';
|
|
17
|
+
import { EventEmitter } from 'eventemitter3';
|
|
18
|
+
import { createL7Icon } from "../utils/icon";
|
|
19
|
+
export { Popup };
|
|
20
|
+
|
|
21
|
+
var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
22
|
+
_inherits(Popup, _EventEmitter);
|
|
23
|
+
|
|
24
|
+
var _super = _createSuper(Popup);
|
|
25
|
+
|
|
26
|
+
function Popup(cfg) {
|
|
27
|
+
var _this;
|
|
28
|
+
|
|
29
|
+
_classCallCheck(this, Popup);
|
|
30
|
+
|
|
31
|
+
_this = _super.call(this);
|
|
32
|
+
|
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "isShow", true);
|
|
34
|
+
|
|
35
|
+
_defineProperty(_assertThisInitialized(_this), "onMouseMove", function (e) {
|
|
36
|
+
var _container$getBoundin;
|
|
37
|
+
|
|
38
|
+
var container = _this.mapsService.getMapContainer();
|
|
39
|
+
|
|
40
|
+
var _ref = (_container$getBoundin = container === null || container === void 0 ? void 0 : container.getBoundingClientRect()) !== null && _container$getBoundin !== void 0 ? _container$getBoundin : {},
|
|
41
|
+
_ref$left = _ref.left,
|
|
42
|
+
left = _ref$left === void 0 ? 0 : _ref$left,
|
|
43
|
+
_ref$top = _ref.top,
|
|
44
|
+
top = _ref$top === void 0 ? 0 : _ref$top;
|
|
45
|
+
|
|
46
|
+
_this.setPopupPosition(e.clientX - left, e.clientY - top);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
_defineProperty(_assertThisInitialized(_this), "updateLngLatPosition", function () {
|
|
50
|
+
if (!_this.mapsService || _this.popupOption.followCursor) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var _this$lngLat = _this.lngLat,
|
|
55
|
+
lng = _this$lngLat.lng,
|
|
56
|
+
lat = _this$lngLat.lat;
|
|
57
|
+
|
|
58
|
+
var _this$mapsService$lng = _this.mapsService.lngLatToContainer([lng, lat]),
|
|
59
|
+
x = _this$mapsService$lng.x,
|
|
60
|
+
y = _this$mapsService$lng.y;
|
|
61
|
+
|
|
62
|
+
_this.setPopupPosition(x, y);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
|
|
66
|
+
if (e.keyCode === 27) {
|
|
67
|
+
_this.remove();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "onCloseButtonClick", function (e) {
|
|
72
|
+
if (e.stopPropagation) {
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_this.remove();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
_defineProperty(_assertThisInitialized(_this), "update", function () {
|
|
80
|
+
var hasPosition = !!_this.lngLat;
|
|
81
|
+
var _this$popupOption = _this.popupOption,
|
|
82
|
+
className = _this$popupOption.className,
|
|
83
|
+
style = _this$popupOption.style,
|
|
84
|
+
maxWidth = _this$popupOption.maxWidth,
|
|
85
|
+
anchor = _this$popupOption.anchor,
|
|
86
|
+
stopPropagation = _this$popupOption.stopPropagation;
|
|
87
|
+
|
|
88
|
+
if (!_this.mapsService || !hasPosition || !_this.content) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var popupContainer = _this.mapsService.getMarkerContainer(); // 如果当前没有创建 Popup 容器则创建
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if (!_this.container && popupContainer) {
|
|
96
|
+
_this.container = DOM.create('div', "l7-popup ".concat(className !== null && className !== void 0 ? className : '', " ").concat(!_this.isShow ? 'l7-popup-hide' : ''), popupContainer);
|
|
97
|
+
|
|
98
|
+
if (style) {
|
|
99
|
+
_this.container.setAttribute('style', style);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_this.tip = DOM.create('div', 'l7-popup-tip', _this.container);
|
|
103
|
+
|
|
104
|
+
_this.container.appendChild(_this.content); // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if (stopPropagation) {
|
|
108
|
+
['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
|
|
109
|
+
_this.container.addEventListener(type, function (e) {
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_this.container.style.whiteSpace = 'nowrap';
|
|
116
|
+
} // 设置 Popup 的最大宽度
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if (maxWidth && _this.container.style.maxWidth !== maxWidth) {
|
|
120
|
+
_this.container.style.maxWidth = maxWidth;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
_this.updateLngLatPosition();
|
|
124
|
+
|
|
125
|
+
DOM.setTransform(_this.container, "".concat(anchorTranslate[anchor]));
|
|
126
|
+
applyAnchorClass(_this.container, anchor, 'popup');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
_this.popupOption = _objectSpread(_objectSpread({}, _this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
|
|
130
|
+
var lngLat = _this.popupOption.lngLat;
|
|
131
|
+
|
|
132
|
+
if (lngLat) {
|
|
133
|
+
_this.lngLat = lngLat;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return _this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_createClass(Popup, [{
|
|
140
|
+
key: "lngLat",
|
|
141
|
+
get:
|
|
142
|
+
/**
|
|
143
|
+
* 配置
|
|
144
|
+
* @protected
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 关闭按钮对应的 DOM
|
|
149
|
+
* @protected
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Popup 的总容器 DOM,包含 content 和 tip
|
|
154
|
+
* @protected
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* popup 气泡容器
|
|
159
|
+
* @protected
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* popup 气泡标题
|
|
164
|
+
* @protected
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* popup 内容容器
|
|
169
|
+
* @protected
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* popup 内容标题
|
|
174
|
+
* @protected
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 气泡箭头对应的 DOM
|
|
179
|
+
* @protected
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 当前是否展示
|
|
184
|
+
* @protected
|
|
185
|
+
*/
|
|
186
|
+
function get() {
|
|
187
|
+
var _this$popupOption$lng;
|
|
188
|
+
|
|
189
|
+
return (_this$popupOption$lng = this.popupOption.lngLat) !== null && _this$popupOption$lng !== void 0 ? _this$popupOption$lng : {
|
|
190
|
+
lng: 0,
|
|
191
|
+
lat: 0
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
set: function set(newLngLat) {
|
|
195
|
+
this.popupOption.lngLat = newLngLat;
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "getIsShow",
|
|
199
|
+
value: function getIsShow() {
|
|
200
|
+
return this.isShow;
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "addTo",
|
|
204
|
+
value: function addTo(scene) {
|
|
205
|
+
this.mapsService = scene.get(TYPES.IMapService);
|
|
206
|
+
this.sceneService = scene.get(TYPES.ISceneService);
|
|
207
|
+
this.layerService = scene.get(TYPES.ILayerService);
|
|
208
|
+
this.mapsService.on('camerachange', this.update);
|
|
209
|
+
this.mapsService.on('viewchange', this.update);
|
|
210
|
+
this.scene = scene;
|
|
211
|
+
this.update();
|
|
212
|
+
this.updateCloseOnClick();
|
|
213
|
+
this.updateCloseOnEsc();
|
|
214
|
+
this.updateFollowCursor();
|
|
215
|
+
var _this$popupOption2 = this.popupOption,
|
|
216
|
+
html = _this$popupOption2.html,
|
|
217
|
+
text = _this$popupOption2.text;
|
|
218
|
+
|
|
219
|
+
if (html) {
|
|
220
|
+
this.setHTML(html);
|
|
221
|
+
} else if (text) {
|
|
222
|
+
this.setText(text);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
this.emit('open');
|
|
226
|
+
return this;
|
|
227
|
+
} // 移除popup
|
|
228
|
+
|
|
229
|
+
}, {
|
|
230
|
+
key: "remove",
|
|
231
|
+
value: function remove() {
|
|
232
|
+
if (!this.isOpen()) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (this.content) {
|
|
237
|
+
DOM.remove(this.content);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (this.container) {
|
|
241
|
+
DOM.remove(this.container); // @ts-ignore
|
|
242
|
+
|
|
243
|
+
delete this.container;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (this.mapsService) {
|
|
247
|
+
// TODO: mapbox AMap 事件同步
|
|
248
|
+
this.mapsService.off('camerachange', this.update);
|
|
249
|
+
this.mapsService.off('viewchange', this.update);
|
|
250
|
+
this.updateCloseOnClick(true);
|
|
251
|
+
this.updateCloseOnEsc(true);
|
|
252
|
+
this.updateFollowCursor(true); // @ts-ignore
|
|
253
|
+
|
|
254
|
+
delete this.mapsService;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.emit('close');
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 获取 option 配置
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
}, {
|
|
265
|
+
key: "getOptions",
|
|
266
|
+
value: function getOptions() {
|
|
267
|
+
return this.popupOption;
|
|
268
|
+
}
|
|
269
|
+
}, {
|
|
270
|
+
key: "setOptions",
|
|
271
|
+
value: function setOptions(option) {
|
|
272
|
+
this.popupOption = _objectSpread(_objectSpread({}, this.popupOption), option);
|
|
273
|
+
|
|
274
|
+
if (this.checkUpdateOption(option, ['closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets', 'title'])) {
|
|
275
|
+
if (this.container) {
|
|
276
|
+
DOM.remove(this.container); // @ts-ignore
|
|
277
|
+
|
|
278
|
+
this.container = undefined;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (this.popupOption.html) {
|
|
282
|
+
this.setHTML(this.popupOption.html);
|
|
283
|
+
} else if (this.popupOption.text) {
|
|
284
|
+
this.setText(this.popupOption.text);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (this.checkUpdateOption(option, ['closeOnEsc'])) {
|
|
289
|
+
this.updateCloseOnEsc();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (this.checkUpdateOption(option, ['closeOnClick'])) {
|
|
293
|
+
this.updateCloseOnClick();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (this.checkUpdateOption(option, ['followCursor'])) {
|
|
297
|
+
this.updateFollowCursor();
|
|
298
|
+
}
|
|
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
|
+
|
|
306
|
+
if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
|
|
307
|
+
this.setLnglat(option.lngLat);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
}, {
|
|
313
|
+
key: "open",
|
|
314
|
+
value: function open() {
|
|
315
|
+
this.addTo(this.scene);
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
}, {
|
|
319
|
+
key: "close",
|
|
320
|
+
value: function close() {
|
|
321
|
+
this.remove();
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
}, {
|
|
325
|
+
key: "show",
|
|
326
|
+
value: function show() {
|
|
327
|
+
if (this.isShow) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (this.container) {
|
|
332
|
+
DOM.removeClass(this.container, 'l7-popup-hide');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
this.isShow = true;
|
|
336
|
+
this.emit('show');
|
|
337
|
+
return this;
|
|
338
|
+
}
|
|
339
|
+
}, {
|
|
340
|
+
key: "hide",
|
|
341
|
+
value: function hide() {
|
|
342
|
+
if (!this.isShow) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (this.container) {
|
|
347
|
+
DOM.addClass(this.container, 'l7-popup-hide');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
this.isShow = false;
|
|
351
|
+
this.emit('hide');
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* 设置 HTML 内容
|
|
356
|
+
* @param html
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
}, {
|
|
360
|
+
key: "setHTML",
|
|
361
|
+
value: function setHTML(html) {
|
|
362
|
+
this.popupOption.html = html;
|
|
363
|
+
return this.setDOMContent(this.getPopupHTMLFragment(html));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 设置 Popup 展示文本
|
|
367
|
+
* @param text
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
}, {
|
|
371
|
+
key: "setText",
|
|
372
|
+
value: function setText(text) {
|
|
373
|
+
this.popupOption.text = text;
|
|
374
|
+
return this.setDOMContent(window.document.createTextNode(text));
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* 将地图自动平移到气泡位置
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
}, {
|
|
381
|
+
key: "panToPopup",
|
|
382
|
+
value: function panToPopup() {
|
|
383
|
+
var _this$lngLat2 = this.lngLat,
|
|
384
|
+
lng = _this$lngLat2.lng,
|
|
385
|
+
lat = _this$lngLat2.lat;
|
|
386
|
+
|
|
387
|
+
if (this.popupOption.autoPan) {
|
|
388
|
+
this.mapsService.panTo([lng, lat]);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
}, {
|
|
394
|
+
key: "setLngLat",
|
|
395
|
+
value: function setLngLat(lngLat) {
|
|
396
|
+
return this.setLnglat(lngLat);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* 设置 Popup 所在经纬度
|
|
400
|
+
* @param lngLat
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
}, {
|
|
404
|
+
key: "setLnglat",
|
|
405
|
+
value: function setLnglat(lngLat) {
|
|
406
|
+
var _this2 = this;
|
|
407
|
+
|
|
408
|
+
this.lngLat = lngLat;
|
|
409
|
+
|
|
410
|
+
if (Array.isArray(lngLat)) {
|
|
411
|
+
this.lngLat = {
|
|
412
|
+
lng: lngLat[0],
|
|
413
|
+
lat: lngLat[1]
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (this.mapsService) {
|
|
418
|
+
// 防止事件重复监听
|
|
419
|
+
this.mapsService.off('camerachange', this.update);
|
|
420
|
+
this.mapsService.off('viewchange', this.update);
|
|
421
|
+
this.mapsService.on('camerachange', this.update);
|
|
422
|
+
this.mapsService.on('viewchange', this.update);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
this.update();
|
|
426
|
+
|
|
427
|
+
if (this.popupOption.autoPan) {
|
|
428
|
+
setTimeout(function () {
|
|
429
|
+
_this2.panToPopup();
|
|
430
|
+
}, 0);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 获取 Popup 所在经纬度
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
}, {
|
|
440
|
+
key: "getLnglat",
|
|
441
|
+
value: function getLnglat() {
|
|
442
|
+
return this.lngLat;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* 设置 Popup 最大宽度
|
|
446
|
+
* @param maxWidth
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
}, {
|
|
450
|
+
key: "setMaxWidth",
|
|
451
|
+
value: function setMaxWidth(maxWidth) {
|
|
452
|
+
this.popupOption.maxWidth = maxWidth;
|
|
453
|
+
this.update();
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
456
|
+
}, {
|
|
457
|
+
key: "isOpen",
|
|
458
|
+
value: function isOpen() {
|
|
459
|
+
return !!this.mapsService;
|
|
460
|
+
}
|
|
461
|
+
}, {
|
|
462
|
+
key: "getDefault",
|
|
463
|
+
value: function getDefault(option) {
|
|
464
|
+
// tslint:disable-next-line:no-object-literal-type-assertion
|
|
465
|
+
return {
|
|
466
|
+
closeButton: true,
|
|
467
|
+
closeOnClick: true,
|
|
468
|
+
maxWidth: '240px',
|
|
469
|
+
offsets: [0, 0],
|
|
470
|
+
anchor: anchorType.BOTTOM,
|
|
471
|
+
stopPropagation: true,
|
|
472
|
+
autoPan: false,
|
|
473
|
+
autoClose: true,
|
|
474
|
+
closeOnEsc: false,
|
|
475
|
+
followCursor: false
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* 设置 Popup 内容 HTML
|
|
480
|
+
* @param htmlNode
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
}, {
|
|
484
|
+
key: "setDOMContent",
|
|
485
|
+
value: function setDOMContent(htmlNode) {
|
|
486
|
+
this.createContent();
|
|
487
|
+
this.contentPanel.appendChild(htmlNode);
|
|
488
|
+
this.update();
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* 绑定地图点击事件触发销毁 Popup
|
|
493
|
+
* @protected
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
}, {
|
|
497
|
+
key: "updateCloseOnClick",
|
|
498
|
+
value: function updateCloseOnClick(onlyClear) {
|
|
499
|
+
this.mapsService.off('click', this.onCloseButtonClick);
|
|
500
|
+
|
|
501
|
+
if (this.popupOption.closeOnClick && !onlyClear) {
|
|
502
|
+
this.mapsService.on('click', this.onCloseButtonClick);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}, {
|
|
506
|
+
key: "updateCloseOnEsc",
|
|
507
|
+
value: function updateCloseOnEsc(onlyClear) {
|
|
508
|
+
window.removeEventListener('keydown', this.onKeyDown);
|
|
509
|
+
|
|
510
|
+
if (this.popupOption.closeOnEsc && !onlyClear) {
|
|
511
|
+
window.addEventListener('keydown', this.onKeyDown);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}, {
|
|
515
|
+
key: "updateFollowCursor",
|
|
516
|
+
value: function updateFollowCursor(onlyClear) {
|
|
517
|
+
var container = this.mapsService.getContainer();
|
|
518
|
+
container.removeEventListener('mousemove', this.onMouseMove);
|
|
519
|
+
|
|
520
|
+
if (this.popupOption.followCursor && !onlyClear) {
|
|
521
|
+
container.addEventListener('mousemove', this.onMouseMove);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}, {
|
|
525
|
+
key: "createContent",
|
|
526
|
+
value:
|
|
527
|
+
/**
|
|
528
|
+
* 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
|
|
529
|
+
* @protected
|
|
530
|
+
*/
|
|
531
|
+
function createContent() {
|
|
532
|
+
if (this.content) {
|
|
533
|
+
DOM.remove(this.content);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
this.content = DOM.create('div', 'l7-popup-content', this.container);
|
|
537
|
+
|
|
538
|
+
if (this.popupOption.title) {
|
|
539
|
+
var _this$contentTitle;
|
|
540
|
+
|
|
541
|
+
this.contentTitle = DOM.create('div', 'l7-popup-content__title', this.content);
|
|
542
|
+
(_this$contentTitle = this.contentTitle) === null || _this$contentTitle === void 0 ? void 0 : _this$contentTitle.append(this.getPopupHTMLFragment(this.popupOption.title));
|
|
543
|
+
} else {
|
|
544
|
+
this.contentTitle = undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (this.popupOption.closeButton) {
|
|
548
|
+
var closeButton = createL7Icon('l7-icon-guanbi');
|
|
549
|
+
DOM.addClass(closeButton, 'l7-popup-close-button');
|
|
550
|
+
this.content.appendChild(closeButton);
|
|
551
|
+
|
|
552
|
+
if (this.popupOption.closeButtonOffsets) {
|
|
553
|
+
// 关闭按钮的偏移
|
|
554
|
+
closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
|
|
555
|
+
closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
|
|
556
|
+
} // this.closeButton.type = 'button';
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
closeButton.setAttribute('aria-label', 'Close popup');
|
|
560
|
+
closeButton.addEventListener('click', this.onCloseButtonClick);
|
|
561
|
+
this.closeButton = closeButton;
|
|
562
|
+
} else {
|
|
563
|
+
this.closeButton = undefined;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
this.contentPanel = DOM.create('div', 'l7-popup-content__panel', this.content);
|
|
567
|
+
}
|
|
568
|
+
}, {
|
|
569
|
+
key: "setPopupPosition",
|
|
570
|
+
value:
|
|
571
|
+
/**
|
|
572
|
+
* 设置 Popup 相对于地图容器的 Position
|
|
573
|
+
* @param left
|
|
574
|
+
* @param top
|
|
575
|
+
* @protected
|
|
576
|
+
*/
|
|
577
|
+
function setPopupPosition(left, top) {
|
|
578
|
+
if (this.container) {
|
|
579
|
+
var offsets = this.popupOption.offsets;
|
|
580
|
+
this.container.style.left = left + offsets[0] + 'px';
|
|
581
|
+
this.container.style.top = top - offsets[1] + 'px';
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* 检查当前传入 option 是否包含 keys 字段
|
|
586
|
+
* @param option
|
|
587
|
+
* @param keys
|
|
588
|
+
* @protected
|
|
589
|
+
*/
|
|
590
|
+
|
|
591
|
+
}, {
|
|
592
|
+
key: "checkUpdateOption",
|
|
593
|
+
value: function checkUpdateOption(option, keys) {
|
|
594
|
+
return keys.some(function (key) {
|
|
595
|
+
return key in option;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* 根据参数 HTML 片段返回对应的 Fragment
|
|
600
|
+
* @param html
|
|
601
|
+
* @protected
|
|
602
|
+
*/
|
|
603
|
+
|
|
604
|
+
}, {
|
|
605
|
+
key: "getPopupHTMLFragment",
|
|
606
|
+
value: function getPopupHTMLFragment(html) {
|
|
607
|
+
var frag = window.document.createDocumentFragment();
|
|
608
|
+
var temp = window.document.createElement('body');
|
|
609
|
+
var child;
|
|
610
|
+
|
|
611
|
+
if (typeof html === 'string') {
|
|
612
|
+
temp.innerHTML = html;
|
|
613
|
+
} else if (Array.isArray(html)) {
|
|
614
|
+
temp.append.apply(temp, _toConsumableArray(html));
|
|
615
|
+
} else if (html instanceof HTMLElement) {
|
|
616
|
+
temp.append(html);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
while (true) {
|
|
620
|
+
child = temp.firstChild;
|
|
621
|
+
|
|
622
|
+
if (!child) {
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
frag.appendChild(child);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return frag;
|
|
630
|
+
}
|
|
631
|
+
}]);
|
|
632
|
+
|
|
633
|
+
return Popup;
|
|
634
|
+
}(EventEmitter);
|
|
635
|
+
|
|
636
|
+
export { Popup as default };
|
|
@@ -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,35 @@
|
|
|
1
|
+
export var anchorType;
|
|
2
|
+
|
|
3
|
+
(function (anchorType) {
|
|
4
|
+
anchorType["CENTER"] = "center";
|
|
5
|
+
anchorType["TOP"] = "top";
|
|
6
|
+
anchorType["TOP-LEFT"] = "top-left";
|
|
7
|
+
anchorType["TOP-RIGHT"] = "top-right";
|
|
8
|
+
anchorType["BOTTOM"] = "bottom";
|
|
9
|
+
anchorType["BOTTOM-LEFT"] = "bottom-left";
|
|
10
|
+
anchorType["LEFT"] = "left";
|
|
11
|
+
anchorType["RIGHT"] = "right";
|
|
12
|
+
})(anchorType || (anchorType = {}));
|
|
13
|
+
|
|
14
|
+
export var anchorTranslate = {
|
|
15
|
+
center: 'translate(-50%,-50%)',
|
|
16
|
+
top: 'translate(-50%,0)',
|
|
17
|
+
'top-left': 'translate(0,0)',
|
|
18
|
+
'top-right': 'translate(-100%,0)',
|
|
19
|
+
bottom: 'translate(-50%,-100%)',
|
|
20
|
+
'bottom-left': 'translate(0,-100%)',
|
|
21
|
+
'bottom-right': 'translate(-100%,-100%)',
|
|
22
|
+
left: 'translate(0,-50%)',
|
|
23
|
+
right: 'translate(-100%,-50%)'
|
|
24
|
+
};
|
|
25
|
+
export function applyAnchorClass(element, anchor, prefix) {
|
|
26
|
+
var classList = element.classList;
|
|
27
|
+
|
|
28
|
+
for (var key in anchorTranslate) {
|
|
29
|
+
if (anchorTranslate.hasOwnProperty(key)) {
|
|
30
|
+
classList.remove("l7-".concat(prefix, "-anchor-").concat(key));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
classList.add("l7-".concat(prefix, "-anchor-").concat(anchor));
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createL7Icon: (className: string) => SVGSVGElement;
|
package/es/utils/icon.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var createL7Icon = function createL7Icon(className) {
|
|
2
|
+
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
3
|
+
svg.classList.add('l7-iconfont');
|
|
4
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
5
|
+
var use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
|
|
6
|
+
use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', "#".concat(className));
|
|
7
|
+
svg.appendChild(use);
|
|
8
|
+
return svg;
|
|
9
|
+
};
|