@antv/l7-component 2.9.25 → 2.9.26-alpha.0

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/popup.js DELETED
@@ -1,300 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
-
9
- 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); }; }
10
-
11
- 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; } }
12
-
13
- import { TYPES } from '@antv/l7-core';
14
- import { anchorTranslate, anchorType, applyAnchorClass, bindAll, DOM } from '@antv/l7-utils';
15
- import { EventEmitter } from 'eventemitter3';
16
-
17
- /** colse event */
18
- var Popup = /*#__PURE__*/function (_EventEmitter) {
19
- _inherits(Popup, _EventEmitter);
20
-
21
- var _super = _createSuper(Popup);
22
-
23
- function Popup(cfg) {
24
- var _this;
25
-
26
- _classCallCheck(this, Popup);
27
-
28
- _this = _super.call(this);
29
- _this.popupOption = _objectSpread(_objectSpread({}, _this.getdefault()), cfg);
30
- bindAll(['update', 'onClickClose', 'remove'], _assertThisInitialized(_this));
31
- return _this;
32
- }
33
-
34
- _createClass(Popup, [{
35
- key: "addTo",
36
- value: function addTo(scene) {
37
- var _this2 = this;
38
-
39
- this.mapsService = scene.get(TYPES.IMapService);
40
- this.sceneSerive = scene.get(TYPES.ISceneService);
41
- this.mapsService.on('camerachange', this.update);
42
- this.mapsService.on('viewchange', this.update);
43
- this.scene = scene;
44
- this.update();
45
-
46
- if (this.popupOption.closeOnClick) {
47
- this.timeoutInstance = setTimeout(function () {
48
- _this2.mapsService.on('click', _this2.onClickClose);
49
- }, 30);
50
- }
51
-
52
- this.emit('open');
53
- return this;
54
- }
55
- }, {
56
- key: "close",
57
- value: function close() {
58
- this.remove();
59
- }
60
- }, {
61
- key: "open",
62
- value: function open() {
63
- this.addTo(this.scene);
64
- }
65
- }, {
66
- key: "setHTML",
67
- value: function setHTML(html) {
68
- var frag = window.document.createDocumentFragment();
69
- var temp = window.document.createElement('body');
70
- var child;
71
- temp.innerHTML = html;
72
-
73
- while (true) {
74
- child = temp.firstChild;
75
-
76
- if (!child) {
77
- break;
78
- }
79
-
80
- frag.appendChild(child);
81
- }
82
-
83
- return this.setDOMContent(frag);
84
- }
85
- }, {
86
- key: "setLnglat",
87
- value: function setLnglat(lngLat) {
88
- this.lngLat = lngLat;
89
-
90
- if (Array.isArray(lngLat)) {
91
- this.lngLat = {
92
- lng: lngLat[0],
93
- lat: lngLat[1]
94
- };
95
- }
96
-
97
- if (this.mapsService) {
98
- this.mapsService.on('camerachange', this.update);
99
- this.mapsService.on('viewchange', this.update);
100
- }
101
-
102
- this.update();
103
- return this;
104
- }
105
- }, {
106
- key: "getLnglat",
107
- value: function getLnglat() {
108
- return this.lngLat;
109
- }
110
- }, {
111
- key: "setText",
112
- value: function setText(text) {
113
- return this.setDOMContent(window.document.createTextNode(text));
114
- }
115
- }, {
116
- key: "setMaxWidth",
117
- value: function setMaxWidth(maxWidth) {
118
- this.popupOption.maxWidth = maxWidth;
119
- this.update();
120
- return this;
121
- }
122
- }, {
123
- key: "setDOMContent",
124
- value: function setDOMContent(htmlNode) {
125
- this.createContent();
126
- this.content.appendChild(htmlNode);
127
- this.update();
128
- return this;
129
- } // 移除popup
130
-
131
- }, {
132
- key: "remove",
133
- value: function remove() {
134
- if (this.content) {
135
- this.removeDom(this.content);
136
- }
137
-
138
- if (this.container) {
139
- this.removeDom(this.container); // @ts-ignore
140
-
141
- delete this.container;
142
- }
143
-
144
- if (this.mapsService) {
145
- // TODO: mapbox AMap 事件同步
146
- this.mapsService.off('camerachange', this.update);
147
- this.mapsService.off('viewchange', this.update);
148
- this.mapsService.off('click', this.onClickClose); // @ts-ignore
149
-
150
- delete this.mapsService;
151
- }
152
-
153
- clearTimeout(this.timeoutInstance);
154
- this.emit('close');
155
- return this;
156
- }
157
- }, {
158
- key: "isOpen",
159
- value: function isOpen() {
160
- return !!this.mapsService;
161
- }
162
- }, {
163
- key: "createContent",
164
- value: function createContent() {
165
- if (this.content) {
166
- DOM.remove(this.content);
167
- }
168
-
169
- this.content = DOM.create('div', 'l7-popup-content', this.container);
170
-
171
- if (this.popupOption.closeButton) {
172
- this.closeButton = DOM.create('button', 'l7-popup-close-button', this.content);
173
-
174
- if (this.popupOption.closeButtonOffsets) {
175
- // 关闭按钮的偏移
176
- this.closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
177
- this.closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
178
- } // this.closeButton.type = 'button';
179
-
180
-
181
- this.closeButton.setAttribute('aria-label', 'Close popup');
182
- this.closeButton.innerHTML = '×';
183
- this.closeButton.addEventListener('click', this.onClickClose);
184
- }
185
- }
186
- }, {
187
- key: "creatDom",
188
- value: function creatDom(tagName, className, container) {
189
- var el = window.document.createElement(tagName);
190
-
191
- if (className !== undefined) {
192
- el.className = className;
193
- }
194
-
195
- if (container) {
196
- container.appendChild(el);
197
- }
198
-
199
- return el;
200
- }
201
- }, {
202
- key: "removeDom",
203
- value: function removeDom(node) {
204
- if (node.parentNode) {
205
- node.parentNode.removeChild(node);
206
- }
207
- }
208
- }, {
209
- key: "getdefault",
210
- value: function getdefault() {
211
- return {
212
- closeButton: true,
213
- closeOnClick: true,
214
- maxWidth: '240px',
215
- offsets: [0, 0],
216
- anchor: anchorType.BOTTOM,
217
- className: '',
218
- stopPropagation: true
219
- };
220
- }
221
- }, {
222
- key: "onClickClose",
223
- value: function onClickClose(e) {
224
- if (e.stopPropagation) {
225
- e.stopPropagation();
226
- }
227
-
228
- this.remove();
229
- }
230
- }, {
231
- key: "update",
232
- value: function update() {
233
- var _this3 = this;
234
-
235
- var hasPosition = this.lngLat;
236
- var _this$popupOption = this.popupOption,
237
- className = _this$popupOption.className,
238
- maxWidth = _this$popupOption.maxWidth,
239
- anchor = _this$popupOption.anchor;
240
-
241
- if (!this.mapsService || !hasPosition || !this.content) {
242
- return;
243
- }
244
-
245
- var popupContainer = this.mapsService.getMarkerContainer();
246
-
247
- if (!this.container && popupContainer) {
248
- this.container = this.creatDom('div', 'l7-popup', popupContainer);
249
- this.tip = this.creatDom('div', 'l7-popup-tip', this.container);
250
- this.container.appendChild(this.content);
251
-
252
- if (className) {
253
- className.split(' ').forEach(function (name) {
254
- return _this3.container.classList.add(name);
255
- });
256
- } // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
257
-
258
-
259
- var stopPropagation = this.popupOption.stopPropagation;
260
-
261
- if (stopPropagation) {
262
- ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
263
- _this3.container.addEventListener(type, function (e) {
264
- e.stopPropagation();
265
- });
266
- });
267
- }
268
-
269
- this.container.style.whiteSpace = 'nowrap';
270
- }
271
-
272
- if (maxWidth && this.container.style.maxWidth !== maxWidth) {
273
- this.container.style.maxWidth = maxWidth;
274
- }
275
-
276
- this.updatePosition();
277
- DOM.setTransform(this.container, "".concat(anchorTranslate[anchor]));
278
- applyAnchorClass(this.container, anchor, 'popup');
279
- }
280
- }, {
281
- key: "updatePosition",
282
- value: function updatePosition() {
283
- if (!this.mapsService) {
284
- return;
285
- }
286
-
287
- var _this$lngLat = this.lngLat,
288
- lng = _this$lngLat.lng,
289
- lat = _this$lngLat.lat;
290
- var offsets = this.popupOption.offsets;
291
- var pos = this.mapsService.lngLatToContainer([lng, lat]);
292
- this.container.style.left = pos.x + offsets[0] + 'px';
293
- this.container.style.top = pos.y - offsets[1] + 'px';
294
- }
295
- }]);
296
-
297
- return Popup;
298
- }(EventEmitter);
299
-
300
- export { Popup as default };
@@ -1,22 +0,0 @@
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;
@@ -1,35 +0,0 @@
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
- }
@@ -1,110 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/control/BaseControl.ts
20
- var BaseControl_exports = {};
21
- __export(BaseControl_exports, {
22
- PositionType: () => import_l7_core2.PositionType,
23
- default: () => Control
24
- });
25
- module.exports = __toCommonJS(BaseControl_exports);
26
- var import_l7_core = require("@antv/l7-core");
27
- var import_l7_utils = require("@antv/l7-utils");
28
- var import_eventemitter3 = require("eventemitter3");
29
- var import_l7_core2 = require("@antv/l7-core");
30
- var controlId = 0;
31
- var Control = class extends import_eventemitter3.EventEmitter {
32
- constructor(cfg) {
33
- super();
34
- this.controlOption = {
35
- ...this.getDefault(),
36
- ...cfg || {}
37
- };
38
- }
39
- getDefault() {
40
- return {
41
- position: import_l7_core.PositionType.TOPRIGHT,
42
- name: `${controlId++}`
43
- };
44
- }
45
- setPosition(position = import_l7_core.PositionType.BOTTOMRIGHT) {
46
- const controlService = this.controlService;
47
- if (controlService) {
48
- controlService.removeControl(this);
49
- }
50
- this.controlOption.position = position;
51
- if (controlService) {
52
- controlService.addControl(this, this.sceneContainer);
53
- }
54
- return this;
55
- }
56
- addTo(sceneContainer) {
57
- this.mapsService = sceneContainer.get(import_l7_core.TYPES.IMapService);
58
- this.renderService = sceneContainer.get(import_l7_core.TYPES.IRendererService);
59
- this.layerService = sceneContainer.get(import_l7_core.TYPES.ILayerService);
60
- this.controlService = sceneContainer.get(import_l7_core.TYPES.IControlService);
61
- this.sceneContainer = sceneContainer;
62
- this.isShow = true;
63
- this.container = this.onAdd();
64
- const container = this.container;
65
- const pos = this.controlOption.position;
66
- const corner = this.controlService.controlCorners[pos];
67
- import_l7_utils.DOM.addClass(container, "l7-control");
68
- if (pos.indexOf("bottom") !== -1) {
69
- corner.insertBefore(container, corner.firstChild);
70
- } else {
71
- corner.appendChild(container);
72
- }
73
- return this;
74
- }
75
- onAdd() {
76
- throw new Error("Method not implemented.");
77
- }
78
- onRemove() {
79
- throw new Error("Method not implemented.");
80
- }
81
- hide() {
82
- const container = this.container;
83
- import_l7_utils.DOM.addClass(container, "l7-control-hide");
84
- this.isShow = false;
85
- }
86
- show() {
87
- const container = this.container;
88
- import_l7_utils.DOM.removeClass(container, "l7-control-hide");
89
- this.isShow = true;
90
- }
91
- remove() {
92
- if (!this.mapsService) {
93
- return this;
94
- }
95
- import_l7_utils.DOM.remove(this.container);
96
- this.onRemove();
97
- }
98
- _refocusOnMap(e) {
99
- if (this.mapsService && e && e.screenX > 0 && e.screenY > 0) {
100
- const container = this.mapsService.getContainer();
101
- if (container !== null) {
102
- container.focus();
103
- }
104
- }
105
- }
106
- };
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- PositionType
110
- });