@antv/l7-component 2.5.37-mini3 → 2.5.40
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/CHANGELOG.md +325 -0
- package/LICENSE.md +21 -0
- package/es/control/BaseControl.d.ts +27 -0
- package/es/control/BaseControl.js +155 -0
- package/es/control/BaseControl.js.map +1 -0
- package/es/control/layer.d.ts +44 -0
- package/es/control/layer.js +355 -0
- package/es/control/layer.js.map +1 -0
- package/es/control/logo.d.ts +9 -0
- package/es/control/logo.js +58 -0
- package/es/control/logo.js.map +1 -0
- package/es/control/scale.d.ts +30 -0
- package/es/control/scale.js +153 -0
- package/es/control/scale.js.map +1 -0
- package/es/control/zoom.d.ts +30 -0
- package/es/control/zoom.js +128 -0
- package/es/control/zoom.js.map +1 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +52 -0
- package/es/index.js.map +1 -0
- package/es/marker.d.ts +47 -0
- package/es/marker.js +427 -0
- package/es/marker.js.map +1 -0
- package/es/markerlayer.d.ts +68 -0
- package/es/markerlayer.js +309 -0
- package/es/markerlayer.js.map +1 -0
- package/es/popup.d.ts +35 -0
- package/es/popup.js +316 -0
- package/es/popup.js.map +1 -0
- package/es/utils/anchor.d.ts +22 -0
- package/es/utils/anchor.js +36 -0
- package/es/utils/anchor.js.map +1 -0
- package/package.json +4 -4
package/es/popup.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
12
|
+
|
|
13
|
+
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); }; }
|
|
14
|
+
|
|
15
|
+
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; } }
|
|
16
|
+
|
|
17
|
+
import { TYPES } from '@antv/l7-core';
|
|
18
|
+
import { anchorTranslate, anchorType, applyAnchorClass, bindAll, DOM } from '@antv/l7-utils';
|
|
19
|
+
import { EventEmitter } from 'eventemitter3';
|
|
20
|
+
|
|
21
|
+
var Popup = 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), "popupOption", void 0);
|
|
34
|
+
|
|
35
|
+
_defineProperty(_assertThisInitialized(_this), "mapsService", void 0);
|
|
36
|
+
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "sceneSerive", void 0);
|
|
38
|
+
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "lngLat", void 0);
|
|
40
|
+
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "content", void 0);
|
|
42
|
+
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "closeButton", void 0);
|
|
44
|
+
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "timeoutInstance", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "container", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(_assertThisInitialized(_this), "tip", void 0);
|
|
50
|
+
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "scene", void 0);
|
|
52
|
+
|
|
53
|
+
_this.popupOption = _objectSpread(_objectSpread({}, _this.getdefault()), cfg);
|
|
54
|
+
bindAll(['update', 'onClickClose', 'remove'], _assertThisInitialized(_this));
|
|
55
|
+
return _this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_createClass(Popup, [{
|
|
59
|
+
key: "addTo",
|
|
60
|
+
value: function addTo(scene) {
|
|
61
|
+
var _this2 = this;
|
|
62
|
+
|
|
63
|
+
this.mapsService = scene.get(TYPES.IMapService);
|
|
64
|
+
this.sceneSerive = scene.get(TYPES.ISceneService);
|
|
65
|
+
this.mapsService.on('camerachange', this.update);
|
|
66
|
+
this.mapsService.on('viewchange', this.update);
|
|
67
|
+
this.scene = scene;
|
|
68
|
+
this.update();
|
|
69
|
+
|
|
70
|
+
if (this.popupOption.closeOnClick) {
|
|
71
|
+
this.timeoutInstance = setTimeout(function () {
|
|
72
|
+
_this2.mapsService.on('click', _this2.onClickClose);
|
|
73
|
+
}, 30);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.emit('open');
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "close",
|
|
81
|
+
value: function close() {
|
|
82
|
+
this.remove();
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "open",
|
|
86
|
+
value: function open() {
|
|
87
|
+
this.addTo(this.scene);
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "setHTML",
|
|
91
|
+
value: function setHTML(html) {
|
|
92
|
+
var frag = window.document.createDocumentFragment();
|
|
93
|
+
var temp = window.document.createElement('body');
|
|
94
|
+
var child;
|
|
95
|
+
temp.innerHTML = html;
|
|
96
|
+
|
|
97
|
+
while (true) {
|
|
98
|
+
child = temp.firstChild;
|
|
99
|
+
|
|
100
|
+
if (!child) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
frag.appendChild(child);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this.setDOMContent(frag);
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "setLnglat",
|
|
111
|
+
value: function setLnglat(lngLat) {
|
|
112
|
+
this.lngLat = lngLat;
|
|
113
|
+
|
|
114
|
+
if (Array.isArray(lngLat)) {
|
|
115
|
+
this.lngLat = {
|
|
116
|
+
lng: lngLat[0],
|
|
117
|
+
lat: lngLat[1]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (this.mapsService) {
|
|
122
|
+
this.mapsService.on('camerachange', this.update);
|
|
123
|
+
this.mapsService.on('viewchange', this.update);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.update();
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
}, {
|
|
130
|
+
key: "getLnglat",
|
|
131
|
+
value: function getLnglat() {
|
|
132
|
+
return this.lngLat;
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "setText",
|
|
136
|
+
value: function setText(text) {
|
|
137
|
+
return this.setDOMContent(window.document.createTextNode(text));
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "setMaxWidth",
|
|
141
|
+
value: function setMaxWidth(maxWidth) {
|
|
142
|
+
this.popupOption.maxWidth = maxWidth;
|
|
143
|
+
this.update();
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "setDOMContent",
|
|
148
|
+
value: function setDOMContent(htmlNode) {
|
|
149
|
+
this.createContent();
|
|
150
|
+
this.content.appendChild(htmlNode);
|
|
151
|
+
this.update();
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
}, {
|
|
155
|
+
key: "remove",
|
|
156
|
+
value: function remove() {
|
|
157
|
+
if (this.content) {
|
|
158
|
+
this.removeDom(this.content);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this.container) {
|
|
162
|
+
this.removeDom(this.container);
|
|
163
|
+
delete this.container;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.mapsService) {
|
|
167
|
+
this.mapsService.off('camerachange', this.update);
|
|
168
|
+
this.mapsService.off('viewchange', this.update);
|
|
169
|
+
this.mapsService.off('click', this.onClickClose);
|
|
170
|
+
delete this.mapsService;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
clearTimeout(this.timeoutInstance);
|
|
174
|
+
this.emit('close');
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "isOpen",
|
|
179
|
+
value: function isOpen() {
|
|
180
|
+
return !!this.mapsService;
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "createContent",
|
|
184
|
+
value: function createContent() {
|
|
185
|
+
if (this.content) {
|
|
186
|
+
DOM.remove(this.content);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.content = DOM.create('div', 'l7-popup-content', this.container);
|
|
190
|
+
|
|
191
|
+
if (this.popupOption.closeButton) {
|
|
192
|
+
this.closeButton = DOM.create('button', 'l7-popup-close-button', this.content);
|
|
193
|
+
|
|
194
|
+
if (this.popupOption.closeButtonOffsets) {
|
|
195
|
+
this.closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
|
|
196
|
+
this.closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.closeButton.setAttribute('aria-label', 'Close popup');
|
|
200
|
+
this.closeButton.innerHTML = '×';
|
|
201
|
+
this.closeButton.addEventListener('click', this.onClickClose);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "creatDom",
|
|
206
|
+
value: function creatDom(tagName, className, container) {
|
|
207
|
+
var el = window.document.createElement(tagName);
|
|
208
|
+
|
|
209
|
+
if (className !== undefined) {
|
|
210
|
+
el.className = className;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (container) {
|
|
214
|
+
container.appendChild(el);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return el;
|
|
218
|
+
}
|
|
219
|
+
}, {
|
|
220
|
+
key: "removeDom",
|
|
221
|
+
value: function removeDom(node) {
|
|
222
|
+
if (node.parentNode) {
|
|
223
|
+
node.parentNode.removeChild(node);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "getdefault",
|
|
228
|
+
value: function getdefault() {
|
|
229
|
+
return {
|
|
230
|
+
closeButton: true,
|
|
231
|
+
closeOnClick: true,
|
|
232
|
+
maxWidth: '240px',
|
|
233
|
+
offsets: [0, 0],
|
|
234
|
+
anchor: anchorType.BOTTOM,
|
|
235
|
+
className: '',
|
|
236
|
+
stopPropagation: true
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}, {
|
|
240
|
+
key: "onClickClose",
|
|
241
|
+
value: function onClickClose(e) {
|
|
242
|
+
if (e.stopPropagation) {
|
|
243
|
+
e.stopPropagation();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this.remove();
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "update",
|
|
250
|
+
value: function update() {
|
|
251
|
+
var _this3 = this;
|
|
252
|
+
|
|
253
|
+
var hasPosition = this.lngLat;
|
|
254
|
+
var _this$popupOption = this.popupOption,
|
|
255
|
+
className = _this$popupOption.className,
|
|
256
|
+
maxWidth = _this$popupOption.maxWidth,
|
|
257
|
+
anchor = _this$popupOption.anchor;
|
|
258
|
+
|
|
259
|
+
if (!this.mapsService || !hasPosition || !this.content) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var popupContainer = this.mapsService.getMarkerContainer();
|
|
264
|
+
|
|
265
|
+
if (!this.container && popupContainer) {
|
|
266
|
+
this.container = this.creatDom('div', 'l7-popup', popupContainer);
|
|
267
|
+
this.tip = this.creatDom('div', 'l7-popup-tip', this.container);
|
|
268
|
+
this.container.appendChild(this.content);
|
|
269
|
+
|
|
270
|
+
if (className) {
|
|
271
|
+
className.split(' ').forEach(function (name) {
|
|
272
|
+
return _this3.container.classList.add(name);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var stopPropagation = this.popupOption.stopPropagation;
|
|
277
|
+
|
|
278
|
+
if (stopPropagation) {
|
|
279
|
+
['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
|
|
280
|
+
_this3.container.addEventListener(type, function (e) {
|
|
281
|
+
e.stopPropagation();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (maxWidth && this.container.style.maxWidth !== maxWidth) {
|
|
288
|
+
this.container.style.maxWidth = maxWidth;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
this.updatePosition();
|
|
292
|
+
DOM.setTransform(this.container, "".concat(anchorTranslate[anchor]));
|
|
293
|
+
applyAnchorClass(this.container, anchor, 'popup');
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
key: "updatePosition",
|
|
297
|
+
value: function updatePosition() {
|
|
298
|
+
if (!this.mapsService) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
var _this$lngLat = this.lngLat,
|
|
303
|
+
lng = _this$lngLat.lng,
|
|
304
|
+
lat = _this$lngLat.lat;
|
|
305
|
+
var offsets = this.popupOption.offsets;
|
|
306
|
+
var pos = this.mapsService.lngLatToContainer([lng, lat]);
|
|
307
|
+
this.container.style.left = pos.x + offsets[0] + 'px';
|
|
308
|
+
this.container.style.top = pos.y - offsets[1] + 'px';
|
|
309
|
+
}
|
|
310
|
+
}]);
|
|
311
|
+
|
|
312
|
+
return Popup;
|
|
313
|
+
}(EventEmitter);
|
|
314
|
+
|
|
315
|
+
export { Popup as default };
|
|
316
|
+
//# sourceMappingURL=popup.js.map
|
package/es/popup.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/popup.ts"],"names":["TYPES","anchorTranslate","anchorType","applyAnchorClass","bindAll","DOM","EventEmitter","Popup","cfg","popupOption","getdefault","scene","mapsService","get","IMapService","sceneSerive","ISceneService","on","update","closeOnClick","timeoutInstance","setTimeout","onClickClose","emit","remove","addTo","html","frag","window","document","createDocumentFragment","temp","createElement","child","innerHTML","firstChild","appendChild","setDOMContent","lngLat","Array","isArray","lng","lat","text","createTextNode","maxWidth","htmlNode","createContent","content","removeDom","container","off","clearTimeout","create","closeButton","closeButtonOffsets","style","right","top","setAttribute","addEventListener","tagName","className","el","undefined","node","parentNode","removeChild","offsets","anchor","BOTTOM","stopPropagation","e","hasPosition","popupContainer","getMarkerContainer","creatDom","tip","split","forEach","name","classList","add","type","updatePosition","setTransform","pos","lngLatToContainer","left","x","y"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAO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F;AACD,aAFD;AAGD,WALH;AAOD;AACF;;AACD,UAAI1B,QAAQ,IAAI,KAAKK,SAAL,CAAeM,KAAf,CAAqBX,QAArB,KAAkCA,QAAlD,EAA4D;AAC1D,aAAKK,SAAL,CAAeM,KAAf,CAAqBX,QAArB,GAAgCA,QAAhC;AACD;;AAED,WAAKuC,cAAL;AACA/E,MAAAA,GAAG,CAACgF,YAAJ,CAAiB,KAAKnC,SAAtB,YAAoCjD,eAAe,CAACoE,MAAD,CAAnD;AACAlE,MAAAA,gBAAgB,CAAC,KAAK+C,SAAN,EAAiBmB,MAAjB,EAAyB,OAAzB,CAAhB;AACD;;;WAED,0BAAyB;AACvB,UAAI,CAAC,KAAKzD,WAAV,EAAuB;AACrB;AACD;;AACD,yBAAqB,KAAK0B,MAA1B;AAAA,UAAQG,GAAR,gBAAQA,GAAR;AAAA,UAAaC,GAAb,gBAAaA,GAAb;AACA,UAAQ0B,OAAR,GAAoB,KAAK3D,WAAzB,CAAQ2D,OAAR;AACA,UAAMkB,GAAG,GAAG,KAAK1E,WAAL,CAAiB2E,iBAAjB,CAAmC,CAAC9C,GAAD,EAAMC,GAAN,CAAnC,CAAZ;AACA,WAAKQ,SAAL,CAAeM,KAAf,CAAqBgC,IAArB,GAA4BF,GAAG,CAACG,CAAJ,GAAQrB,OAAO,CAAC,CAAD,CAAf,GAAqB,IAAjD;AACA,WAAKlB,SAAL,CAAeM,KAAf,CAAqBE,GAArB,GAA2B4B,GAAG,CAACI,CAAJ,GAAQtB,OAAO,CAAC,CAAD,CAAf,GAAqB,IAAhD;AACD;;;;EA9OgC9D,Y;;SAAdC,K","sourcesContent":["import {\n ILngLat,\n IMapService,\n IPoint,\n IPopup,\n IPopupOption,\n ISceneService,\n TYPES,\n} from '@antv/l7-core';\nimport {\n anchorTranslate,\n anchorType,\n applyAnchorClass,\n bindAll,\n DOM,\n} from '@antv/l7-utils';\nimport { EventEmitter } from 'eventemitter3';\nimport { Container } from 'inversify';\n\n/** colse event */\n\nexport default class Popup extends EventEmitter implements IPopup {\n private popupOption: IPopupOption;\n private mapsService: IMapService<unknown>;\n private sceneSerive: ISceneService;\n private lngLat: ILngLat;\n private content: HTMLElement;\n private closeButton: HTMLElement;\n private timeoutInstance: any;\n private container: HTMLElement;\n private tip: HTMLElement;\n private scene: Container;\n\n constructor(cfg?: Partial<IPopupOption>) {\n super();\n this.popupOption = {\n ...this.getdefault(),\n ...cfg,\n };\n bindAll(['update', 'onClickClose', 'remove'], this);\n }\n\n public addTo(scene: Container) {\n this.mapsService = scene.get<IMapService>(TYPES.IMapService);\n this.sceneSerive = scene.get<ISceneService>(TYPES.ISceneService);\n this.mapsService.on('camerachange', this.update);\n this.mapsService.on('viewchange', this.update);\n this.scene = scene;\n this.update();\n if (this.popupOption.closeOnClick) {\n this.timeoutInstance = setTimeout(() => {\n this.mapsService.on('click', this.onClickClose);\n }, 30);\n }\n this.emit('open');\n return this;\n }\n\n public close(): void {\n this.remove();\n }\n\n public open(): void {\n this.addTo(this.scene);\n }\n\n public setHTML(html: string) {\n const frag = window.document.createDocumentFragment();\n const temp = window.document.createElement('body');\n let child: ChildNode | null;\n temp.innerHTML = html;\n while (true) {\n child = temp.firstChild;\n if (!child) {\n break;\n }\n frag.appendChild(child);\n }\n\n return this.setDOMContent(frag);\n }\n\n public setLnglat(lngLat: ILngLat | number[]): this {\n this.lngLat = lngLat as ILngLat;\n if (Array.isArray(lngLat)) {\n this.lngLat = {\n lng: lngLat[0],\n lat: lngLat[1],\n };\n }\n if (this.mapsService) {\n this.mapsService.on('camerachange', this.update);\n this.mapsService.on('viewchange', this.update);\n }\n this.update();\n return this;\n }\n public getLnglat(): ILngLat {\n return this.lngLat;\n }\n public setText(text: string) {\n return this.setDOMContent(window.document.createTextNode(text));\n }\n\n public setMaxWidth(maxWidth: string): this {\n this.popupOption.maxWidth = maxWidth;\n this.update();\n return this;\n }\n\n public setDOMContent(htmlNode: ChildNode | DocumentFragment) {\n this.createContent();\n this.content.appendChild(htmlNode);\n this.update();\n return this;\n }\n\n // 移除popup\n public remove() {\n if (this.content) {\n this.removeDom(this.content);\n }\n\n if (this.container) {\n this.removeDom(this.container);\n // @ts-ignore\n delete this.container;\n }\n if (this.mapsService) {\n // TODO: mapbox AMap 事件同步\n this.mapsService.off('camerachange', this.update);\n this.mapsService.off('viewchange', this.update);\n this.mapsService.off('click', this.onClickClose);\n // @ts-ignore\n delete this.mapsService;\n }\n clearTimeout(this.timeoutInstance);\n this.emit('close');\n return this;\n }\n public isOpen() {\n return !!this.mapsService;\n }\n\n private createContent() {\n if (this.content) {\n DOM.remove(this.content);\n }\n this.content = DOM.create('div', 'l7-popup-content', this.container);\n if (this.popupOption.closeButton) {\n this.closeButton = DOM.create(\n 'button',\n 'l7-popup-close-button',\n this.content,\n );\n\n if (this.popupOption.closeButtonOffsets) {\n // 关闭按钮的偏移\n this.closeButton.style.right =\n this.popupOption.closeButtonOffsets[0] + 'px';\n this.closeButton.style.top =\n this.popupOption.closeButtonOffsets[1] + 'px';\n }\n\n // this.closeButton.type = 'button';\n this.closeButton.setAttribute('aria-label', 'Close popup');\n this.closeButton.innerHTML = '×';\n this.closeButton.addEventListener('click', this.onClickClose);\n }\n }\n\n private creatDom(tagName: string, className: string, container: HTMLElement) {\n const el = window.document.createElement(tagName);\n if (className !== undefined) {\n el.className = className;\n }\n if (container) {\n container.appendChild(el);\n }\n return el;\n }\n\n private removeDom(node: ChildNode) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n\n private getdefault() {\n return {\n closeButton: true,\n closeOnClick: true,\n maxWidth: '240px',\n offsets: [0, 0],\n anchor: anchorType.BOTTOM,\n className: '',\n stopPropagation: true,\n };\n }\n\n private onClickClose(e: Event) {\n if (e.stopPropagation) {\n e.stopPropagation();\n }\n this.remove();\n }\n\n private update() {\n const hasPosition = this.lngLat;\n const { className, maxWidth, anchor } = this.popupOption;\n if (!this.mapsService || !hasPosition || !this.content) {\n return;\n }\n const popupContainer = this.mapsService.getMarkerContainer();\n if (!this.container && popupContainer) {\n this.container = this.creatDom(\n 'div',\n 'l7-popup',\n popupContainer as HTMLElement,\n );\n\n this.tip = this.creatDom('div', 'l7-popup-tip', this.container);\n this.container.appendChild(this.content);\n if (className) {\n className\n .split(' ')\n .forEach((name) => this.container.classList.add(name));\n }\n\n // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加\n const { stopPropagation } = this.popupOption;\n if (stopPropagation) {\n ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(\n (type) => {\n this.container.addEventListener(type, (e) => {\n e.stopPropagation();\n });\n },\n );\n }\n }\n if (maxWidth && this.container.style.maxWidth !== maxWidth) {\n this.container.style.maxWidth = maxWidth;\n }\n\n this.updatePosition();\n DOM.setTransform(this.container, `${anchorTranslate[anchor]}`);\n applyAnchorClass(this.container, anchor, 'popup');\n }\n\n private updatePosition() {\n if (!this.mapsService) {\n return;\n }\n const { lng, lat } = this.lngLat;\n const { offsets } = this.popupOption;\n const pos = this.mapsService.lngLatToContainer([lng, lat]);\n this.container.style.left = pos.x + offsets[0] + 'px';\n this.container.style.top = pos.y - offsets[1] + 'px';\n }\n}\n"],"file":"popup.js"}
|
|
@@ -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,36 @@
|
|
|
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
|
+
}
|
|
36
|
+
//# sourceMappingURL=anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/anchor.ts"],"names":["anchorType","anchorTranslate","center","top","bottom","left","right","applyAnchorClass","element","anchor","prefix","classList","key","hasOwnProperty","remove","add"],"mappings":"AAAA,WAAYA,UAAZ;;WAAYA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;AAAAA,EAAAA,U;GAAAA,U,KAAAA,U;;AAWZ,OAAO,IAAMC,eAAe,GAAG;AAC7BC,EAAAA,MAAM,EAAE,sBADqB;AAE7BC,EAAAA,GAAG,EAAE,mBAFwB;AAG7B,cAAY,gBAHiB;AAI7B,eAAa,oBAJgB;AAK7BC,EAAAA,MAAM,EAAE,uBALqB;AAM7B,iBAAe,oBANc;AAO7B,kBAAgB,wBAPa;AAQ7BC,EAAAA,IAAI,EAAE,mBARuB;AAS7BC,EAAAA,KAAK,EAAE;AATsB,CAAxB;AAYP,OAAO,SAASC,gBAAT,CACLC,OADK,EAELC,MAFK,EAGLC,MAHK,EAIL;AACA,MAAMC,SAAS,GAAGH,OAAO,CAACG,SAA1B;;AACA,OAAK,IAAMC,GAAX,IAAkBX,eAAlB,EAAmC;AACjC,QAAIA,eAAe,CAACY,cAAhB,CAA+BD,GAA/B,CAAJ,EAAyC;AACvCD,MAAAA,SAAS,CAACG,MAAV,cAAuBJ,MAAvB,qBAAwCE,GAAxC;AACD;AACF;;AACDD,EAAAA,SAAS,CAACI,GAAV,cAAoBL,MAApB,qBAAqCD,MAArC;AACD","sourcesContent":["export enum anchorType {\n 'CENTER' = 'center',\n 'TOP' = 'top',\n 'TOP-LEFT' = 'top-left',\n 'TOP-RIGHT' = 'top-right',\n 'BOTTOM' = 'bottom',\n 'BOTTOM-LEFT' = 'bottom-left',\n 'LEFT' = 'left',\n 'RIGHT' = 'right',\n}\n\nexport const anchorTranslate = {\n center: 'translate(-50%,-50%)',\n top: 'translate(-50%,0)',\n 'top-left': 'translate(0,0)',\n 'top-right': 'translate(-100%,0)',\n bottom: 'translate(-50%,-100%)',\n 'bottom-left': 'translate(0,-100%)',\n 'bottom-right': 'translate(-100%,-100%)',\n left: 'translate(0,-50%)',\n right: 'translate(-100%,-50%)',\n};\n\nexport function applyAnchorClass(\n element: HTMLElement,\n anchor: string,\n prefix: string,\n) {\n const classList = element.classList;\n for (const key in anchorTranslate) {\n if (anchorTranslate.hasOwnProperty(key)) {\n classList.remove(`l7-${prefix}-anchor-${key}`);\n }\n }\n classList.add(`l7-${prefix}-anchor-${anchor}`);\n}\n"],"file":"anchor.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/l7-component",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.40",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"author": "lzxue",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@antv/l7-core": "^2.5.
|
|
29
|
-
"@antv/l7-utils": "^2.5.
|
|
28
|
+
"@antv/l7-core": "^2.5.40",
|
|
29
|
+
"@antv/l7-utils": "^2.5.40",
|
|
30
30
|
"@babel/runtime": "^7.7.7",
|
|
31
31
|
"eventemitter3": "^4.0.0",
|
|
32
32
|
"inversify": "^5.0.1",
|
|
33
33
|
"reflect-metadata": "^0.1.13"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "71ad386f421143c46bde07222283452e7c394e4b",
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
}
|