@antv/l7-component 2.20.15 → 2.20.17
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/marker.d.ts +1 -0
- package/es/marker.js +74 -18
- package/es/popup/layerPopup.js +2 -1
- package/es/popup/popup.d.ts +7 -3
- package/es/popup/popup.js +54 -7
- package/lib/marker.js +73 -17
- package/lib/popup/layerPopup.js +2 -1
- package/lib/popup/popup.js +54 -7
- package/package.json +6 -6
package/es/marker.d.ts
CHANGED
package/es/marker.js
CHANGED
|
@@ -9,7 +9,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
9
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
10
|
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; } }
|
|
11
11
|
import { TYPES } from '@antv/l7-core';
|
|
12
|
-
import { DOM,
|
|
12
|
+
import { DOM, anchorType, applyAnchorClass, bindAll, isPC, anchorTranslate } from '@antv/l7-utils';
|
|
13
13
|
import { EventEmitter } from 'eventemitter3';
|
|
14
14
|
// marker 支持 dragger 未完成
|
|
15
15
|
var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
@@ -76,7 +76,7 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
_this.markerOption = _objectSpread(_objectSpread({}, _this.getDefault()), option);
|
|
79
|
-
bindAll(['update', 'onMove', 'onMapClick'], _assertThisInitialized(_this));
|
|
79
|
+
bindAll(['update', 'onMove', 'onMapClick', 'updatePositionWhenZoom'], _assertThisInitialized(_this));
|
|
80
80
|
_this.init();
|
|
81
81
|
return _this;
|
|
82
82
|
}
|
|
@@ -108,6 +108,8 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
108
108
|
// this.sceneSerive.getSceneContainer().appendChild(element as HTMLElement);
|
|
109
109
|
this.mapsService.getMarkerContainer().appendChild(element);
|
|
110
110
|
this.registerMarkerEvent(element);
|
|
111
|
+
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
|
|
112
|
+
this.mapsService.on('zoomchange', this.updatePositionWhenZoom);
|
|
111
113
|
this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
|
|
112
114
|
this.update();
|
|
113
115
|
this.updateDraggable();
|
|
@@ -122,6 +124,7 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
122
124
|
this.mapsService.off('click', this.onMapClick);
|
|
123
125
|
this.mapsService.off('move', this.update);
|
|
124
126
|
this.mapsService.off('moveend', this.update);
|
|
127
|
+
this.mapsService.off('zoomchange', this.update);
|
|
125
128
|
this.mapsService.off('camerachange', this.update);
|
|
126
129
|
}
|
|
127
130
|
this.unRegisterMarkerEvent();
|
|
@@ -282,7 +285,60 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
282
285
|
this.updatePosition();
|
|
283
286
|
DOM.setTransform(element, "".concat(anchorTranslate[anchor]));
|
|
284
287
|
}
|
|
285
|
-
|
|
288
|
+
//天地图在开始缩放时触发 更新目标位置时添加过渡效果
|
|
289
|
+
}, {
|
|
290
|
+
key: "updatePositionWhenZoom",
|
|
291
|
+
value: function updatePositionWhenZoom(ev) {
|
|
292
|
+
if (!this.mapsService) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
var _this$markerOption2 = this.markerOption,
|
|
296
|
+
element = _this$markerOption2.element,
|
|
297
|
+
offsets = _this$markerOption2.offsets;
|
|
298
|
+
var _this$lngLat = this.lngLat,
|
|
299
|
+
lng = _this$lngLat.lng,
|
|
300
|
+
lat = _this$lngLat.lat;
|
|
301
|
+
if (element) {
|
|
302
|
+
element.style.display = 'block';
|
|
303
|
+
element.style.whiteSpace = 'nowrap';
|
|
304
|
+
var _ref2 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
|
|
305
|
+
containerHeight = _ref2.containerHeight,
|
|
306
|
+
containerWidth = _ref2.containerWidth,
|
|
307
|
+
bounds = _ref2.bounds;
|
|
308
|
+
if (!bounds) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
var map = ev.map;
|
|
312
|
+
var viewHalf = map.getSize();
|
|
313
|
+
viewHalf.x = viewHalf.x / 2;
|
|
314
|
+
viewHalf.y = viewHalf.y / 2;
|
|
315
|
+
var center = ev.center;
|
|
316
|
+
var zoom = ev.zoom;
|
|
317
|
+
var projectedCenter = map.DE(this.lngLat, zoom, center);
|
|
318
|
+
projectedCenter.x = Math.round(projectedCenter.x + offsets[0]);
|
|
319
|
+
projectedCenter.y = Math.round(projectedCenter.y - offsets[1]);
|
|
320
|
+
// 当前可视区域包含跨日界线
|
|
321
|
+
if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
|
|
322
|
+
if (projectedCenter.x > containerWidth) {
|
|
323
|
+
// 日界线右侧点左移
|
|
324
|
+
var newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
|
|
325
|
+
projectedCenter.x = newPos.x;
|
|
326
|
+
}
|
|
327
|
+
if (projectedCenter.x < 0) {
|
|
328
|
+
// 日界线左侧点右移
|
|
329
|
+
var _newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
|
|
330
|
+
projectedCenter.x = _newPos.x;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (projectedCenter.x > containerWidth || projectedCenter.x < 0 || projectedCenter.y > containerHeight || projectedCenter.y < 0) {
|
|
334
|
+
element.style.display = 'none';
|
|
335
|
+
}
|
|
336
|
+
element.style.left = projectedCenter.x + 'px';
|
|
337
|
+
element.style.top = projectedCenter.y + 'px';
|
|
338
|
+
console.log(projectedCenter);
|
|
339
|
+
element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
340
|
+
}
|
|
341
|
+
}
|
|
286
342
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
287
343
|
}, {
|
|
288
344
|
key: "onMapClick",
|
|
@@ -319,20 +375,20 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
319
375
|
if (!this.mapsService) {
|
|
320
376
|
return;
|
|
321
377
|
}
|
|
322
|
-
var _this$
|
|
323
|
-
element = _this$
|
|
324
|
-
offsets = _this$
|
|
325
|
-
var _this$
|
|
326
|
-
lng = _this$
|
|
327
|
-
lat = _this$
|
|
378
|
+
var _this$markerOption3 = this.markerOption,
|
|
379
|
+
element = _this$markerOption3.element,
|
|
380
|
+
offsets = _this$markerOption3.offsets;
|
|
381
|
+
var _this$lngLat2 = this.lngLat,
|
|
382
|
+
lng = _this$lngLat2.lng,
|
|
383
|
+
lat = _this$lngLat2.lat;
|
|
328
384
|
var pos = this.mapsService.lngLatToContainer([lng, lat]);
|
|
329
385
|
if (element) {
|
|
330
386
|
element.style.display = 'block';
|
|
331
387
|
element.style.whiteSpace = 'nowrap';
|
|
332
|
-
var
|
|
333
|
-
containerHeight =
|
|
334
|
-
containerWidth =
|
|
335
|
-
bounds =
|
|
388
|
+
var _ref3 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
|
|
389
|
+
containerHeight = _ref3.containerHeight,
|
|
390
|
+
containerWidth = _ref3.containerWidth,
|
|
391
|
+
bounds = _ref3.bounds;
|
|
336
392
|
if (!bounds) {
|
|
337
393
|
return;
|
|
338
394
|
}
|
|
@@ -345,8 +401,8 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
345
401
|
}
|
|
346
402
|
if (pos.x < 0) {
|
|
347
403
|
// 日界线左侧点右移
|
|
348
|
-
var
|
|
349
|
-
pos.x =
|
|
404
|
+
var _newPos2 = this.mapsService.lngLatToContainer([lng + 360, lat]);
|
|
405
|
+
pos.x = _newPos2.x;
|
|
350
406
|
}
|
|
351
407
|
}
|
|
352
408
|
// 不在当前可视区域内隐藏点
|
|
@@ -362,9 +418,9 @@ var Marker = /*#__PURE__*/function (_EventEmitter) {
|
|
|
362
418
|
value: function init() {
|
|
363
419
|
var _this5 = this;
|
|
364
420
|
var element = this.markerOption.element;
|
|
365
|
-
var _this$
|
|
366
|
-
color = _this$
|
|
367
|
-
anchor = _this$
|
|
421
|
+
var _this$markerOption4 = this.markerOption,
|
|
422
|
+
color = _this$markerOption4.color,
|
|
423
|
+
anchor = _this$markerOption4.anchor;
|
|
368
424
|
if (!element) {
|
|
369
425
|
this.defaultMarker = true;
|
|
370
426
|
element = DOM.create('div');
|
package/es/popup/layerPopup.js
CHANGED
|
@@ -112,9 +112,10 @@ var LayerPopup = /*#__PURE__*/function (_Popup) {
|
|
|
112
112
|
var items = newOption.items || this.popupOption.items;
|
|
113
113
|
var isEmptyItems = (items === null || items === void 0 ? void 0 : items.length) === 0;
|
|
114
114
|
newOption.followCursor = trigger === 'hover' && !isEmptyItems;
|
|
115
|
+
var isShow = this.isShow;
|
|
115
116
|
_get(_getPrototypeOf(LayerPopup.prototype), "setOptions", this).call(this, newOption);
|
|
116
117
|
this.bindLayerEvent();
|
|
117
|
-
if (isEmptyItems) {
|
|
118
|
+
if (isEmptyItems || !isShow) {
|
|
118
119
|
this.hide();
|
|
119
120
|
}
|
|
120
121
|
return this;
|
package/es/popup/popup.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
|
|
|
101
101
|
* @protected
|
|
102
102
|
*/
|
|
103
103
|
protected updateLngLatPosition: () => void;
|
|
104
|
+
protected updateLngLatPositionWhenZoom: (ev: any) => void;
|
|
104
105
|
protected getDefault(option: Partial<O>): O;
|
|
105
106
|
/**
|
|
106
107
|
* 设置 Popup 内容 HTML
|
|
@@ -121,14 +122,17 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
|
|
|
121
122
|
*/
|
|
122
123
|
protected createContent(): void;
|
|
123
124
|
protected onCloseButtonClick: (e: Event) => void;
|
|
125
|
+
private updatePosition;
|
|
126
|
+
protected updateWhenZoom: (ev: any) => void;
|
|
124
127
|
protected update: () => void;
|
|
125
128
|
/**
|
|
126
129
|
* 设置 Popup 相对于地图容器的 Position
|
|
127
|
-
* @param left
|
|
128
|
-
* @param top
|
|
130
|
+
* @param {Number} left
|
|
131
|
+
* @param {Number} top
|
|
132
|
+
* @param {Boolean} [useTransition=false] 是否使用过度效果
|
|
129
133
|
* @protected
|
|
130
134
|
*/
|
|
131
|
-
protected setPopupPosition(left: number, top: number): void;
|
|
135
|
+
protected setPopupPosition(left: number, top: number, useTransition?: boolean): void;
|
|
132
136
|
/**
|
|
133
137
|
* 检查当前传入 option 是否包含 keys 字段
|
|
134
138
|
* @param option
|
package/es/popup/popup.js
CHANGED
|
@@ -79,6 +79,28 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
79
79
|
y = _this$mapsService$lng.y;
|
|
80
80
|
_this.setPopupPosition(x, y);
|
|
81
81
|
});
|
|
82
|
+
//zoom时计算PopUp的位置并更新
|
|
83
|
+
_defineProperty(_assertThisInitialized(_this), "updateLngLatPositionWhenZoom", function (ev) {
|
|
84
|
+
if (!_this.mapsService || _this.popupOption.followCursor) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
var _this$lngLat2 = _this.lngLat,
|
|
88
|
+
lng = _this$lngLat2.lng,
|
|
89
|
+
lat = _this$lngLat2.lat;
|
|
90
|
+
var _this$mapsService$lng2 = _this.mapsService.lngLatToContainer([lng, lat]),
|
|
91
|
+
x = _this$mapsService$lng2.x,
|
|
92
|
+
y = _this$mapsService$lng2.y;
|
|
93
|
+
var map = ev.map;
|
|
94
|
+
var viewHalf = map.getSize();
|
|
95
|
+
viewHalf.x = viewHalf.x / 2;
|
|
96
|
+
viewHalf.y = viewHalf.y / 2;
|
|
97
|
+
var center = ev.center;
|
|
98
|
+
var zoom = ev.zoom;
|
|
99
|
+
var projectedCenter = map.DE(_this.lngLat, zoom, center);
|
|
100
|
+
projectedCenter.x = Math.round(projectedCenter.x);
|
|
101
|
+
projectedCenter.y = Math.round(projectedCenter.y);
|
|
102
|
+
_this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
|
|
103
|
+
});
|
|
82
104
|
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
|
|
83
105
|
if (e.keyCode === 27) {
|
|
84
106
|
_this.remove();
|
|
@@ -90,7 +112,9 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
90
112
|
}
|
|
91
113
|
_this.hide();
|
|
92
114
|
});
|
|
93
|
-
|
|
115
|
+
//更新位置 支持zoom时更新
|
|
116
|
+
_defineProperty(_assertThisInitialized(_this), "updatePosition", function (ev) {
|
|
117
|
+
var zoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
94
118
|
var hasPosition = !!_this.lngLat;
|
|
95
119
|
var _this$popupOption = _this.popupOption,
|
|
96
120
|
className = _this$popupOption.className,
|
|
@@ -121,7 +145,11 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
121
145
|
}
|
|
122
146
|
_this.container.style.whiteSpace = 'nowrap';
|
|
123
147
|
}
|
|
124
|
-
|
|
148
|
+
if (zoom) {
|
|
149
|
+
_this.updateLngLatPositionWhenZoom(ev);
|
|
150
|
+
} else {
|
|
151
|
+
_this.updateLngLatPosition();
|
|
152
|
+
}
|
|
125
153
|
DOM.setTransform(_this.container, "".concat(anchorTranslate[anchor]));
|
|
126
154
|
applyAnchorClass(_this.container, anchor, 'popup');
|
|
127
155
|
if (maxWidth) {
|
|
@@ -134,6 +162,12 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
134
162
|
_this.container.style.removeProperty('width');
|
|
135
163
|
}
|
|
136
164
|
});
|
|
165
|
+
_defineProperty(_assertThisInitialized(_this), "updateWhenZoom", function (ev) {
|
|
166
|
+
_this.updatePosition(ev, true);
|
|
167
|
+
});
|
|
168
|
+
_defineProperty(_assertThisInitialized(_this), "update", function () {
|
|
169
|
+
_this.updatePosition(null, false);
|
|
170
|
+
});
|
|
137
171
|
_this.popupOption = _objectSpread(_objectSpread({}, _this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
|
|
138
172
|
var lngLat = _this.popupOption.lngLat;
|
|
139
173
|
if (lngLat) {
|
|
@@ -164,6 +198,8 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
164
198
|
this.mapsService = scene.get(TYPES.IMapService);
|
|
165
199
|
this.sceneService = scene.get(TYPES.ISceneService);
|
|
166
200
|
this.layerService = scene.get(TYPES.ILayerService);
|
|
201
|
+
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
|
|
202
|
+
this.mapsService.on('zoomchange', this.updateWhenZoom);
|
|
167
203
|
this.mapsService.on('camerachange', this.update);
|
|
168
204
|
this.mapsService.on('viewchange', this.update);
|
|
169
205
|
this.scene = scene;
|
|
@@ -207,6 +243,8 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
207
243
|
// TODO: mapbox AMap 事件同步
|
|
208
244
|
this.mapsService.off('camerachange', this.update);
|
|
209
245
|
this.mapsService.off('viewchange', this.update);
|
|
246
|
+
//天地图的缩放事件
|
|
247
|
+
this.mapsService.off('zoomchange', this.updateWhenZoom);
|
|
210
248
|
this.updateCloseOnClick(true);
|
|
211
249
|
this.updateCloseOnEsc(true);
|
|
212
250
|
this.updateFollowCursor(true);
|
|
@@ -352,9 +390,9 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
352
390
|
}, {
|
|
353
391
|
key: "panToPopup",
|
|
354
392
|
value: function panToPopup() {
|
|
355
|
-
var _this$
|
|
356
|
-
lng = _this$
|
|
357
|
-
lat = _this$
|
|
393
|
+
var _this$lngLat3 = this.lngLat,
|
|
394
|
+
lng = _this$lngLat3.lng,
|
|
395
|
+
lat = _this$lngLat3.lat;
|
|
358
396
|
if (this.popupOption.autoPan) {
|
|
359
397
|
this.mapsService.panTo([lng, lat]);
|
|
360
398
|
}
|
|
@@ -384,8 +422,10 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
384
422
|
}
|
|
385
423
|
if (this.mapsService) {
|
|
386
424
|
// 防止事件重复监听
|
|
425
|
+
this.mapsService.off('zoonanim', this.updateWhenZoom);
|
|
387
426
|
this.mapsService.off('camerachange', this.update);
|
|
388
427
|
this.mapsService.off('viewchange', this.update);
|
|
428
|
+
this.mapsService.on('zoonanim', this.updateWhenZoom);
|
|
389
429
|
this.mapsService.on('camerachange', this.update);
|
|
390
430
|
this.mapsService.on('viewchange', this.update);
|
|
391
431
|
}
|
|
@@ -544,15 +584,22 @@ var Popup = /*#__PURE__*/function (_EventEmitter) {
|
|
|
544
584
|
value:
|
|
545
585
|
/**
|
|
546
586
|
* 设置 Popup 相对于地图容器的 Position
|
|
547
|
-
* @param left
|
|
548
|
-
* @param top
|
|
587
|
+
* @param {Number} left
|
|
588
|
+
* @param {Number} top
|
|
589
|
+
* @param {Boolean} [useTransition=false] 是否使用过度效果
|
|
549
590
|
* @protected
|
|
550
591
|
*/
|
|
551
592
|
function setPopupPosition(left, top) {
|
|
593
|
+
var useTransition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
552
594
|
if (this.container) {
|
|
553
595
|
var offsets = this.popupOption.offsets;
|
|
554
596
|
this.container.style.left = left + offsets[0] + 'px';
|
|
555
597
|
this.container.style.top = top - offsets[1] + 'px';
|
|
598
|
+
if (useTransition) {
|
|
599
|
+
this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
600
|
+
} else {
|
|
601
|
+
this.container.style.transition = '';
|
|
602
|
+
}
|
|
556
603
|
}
|
|
557
604
|
}
|
|
558
605
|
|
package/lib/marker.js
CHANGED
|
@@ -83,7 +83,7 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
_this.markerOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _this.getDefault()), option);
|
|
86
|
-
(0, _l7Utils.bindAll)(['update', 'onMove', 'onMapClick'], (0, _assertThisInitialized2.default)(_this));
|
|
86
|
+
(0, _l7Utils.bindAll)(['update', 'onMove', 'onMapClick', 'updatePositionWhenZoom'], (0, _assertThisInitialized2.default)(_this));
|
|
87
87
|
_this.init();
|
|
88
88
|
return _this;
|
|
89
89
|
}
|
|
@@ -115,6 +115,8 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
115
115
|
// this.sceneSerive.getSceneContainer().appendChild(element as HTMLElement);
|
|
116
116
|
this.mapsService.getMarkerContainer().appendChild(element);
|
|
117
117
|
this.registerMarkerEvent(element);
|
|
118
|
+
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
|
|
119
|
+
this.mapsService.on('zoomchange', this.updatePositionWhenZoom);
|
|
118
120
|
this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
|
|
119
121
|
this.update();
|
|
120
122
|
this.updateDraggable();
|
|
@@ -129,6 +131,7 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
129
131
|
this.mapsService.off('click', this.onMapClick);
|
|
130
132
|
this.mapsService.off('move', this.update);
|
|
131
133
|
this.mapsService.off('moveend', this.update);
|
|
134
|
+
this.mapsService.off('zoomchange', this.update);
|
|
132
135
|
this.mapsService.off('camerachange', this.update);
|
|
133
136
|
}
|
|
134
137
|
this.unRegisterMarkerEvent();
|
|
@@ -289,7 +292,60 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
289
292
|
this.updatePosition();
|
|
290
293
|
_l7Utils.DOM.setTransform(element, "".concat(_l7Utils.anchorTranslate[anchor]));
|
|
291
294
|
}
|
|
292
|
-
|
|
295
|
+
//天地图在开始缩放时触发 更新目标位置时添加过渡效果
|
|
296
|
+
}, {
|
|
297
|
+
key: "updatePositionWhenZoom",
|
|
298
|
+
value: function updatePositionWhenZoom(ev) {
|
|
299
|
+
if (!this.mapsService) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var _this$markerOption2 = this.markerOption,
|
|
303
|
+
element = _this$markerOption2.element,
|
|
304
|
+
offsets = _this$markerOption2.offsets;
|
|
305
|
+
var _this$lngLat = this.lngLat,
|
|
306
|
+
lng = _this$lngLat.lng,
|
|
307
|
+
lat = _this$lngLat.lat;
|
|
308
|
+
if (element) {
|
|
309
|
+
element.style.display = 'block';
|
|
310
|
+
element.style.whiteSpace = 'nowrap';
|
|
311
|
+
var _ref2 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
|
|
312
|
+
containerHeight = _ref2.containerHeight,
|
|
313
|
+
containerWidth = _ref2.containerWidth,
|
|
314
|
+
bounds = _ref2.bounds;
|
|
315
|
+
if (!bounds) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
var map = ev.map;
|
|
319
|
+
var viewHalf = map.getSize();
|
|
320
|
+
viewHalf.x = viewHalf.x / 2;
|
|
321
|
+
viewHalf.y = viewHalf.y / 2;
|
|
322
|
+
var center = ev.center;
|
|
323
|
+
var zoom = ev.zoom;
|
|
324
|
+
var projectedCenter = map.DE(this.lngLat, zoom, center);
|
|
325
|
+
projectedCenter.x = Math.round(projectedCenter.x + offsets[0]);
|
|
326
|
+
projectedCenter.y = Math.round(projectedCenter.y - offsets[1]);
|
|
327
|
+
// 当前可视区域包含跨日界线
|
|
328
|
+
if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
|
|
329
|
+
if (projectedCenter.x > containerWidth) {
|
|
330
|
+
// 日界线右侧点左移
|
|
331
|
+
var newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
|
|
332
|
+
projectedCenter.x = newPos.x;
|
|
333
|
+
}
|
|
334
|
+
if (projectedCenter.x < 0) {
|
|
335
|
+
// 日界线左侧点右移
|
|
336
|
+
var _newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
|
|
337
|
+
projectedCenter.x = _newPos.x;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (projectedCenter.x > containerWidth || projectedCenter.x < 0 || projectedCenter.y > containerHeight || projectedCenter.y < 0) {
|
|
341
|
+
element.style.display = 'none';
|
|
342
|
+
}
|
|
343
|
+
element.style.left = projectedCenter.x + 'px';
|
|
344
|
+
element.style.top = projectedCenter.y + 'px';
|
|
345
|
+
console.log(projectedCenter);
|
|
346
|
+
element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
347
|
+
}
|
|
348
|
+
}
|
|
293
349
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
294
350
|
}, {
|
|
295
351
|
key: "onMapClick",
|
|
@@ -326,20 +382,20 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
326
382
|
if (!this.mapsService) {
|
|
327
383
|
return;
|
|
328
384
|
}
|
|
329
|
-
var _this$
|
|
330
|
-
element = _this$
|
|
331
|
-
offsets = _this$
|
|
332
|
-
var _this$
|
|
333
|
-
lng = _this$
|
|
334
|
-
lat = _this$
|
|
385
|
+
var _this$markerOption3 = this.markerOption,
|
|
386
|
+
element = _this$markerOption3.element,
|
|
387
|
+
offsets = _this$markerOption3.offsets;
|
|
388
|
+
var _this$lngLat2 = this.lngLat,
|
|
389
|
+
lng = _this$lngLat2.lng,
|
|
390
|
+
lat = _this$lngLat2.lat;
|
|
335
391
|
var pos = this.mapsService.lngLatToContainer([lng, lat]);
|
|
336
392
|
if (element) {
|
|
337
393
|
element.style.display = 'block';
|
|
338
394
|
element.style.whiteSpace = 'nowrap';
|
|
339
|
-
var
|
|
340
|
-
containerHeight =
|
|
341
|
-
containerWidth =
|
|
342
|
-
bounds =
|
|
395
|
+
var _ref3 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
|
|
396
|
+
containerHeight = _ref3.containerHeight,
|
|
397
|
+
containerWidth = _ref3.containerWidth,
|
|
398
|
+
bounds = _ref3.bounds;
|
|
343
399
|
if (!bounds) {
|
|
344
400
|
return;
|
|
345
401
|
}
|
|
@@ -352,8 +408,8 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
352
408
|
}
|
|
353
409
|
if (pos.x < 0) {
|
|
354
410
|
// 日界线左侧点右移
|
|
355
|
-
var
|
|
356
|
-
pos.x =
|
|
411
|
+
var _newPos2 = this.mapsService.lngLatToContainer([lng + 360, lat]);
|
|
412
|
+
pos.x = _newPos2.x;
|
|
357
413
|
}
|
|
358
414
|
}
|
|
359
415
|
// 不在当前可视区域内隐藏点
|
|
@@ -369,9 +425,9 @@ var Marker = exports.default = /*#__PURE__*/function (_EventEmitter) {
|
|
|
369
425
|
value: function init() {
|
|
370
426
|
var _this5 = this;
|
|
371
427
|
var element = this.markerOption.element;
|
|
372
|
-
var _this$
|
|
373
|
-
color = _this$
|
|
374
|
-
anchor = _this$
|
|
428
|
+
var _this$markerOption4 = this.markerOption,
|
|
429
|
+
color = _this$markerOption4.color,
|
|
430
|
+
anchor = _this$markerOption4.anchor;
|
|
375
431
|
if (!element) {
|
|
376
432
|
this.defaultMarker = true;
|
|
377
433
|
element = _l7Utils.DOM.create('div');
|
package/lib/popup/layerPopup.js
CHANGED
|
@@ -118,9 +118,10 @@ var LayerPopup = exports.default = exports.LayerPopup = /*#__PURE__*/function (_
|
|
|
118
118
|
var items = newOption.items || this.popupOption.items;
|
|
119
119
|
var isEmptyItems = (items === null || items === void 0 ? void 0 : items.length) === 0;
|
|
120
120
|
newOption.followCursor = trigger === 'hover' && !isEmptyItems;
|
|
121
|
+
var isShow = this.isShow;
|
|
121
122
|
(0, _get2.default)((0, _getPrototypeOf2.default)(LayerPopup.prototype), "setOptions", this).call(this, newOption);
|
|
122
123
|
this.bindLayerEvent();
|
|
123
|
-
if (isEmptyItems) {
|
|
124
|
+
if (isEmptyItems || !isShow) {
|
|
124
125
|
this.hide();
|
|
125
126
|
}
|
|
126
127
|
return this;
|
package/lib/popup/popup.js
CHANGED
|
@@ -85,6 +85,28 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
85
85
|
y = _this$mapsService$lng.y;
|
|
86
86
|
_this.setPopupPosition(x, y);
|
|
87
87
|
});
|
|
88
|
+
//zoom时计算PopUp的位置并更新
|
|
89
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateLngLatPositionWhenZoom", function (ev) {
|
|
90
|
+
if (!_this.mapsService || _this.popupOption.followCursor) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
var _this$lngLat2 = _this.lngLat,
|
|
94
|
+
lng = _this$lngLat2.lng,
|
|
95
|
+
lat = _this$lngLat2.lat;
|
|
96
|
+
var _this$mapsService$lng2 = _this.mapsService.lngLatToContainer([lng, lat]),
|
|
97
|
+
x = _this$mapsService$lng2.x,
|
|
98
|
+
y = _this$mapsService$lng2.y;
|
|
99
|
+
var map = ev.map;
|
|
100
|
+
var viewHalf = map.getSize();
|
|
101
|
+
viewHalf.x = viewHalf.x / 2;
|
|
102
|
+
viewHalf.y = viewHalf.y / 2;
|
|
103
|
+
var center = ev.center;
|
|
104
|
+
var zoom = ev.zoom;
|
|
105
|
+
var projectedCenter = map.DE(_this.lngLat, zoom, center);
|
|
106
|
+
projectedCenter.x = Math.round(projectedCenter.x);
|
|
107
|
+
projectedCenter.y = Math.round(projectedCenter.y);
|
|
108
|
+
_this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
|
|
109
|
+
});
|
|
88
110
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (e) {
|
|
89
111
|
if (e.keyCode === 27) {
|
|
90
112
|
_this.remove();
|
|
@@ -96,7 +118,9 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
96
118
|
}
|
|
97
119
|
_this.hide();
|
|
98
120
|
});
|
|
99
|
-
|
|
121
|
+
//更新位置 支持zoom时更新
|
|
122
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updatePosition", function (ev) {
|
|
123
|
+
var zoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
100
124
|
var hasPosition = !!_this.lngLat;
|
|
101
125
|
var _this$popupOption = _this.popupOption,
|
|
102
126
|
className = _this$popupOption.className,
|
|
@@ -127,7 +151,11 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
127
151
|
}
|
|
128
152
|
_this.container.style.whiteSpace = 'nowrap';
|
|
129
153
|
}
|
|
130
|
-
|
|
154
|
+
if (zoom) {
|
|
155
|
+
_this.updateLngLatPositionWhenZoom(ev);
|
|
156
|
+
} else {
|
|
157
|
+
_this.updateLngLatPosition();
|
|
158
|
+
}
|
|
131
159
|
_l7Utils.DOM.setTransform(_this.container, "".concat(_l7Utils.anchorTranslate[anchor]));
|
|
132
160
|
(0, _l7Utils.applyAnchorClass)(_this.container, anchor, 'popup');
|
|
133
161
|
if (maxWidth) {
|
|
@@ -140,6 +168,12 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
140
168
|
_this.container.style.removeProperty('width');
|
|
141
169
|
}
|
|
142
170
|
});
|
|
171
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateWhenZoom", function (ev) {
|
|
172
|
+
_this.updatePosition(ev, true);
|
|
173
|
+
});
|
|
174
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "update", function () {
|
|
175
|
+
_this.updatePosition(null, false);
|
|
176
|
+
});
|
|
143
177
|
_this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
|
|
144
178
|
var lngLat = _this.popupOption.lngLat;
|
|
145
179
|
if (lngLat) {
|
|
@@ -170,6 +204,8 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
170
204
|
this.mapsService = scene.get(_l7Core.TYPES.IMapService);
|
|
171
205
|
this.sceneService = scene.get(_l7Core.TYPES.ISceneService);
|
|
172
206
|
this.layerService = scene.get(_l7Core.TYPES.ILayerService);
|
|
207
|
+
//天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
|
|
208
|
+
this.mapsService.on('zoomchange', this.updateWhenZoom);
|
|
173
209
|
this.mapsService.on('camerachange', this.update);
|
|
174
210
|
this.mapsService.on('viewchange', this.update);
|
|
175
211
|
this.scene = scene;
|
|
@@ -213,6 +249,8 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
213
249
|
// TODO: mapbox AMap 事件同步
|
|
214
250
|
this.mapsService.off('camerachange', this.update);
|
|
215
251
|
this.mapsService.off('viewchange', this.update);
|
|
252
|
+
//天地图的缩放事件
|
|
253
|
+
this.mapsService.off('zoomchange', this.updateWhenZoom);
|
|
216
254
|
this.updateCloseOnClick(true);
|
|
217
255
|
this.updateCloseOnEsc(true);
|
|
218
256
|
this.updateFollowCursor(true);
|
|
@@ -358,9 +396,9 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
358
396
|
}, {
|
|
359
397
|
key: "panToPopup",
|
|
360
398
|
value: function panToPopup() {
|
|
361
|
-
var _this$
|
|
362
|
-
lng = _this$
|
|
363
|
-
lat = _this$
|
|
399
|
+
var _this$lngLat3 = this.lngLat,
|
|
400
|
+
lng = _this$lngLat3.lng,
|
|
401
|
+
lat = _this$lngLat3.lat;
|
|
364
402
|
if (this.popupOption.autoPan) {
|
|
365
403
|
this.mapsService.panTo([lng, lat]);
|
|
366
404
|
}
|
|
@@ -390,8 +428,10 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
390
428
|
}
|
|
391
429
|
if (this.mapsService) {
|
|
392
430
|
// 防止事件重复监听
|
|
431
|
+
this.mapsService.off('zoonanim', this.updateWhenZoom);
|
|
393
432
|
this.mapsService.off('camerachange', this.update);
|
|
394
433
|
this.mapsService.off('viewchange', this.update);
|
|
434
|
+
this.mapsService.on('zoonanim', this.updateWhenZoom);
|
|
395
435
|
this.mapsService.on('camerachange', this.update);
|
|
396
436
|
this.mapsService.on('viewchange', this.update);
|
|
397
437
|
}
|
|
@@ -550,15 +590,22 @@ var Popup = exports.default = exports.Popup = /*#__PURE__*/function (_EventEmitt
|
|
|
550
590
|
value:
|
|
551
591
|
/**
|
|
552
592
|
* 设置 Popup 相对于地图容器的 Position
|
|
553
|
-
* @param left
|
|
554
|
-
* @param top
|
|
593
|
+
* @param {Number} left
|
|
594
|
+
* @param {Number} top
|
|
595
|
+
* @param {Boolean} [useTransition=false] 是否使用过度效果
|
|
555
596
|
* @protected
|
|
556
597
|
*/
|
|
557
598
|
function setPopupPosition(left, top) {
|
|
599
|
+
var useTransition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
558
600
|
if (this.container) {
|
|
559
601
|
var offsets = this.popupOption.offsets;
|
|
560
602
|
this.container.style.left = left + offsets[0] + 'px';
|
|
561
603
|
this.container.style.top = top - offsets[1] + 'px';
|
|
604
|
+
if (useTransition) {
|
|
605
|
+
this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
606
|
+
} else {
|
|
607
|
+
this.container.style.transition = '';
|
|
608
|
+
}
|
|
562
609
|
}
|
|
563
610
|
}
|
|
564
611
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/l7-component",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"author": "lzxue",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@antv/l7-core": "2.20.
|
|
30
|
-
"@antv/l7-utils": "2.20.
|
|
29
|
+
"@antv/l7-core": "2.20.17",
|
|
30
|
+
"@antv/l7-utils": "2.20.17",
|
|
31
31
|
"@babel/runtime": "^7.7.7",
|
|
32
32
|
"eventemitter3": "^4.0.0",
|
|
33
33
|
"inversify": "^5.0.1",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"supercluster": "^7.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@antv/l7-layers": "2.20.
|
|
39
|
-
"@antv/l7-test-utils": "2.20.
|
|
38
|
+
"@antv/l7-layers": "2.20.17",
|
|
39
|
+
"@antv/l7-test-utils": "2.20.17",
|
|
40
40
|
"gcoord": "^0.3.2",
|
|
41
41
|
"less": "^4.1.3"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "e37d5cc24eec17a0949b827d76d1ac7c97a8fef3",
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
}
|