@antv/l7-component 2.21.1 → 2.21.2

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.
Files changed (82) hide show
  1. package/es/assets/iconfont/iconfont.js +6 -6
  2. package/es/constants/index.js +2 -2
  3. package/es/control/baseControl/buttonControl.js +109 -144
  4. package/es/control/baseControl/control.js +212 -258
  5. package/es/control/baseControl/popperControl.js +67 -95
  6. package/es/control/baseControl/selectControl.js +132 -178
  7. package/es/control/exportImage.js +59 -142
  8. package/es/control/fullscreen.js +69 -100
  9. package/es/control/geoLocate.js +37 -84
  10. package/es/control/layerSwitch.js +111 -154
  11. package/es/control/logo.js +43 -69
  12. package/es/control/mapTheme.js +57 -98
  13. package/es/control/mouseLocation.js +37 -69
  14. package/es/control/scale.js +107 -135
  15. package/es/control/swipe.js +297 -389
  16. package/es/control/zoom.js +80 -112
  17. package/es/css/index.css +10 -7
  18. package/es/index.js +667 -1
  19. package/es/marker-layer.js +275 -326
  20. package/es/marker.js +394 -446
  21. package/es/popup/layerPopup.js +277 -321
  22. package/es/popup/popup.js +422 -482
  23. package/es/utils/anchor.js +6 -6
  24. package/es/utils/icon.js +4 -4
  25. package/es/utils/popper.js +180 -196
  26. package/es/utils/screenfull.js +29 -51
  27. package/lib/assets/iconfont/iconfont.js +6 -6
  28. package/lib/constants/index.d.ts +60 -0
  29. package/lib/constants/index.js +2 -2
  30. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  31. package/lib/control/baseControl/buttonControl.js +110 -143
  32. package/lib/control/baseControl/control.d.ts +112 -0
  33. package/lib/control/baseControl/control.js +213 -257
  34. package/lib/control/baseControl/index.d.ts +4 -0
  35. package/lib/control/baseControl/index.js +5 -5
  36. package/lib/control/baseControl/popperControl.d.ts +28 -0
  37. package/lib/control/baseControl/popperControl.js +68 -94
  38. package/lib/control/baseControl/selectControl.d.ts +53 -0
  39. package/lib/control/baseControl/selectControl.js +133 -177
  40. package/lib/control/exportImage.d.ts +19 -0
  41. package/lib/control/exportImage.js +60 -141
  42. package/lib/control/fullscreen.d.ts +20 -0
  43. package/lib/control/fullscreen.js +70 -99
  44. package/lib/control/geoLocate.d.ts +17 -0
  45. package/lib/control/geoLocate.js +38 -83
  46. package/lib/control/layerSwitch.d.ts +27 -0
  47. package/lib/control/layerSwitch.js +112 -153
  48. package/lib/control/logo.d.ts +14 -0
  49. package/lib/control/logo.js +44 -69
  50. package/lib/control/mapTheme.d.ts +11 -0
  51. package/lib/control/mapTheme.js +58 -97
  52. package/lib/control/mouseLocation.d.ts +16 -0
  53. package/lib/control/mouseLocation.js +38 -68
  54. package/lib/control/scale.d.ts +35 -0
  55. package/lib/control/scale.js +108 -134
  56. package/lib/control/swipe.d.ts +66 -0
  57. package/lib/control/swipe.js +298 -388
  58. package/lib/control/zoom.d.ts +39 -0
  59. package/lib/control/zoom.js +81 -111
  60. package/lib/css/index.css +10 -7
  61. package/lib/index.d.ts +19 -0
  62. package/lib/index.js +683 -17
  63. package/lib/interface.d.ts +18 -0
  64. package/lib/marker-layer.d.ts +55 -0
  65. package/lib/marker-layer.js +277 -324
  66. package/lib/marker.d.ts +58 -0
  67. package/lib/marker.js +395 -445
  68. package/lib/popup/layerPopup.d.ts +99 -0
  69. package/lib/popup/layerPopup.js +278 -320
  70. package/lib/popup/popup.d.ts +142 -0
  71. package/lib/popup/popup.js +423 -481
  72. package/lib/utils/anchor.d.ts +22 -0
  73. package/lib/utils/anchor.js +6 -6
  74. package/lib/utils/icon.d.ts +1 -0
  75. package/lib/utils/icon.js +6 -5
  76. package/lib/utils/popper.d.ts +76 -0
  77. package/lib/utils/popper.js +184 -196
  78. package/lib/utils/screenfull.d.ts +2 -0
  79. package/lib/utils/screenfull.js +29 -52
  80. package/package.json +16 -20
  81. package/CHANGELOG.md +0 -325
  82. package/LICENSE.md +0 -21
package/es/marker.js CHANGED
@@ -1,514 +1,462 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/esm/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
8
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
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
- 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
3
  import { DOM, anchorTranslate, anchorType, applyAnchorClass, bindAll, isPC } from '@antv/l7-utils';
12
4
  import { EventEmitter } from 'eventemitter3';
13
5
 
14
6
  // marker 支持 dragger 未完成
15
- var Marker = /*#__PURE__*/function (_EventEmitter) {
16
- _inherits(Marker, _EventEmitter);
17
- var _super = _createSuper(Marker);
18
- function Marker(option) {
19
- var _this;
20
- _classCallCheck(this, Marker);
21
- _this = _super.call(this);
22
- _defineProperty(_assertThisInitialized(_this), "added", false);
23
- _defineProperty(_assertThisInitialized(_this), "preLngLat", {
7
+ export default class Marker extends EventEmitter {
8
+ // tslint:disable-next-line: no-empty
9
+ getMarkerLayerContainerSize() {}
10
+ constructor(option) {
11
+ super();
12
+ _defineProperty(this, "markerOption", void 0);
13
+ _defineProperty(this, "popup", void 0);
14
+ _defineProperty(this, "mapsService", void 0);
15
+ _defineProperty(this, "lngLat", void 0);
16
+ _defineProperty(this, "scene", void 0);
17
+ _defineProperty(this, "added", false);
18
+ _defineProperty(this, "preLngLat", {
24
19
  lng: 0,
25
20
  lat: 0
26
21
  });
27
- _defineProperty(_assertThisInitialized(_this), "onMarkerDragStart", function (e) {
28
- var mapContainer = _this.mapsService.getContainer();
22
+ _defineProperty(this, "onMarkerDragStart", e => {
23
+ const mapContainer = this.mapsService.getContainer();
29
24
  if (!mapContainer) {
30
25
  return;
31
26
  }
32
- _this.mapsService.setMapStatus({
27
+ this.mapsService.setMapStatus({
33
28
  dragEnable: false,
34
29
  zoomEnable: false
35
30
  });
36
- var _ref = mapContainer.getClientRects()[0],
37
- containerX = _ref.left,
38
- containerY = _ref.top;
39
- var clickX = e.x,
40
- clickY = e.y;
41
- _this.preLngLat = _this.mapsService.containerToLngLat([clickX - containerX, clickY - containerY]);
42
- _this.mapsService.on('mousemove', _this.onMarkerDragMove);
43
- document.addEventListener('mouseup', _this.onMarkerDragEnd);
44
- _this.emit('dragstart', _this.lngLat);
31
+ const {
32
+ left: containerX,
33
+ top: containerY
34
+ } = mapContainer.getClientRects()[0];
35
+ const {
36
+ x: clickX,
37
+ y: clickY
38
+ } = e;
39
+ this.preLngLat = this.mapsService.containerToLngLat([clickX - containerX, clickY - containerY]);
40
+ this.mapsService.on('mousemove', this.onMarkerDragMove);
41
+ document.addEventListener('mouseup', this.onMarkerDragEnd);
42
+ this.emit('dragstart', this.lngLat);
45
43
  });
46
- _defineProperty(_assertThisInitialized(_this), "onMarkerDragMove", function (e) {
47
- var _this$preLngLat = _this.preLngLat,
48
- preLng = _this$preLngLat.lng,
49
- preLat = _this$preLngLat.lat;
50
- var _e$lnglat = e.lnglat,
51
- curLng = _e$lnglat.lng,
52
- curLat = _e$lnglat.lat;
53
- var newLngLat = {
54
- lng: _this.lngLat.lng + curLng - preLng,
55
- lat: _this.lngLat.lat + curLat - preLat
44
+ _defineProperty(this, "onMarkerDragMove", e => {
45
+ const {
46
+ lng: preLng,
47
+ lat: preLat
48
+ } = this.preLngLat;
49
+ const {
50
+ lng: curLng,
51
+ lat: curLat
52
+ } = e.lnglat;
53
+ const newLngLat = {
54
+ lng: this.lngLat.lng + curLng - preLng,
55
+ lat: this.lngLat.lat + curLat - preLat
56
56
  };
57
- _this.setLnglat(newLngLat);
58
- _this.preLngLat = e.lnglat;
59
- _this.emit('dragging', newLngLat);
57
+ this.setLnglat(newLngLat);
58
+ this.preLngLat = e.lnglat;
59
+ this.emit('dragging', newLngLat);
60
60
  });
61
- _defineProperty(_assertThisInitialized(_this), "onMarkerDragEnd", function () {
62
- _this.mapsService.setMapStatus({
61
+ _defineProperty(this, "onMarkerDragEnd", () => {
62
+ this.mapsService.setMapStatus({
63
63
  dragEnable: true,
64
64
  zoomEnable: true
65
65
  });
66
- _this.mapsService.off('mousemove', _this.onMarkerDragMove);
67
- document.removeEventListener('mouseup', _this.onMarkerDragEnd);
68
- _this.emit('dragend', _this.lngLat);
66
+ this.mapsService.off('mousemove', this.onMarkerDragMove);
67
+ document.removeEventListener('mouseup', this.onMarkerDragEnd);
68
+ this.emit('dragend', this.lngLat);
69
69
  });
70
- _defineProperty(_assertThisInitialized(_this), "eventHandle", function (e) {
71
- _this.polyfillEvent(e);
72
- _this.emit(e.type, {
70
+ _defineProperty(this, "eventHandle", e => {
71
+ this.polyfillEvent(e);
72
+ this.emit(e.type, {
73
73
  target: e,
74
- data: _this.markerOption.extData,
75
- lngLat: _this.lngLat
74
+ data: this.markerOption.extData,
75
+ lngLat: this.lngLat
76
76
  });
77
77
  });
78
- _this.markerOption = _objectSpread(_objectSpread({}, _this.getDefault()), option);
79
- bindAll(['update', 'onMove', 'onMapClick', 'updatePositionWhenZoom'], _assertThisInitialized(_this));
80
- _this.init();
81
- return _this;
78
+ /**
79
+ * 高德 2.x 使用了 fastClick.js 避免延迟,导致 IOS 移动端的 click 事件不会正常触发,需要手动触发
80
+ * @param e
81
+ */
82
+ _defineProperty(this, "touchStartTime", void 0);
83
+ this.markerOption = _objectSpread(_objectSpread({}, this.getDefault()), option);
84
+ bindAll(['update', 'onMove', 'onMapClick', 'updatePositionWhenZoom'], this);
85
+ this.init();
82
86
  }
83
- _createClass(Marker, [{
84
- key: "getMarkerLayerContainerSize",
85
- value:
86
- // tslint:disable-next-line: no-empty
87
- function getMarkerLayerContainerSize() {}
88
- }, {
89
- key: "getDefault",
90
- value: function getDefault() {
91
- return {
92
- element: undefined,
93
- // DOM element
94
- anchor: anchorType.BOTTOM,
95
- offsets: [0, 0],
96
- color: '#5B8FF9',
97
- draggable: false
98
- };
99
- }
100
- }, {
101
- key: "addTo",
102
- value: function addTo(scene) {
103
- this.scene = scene;
104
- this.mapsService = scene.mapService;
105
- var element = this.markerOption.element;
106
- this.mapsService.getMarkerContainer().appendChild(element);
107
- this.registerMarkerEvent(element);
108
- this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
109
- this.update();
110
- this.updateDraggable();
111
- this.added = true;
112
- this.emit('added');
113
- return this;
114
- }
115
- }, {
116
- key: "remove",
117
- value: function remove() {
118
- if (this.mapsService) {
119
- this.mapsService.off('click', this.onMapClick);
120
- this.mapsService.off('move', this.update);
121
- this.mapsService.off('moveend', this.update);
122
- this.mapsService.off('camerachange', this.update);
123
- }
124
- this.unRegisterMarkerEvent();
125
- this.removeAllListeners();
126
- var element = this.markerOption.element;
127
- if (element) {
128
- DOM.remove(element);
129
- }
130
- if (this.popup) {
131
- this.popup.remove();
132
- }
133
- return this;
87
+ getDefault() {
88
+ return {
89
+ element: undefined,
90
+ // DOM element
91
+ anchor: anchorType.BOTTOM,
92
+ offsets: [0, 0],
93
+ color: '#5B8FF9',
94
+ draggable: false
95
+ };
96
+ }
97
+ addTo(scene) {
98
+ this.scene = scene;
99
+ this.mapsService = scene.mapService;
100
+ const {
101
+ element
102
+ } = this.markerOption;
103
+ this.mapsService.getMarkerContainer().appendChild(element);
104
+ this.registerMarkerEvent(element);
105
+ this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
106
+ this.update();
107
+ this.updateDraggable();
108
+ this.added = true;
109
+ this.emit('added');
110
+ return this;
111
+ }
112
+ remove() {
113
+ if (this.mapsService) {
114
+ this.mapsService.off('click', this.onMapClick);
115
+ this.mapsService.off('move', this.update);
116
+ this.mapsService.off('moveend', this.update);
117
+ this.mapsService.off('camerachange', this.update);
134
118
  }
135
- }, {
136
- key: "setLnglat",
137
- value: function setLnglat(lngLat) {
138
- this.lngLat = lngLat;
139
- if (Array.isArray(lngLat)) {
140
- this.lngLat = {
141
- lng: lngLat[0],
142
- lat: lngLat[1]
143
- };
144
- }
145
- if (this.popup) {
146
- this.popup.setLnglat(this.lngLat);
147
- }
148
- this.update();
149
- return this;
119
+ this.unRegisterMarkerEvent();
120
+ this.removeAllListeners();
121
+ const {
122
+ element
123
+ } = this.markerOption;
124
+ if (element) {
125
+ DOM.remove(element);
150
126
  }
151
- }, {
152
- key: "getLnglat",
153
- value: function getLnglat() {
154
- return this.lngLat;
127
+ if (this.popup) {
128
+ this.popup.remove();
155
129
  }
156
- }, {
157
- key: "getElement",
158
- value: function getElement() {
159
- return this.markerOption.element;
130
+ return this;
131
+ }
132
+ setLnglat(lngLat) {
133
+ this.lngLat = lngLat;
134
+ if (Array.isArray(lngLat)) {
135
+ this.lngLat = {
136
+ lng: lngLat[0],
137
+ lat: lngLat[1]
138
+ };
160
139
  }
161
- }, {
162
- key: "setElement",
163
- value: function setElement(el) {
164
- var _this2 = this;
165
- if (!this.added) {
166
- this.once('added', function () {
167
- _this2.setElement(el);
168
- });
169
- return this;
170
- }
171
- var element = this.markerOption.element;
172
- if (element) {
173
- DOM.remove(element);
174
- }
175
- this.markerOption.element = el;
176
- this.init();
177
- this.mapsService.getMarkerContainer().appendChild(el);
178
- this.registerMarkerEvent(el);
179
- this.updateDraggable();
180
- this.update();
181
- return this;
140
+ if (this.popup) {
141
+ this.popup.setLnglat(this.lngLat);
182
142
  }
183
- }, {
184
- key: "openPopup",
185
- value: function openPopup() {
186
- var _this3 = this;
187
- if (!this.added) {
188
- this.once('added', function () {
189
- _this3.openPopup();
190
- });
191
- return this;
192
- }
193
- var popup = this.popup;
194
- if (!popup) {
195
- return this;
196
- }
197
- if (!popup.isOpen()) {
198
- popup.addTo(this.scene);
199
- }
143
+ this.update();
144
+ return this;
145
+ }
146
+ getLnglat() {
147
+ return this.lngLat;
148
+ }
149
+ getElement() {
150
+ return this.markerOption.element;
151
+ }
152
+ setElement(el) {
153
+ if (!this.added) {
154
+ this.once('added', () => {
155
+ this.setElement(el);
156
+ });
200
157
  return this;
201
158
  }
202
- }, {
203
- key: "closePopup",
204
- value: function closePopup() {
205
- var _this4 = this;
206
- if (!this.added) {
207
- this.once('added', function () {
208
- _this4.closePopup();
209
- });
210
- }
211
- var popup = this.popup;
212
- if (popup) {
213
- popup.remove();
214
- }
215
- return this;
159
+ const {
160
+ element
161
+ } = this.markerOption;
162
+ if (element) {
163
+ DOM.remove(element);
216
164
  }
217
- }, {
218
- key: "setPopup",
219
- value: function setPopup(popup) {
220
- this.popup = popup;
221
- if (this.lngLat) {
222
- this.popup.setLnglat(this.lngLat);
223
- }
165
+ this.markerOption.element = el;
166
+ this.init();
167
+ this.mapsService.getMarkerContainer().appendChild(el);
168
+ this.registerMarkerEvent(el);
169
+ this.updateDraggable();
170
+ this.update();
171
+ return this;
172
+ }
173
+ openPopup() {
174
+ if (!this.added) {
175
+ this.once('added', () => {
176
+ this.openPopup();
177
+ });
224
178
  return this;
225
179
  }
226
- }, {
227
- key: "togglePopup",
228
- value: function togglePopup() {
229
- var popup = this.popup;
230
- if (!popup) {
231
- return this;
232
- } else if (popup.isOpen()) {
233
- popup.remove();
234
- } else {
235
- popup.addTo(this.scene);
236
- }
180
+ const popup = this.popup;
181
+ if (!popup) {
237
182
  return this;
238
183
  }
239
- }, {
240
- key: "getPopup",
241
- value: function getPopup() {
242
- return this.popup;
184
+ if (!popup.isOpen()) {
185
+ popup.addTo(this.scene);
243
186
  }
244
- }, {
245
- key: "getOffset",
246
- value: function getOffset() {
247
- return this.markerOption.offsets;
187
+ return this;
188
+ }
189
+ closePopup() {
190
+ if (!this.added) {
191
+ this.once('added', () => {
192
+ this.closePopup();
193
+ });
248
194
  }
249
- }, {
250
- key: "setDraggable",
251
- value: function setDraggable(draggable) {
252
- this.markerOption.draggable = draggable;
253
- this.updateDraggable();
195
+ const popup = this.popup;
196
+ if (popup) {
197
+ popup.remove();
254
198
  }
255
- }, {
256
- key: "getDraggable",
257
- value: function getDraggable() {
258
- return this.markerOption.draggable;
199
+ return this;
200
+ }
201
+ setPopup(popup) {
202
+ this.popup = popup;
203
+ if (this.lngLat) {
204
+ this.popup.setLnglat(this.lngLat);
259
205
  }
260
- }, {
261
- key: "getExtData",
262
- value: function getExtData() {
263
- return this.markerOption.extData;
206
+ return this;
207
+ }
208
+ togglePopup() {
209
+ const popup = this.popup;
210
+ if (!popup) {
211
+ return this;
212
+ } else if (popup.isOpen()) {
213
+ popup.remove();
214
+ } else {
215
+ popup.addTo(this.scene);
264
216
  }
265
- }, {
266
- key: "setExtData",
267
- value: function setExtData(data) {
268
- this.markerOption.extData = data;
217
+ return this;
218
+ }
219
+ getPopup() {
220
+ return this.popup;
221
+ }
222
+ getOffset() {
223
+ return this.markerOption.offsets;
224
+ }
225
+ setDraggable(draggable) {
226
+ this.markerOption.draggable = draggable;
227
+ this.updateDraggable();
228
+ }
229
+ getDraggable() {
230
+ return this.markerOption.draggable;
231
+ }
232
+ getExtData() {
233
+ return this.markerOption.extData;
234
+ }
235
+ setExtData(data) {
236
+ this.markerOption.extData = data;
237
+ }
238
+ update() {
239
+ if (!this.mapsService) {
240
+ return;
269
241
  }
270
- }, {
271
- key: "update",
272
- value: function update() {
273
- if (!this.mapsService) {
274
- return;
275
- }
276
- var _this$markerOption = this.markerOption,
277
- element = _this$markerOption.element,
278
- anchor = _this$markerOption.anchor;
279
- this.updatePosition();
280
- DOM.setTransform(element, "".concat(anchorTranslate[anchor]));
242
+ const {
243
+ element,
244
+ anchor
245
+ } = this.markerOption;
246
+ this.updatePosition();
247
+ DOM.setTransform(element, `${anchorTranslate[anchor]}`);
248
+ }
249
+ //天地图在开始缩放时触发 更新目标位置时添加过渡效果
250
+ updatePositionWhenZoom(ev) {
251
+ if (!this.mapsService) {
252
+ return;
281
253
  }
282
- //天地图在开始缩放时触发 更新目标位置时添加过渡效果
283
- }, {
284
- key: "updatePositionWhenZoom",
285
- value: function updatePositionWhenZoom(ev) {
286
- if (!this.mapsService) {
254
+ const {
255
+ element,
256
+ offsets
257
+ } = this.markerOption;
258
+ const {
259
+ lng,
260
+ lat
261
+ } = this.lngLat;
262
+ if (element) {
263
+ element.style.display = 'block';
264
+ element.style.whiteSpace = 'nowrap';
265
+ const {
266
+ containerHeight,
267
+ containerWidth,
268
+ bounds
269
+ } = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize();
270
+ if (!bounds) {
287
271
  return;
288
272
  }
289
- var _this$markerOption2 = this.markerOption,
290
- element = _this$markerOption2.element,
291
- offsets = _this$markerOption2.offsets;
292
- var _this$lngLat = this.lngLat,
293
- lng = _this$lngLat.lng,
294
- lat = _this$lngLat.lat;
295
- if (element) {
296
- element.style.display = 'block';
297
- element.style.whiteSpace = 'nowrap';
298
- var _ref2 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
299
- containerHeight = _ref2.containerHeight,
300
- containerWidth = _ref2.containerWidth,
301
- bounds = _ref2.bounds;
302
- if (!bounds) {
303
- return;
304
- }
305
- var map = ev.map;
306
- var center = ev.center;
307
- var zoom = ev.zoom;
308
- var projectedCenter = map.DE(this.lngLat, zoom, center);
309
- projectedCenter.x = Math.round(projectedCenter.x + offsets[0]);
310
- projectedCenter.y = Math.round(projectedCenter.y - offsets[1]);
311
- // 当前可视区域包含跨日界线
312
- if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
313
- if (projectedCenter.x > containerWidth) {
314
- // 日界线右侧点左移
315
- var newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
316
- projectedCenter.x = newPos.x;
317
- }
318
- if (projectedCenter.x < 0) {
319
- // 日界线左侧点右移
320
- var _newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
321
- projectedCenter.x = _newPos.x;
322
- }
273
+ const map = ev.map;
274
+ const center = ev.center;
275
+ const zoom = ev.zoom;
276
+ const projectedCenter = map.DE(this.lngLat, zoom, center);
277
+ projectedCenter.x = Math.round(projectedCenter.x + offsets[0]);
278
+ projectedCenter.y = Math.round(projectedCenter.y - offsets[1]);
279
+ // 当前可视区域包含跨日界线
280
+ if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
281
+ if (projectedCenter.x > containerWidth) {
282
+ // 日界线右侧点左移
283
+ const newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
284
+ projectedCenter.x = newPos.x;
323
285
  }
324
- if (projectedCenter.x > containerWidth || projectedCenter.x < 0 || projectedCenter.y > containerHeight || projectedCenter.y < 0) {
325
- element.style.display = 'none';
286
+ if (projectedCenter.x < 0) {
287
+ // 日界线左侧点右移
288
+ const newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
289
+ projectedCenter.x = newPos.x;
326
290
  }
327
- element.style.left = projectedCenter.x + 'px';
328
- element.style.top = projectedCenter.y + 'px';
329
- element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
330
291
  }
331
- }
332
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
333
- }, {
334
- key: "onMapClick",
335
- value: function onMapClick(e) {
336
- var element = this.markerOption.element;
337
- if (this.popup && element) {
338
- this.togglePopup();
292
+ if (projectedCenter.x > containerWidth || projectedCenter.x < 0 || projectedCenter.y > containerHeight || projectedCenter.y < 0) {
293
+ element.style.display = 'none';
339
294
  }
295
+ element.style.left = projectedCenter.x + 'px';
296
+ element.style.top = projectedCenter.y + 'px';
297
+ element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
340
298
  }
341
- }, {
342
- key: "getCurrentContainerSize",
343
- value: function getCurrentContainerSize() {
344
- var container = this.mapsService.getContainer();
345
- return {
346
- containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
347
- containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
348
- bounds: this.mapsService.getBounds()
349
- };
299
+ }
300
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
301
+ onMapClick(e) {
302
+ const {
303
+ element
304
+ } = this.markerOption;
305
+ if (this.popup && element) {
306
+ this.togglePopup();
350
307
  }
351
- }, {
352
- key: "updateDraggable",
353
- value: function updateDraggable() {
354
- var element = this.markerOption.element;
355
- element === null || element === void 0 || element.removeEventListener('mousedown', this.onMarkerDragStart);
356
- this.mapsService.off('mousemove', this.onMarkerDragMove);
357
- document.removeEventListener('mouseup', this.onMarkerDragEnd);
358
- if (this.markerOption.draggable) {
359
- element === null || element === void 0 || element.addEventListener('mousedown', this.onMarkerDragStart);
360
- }
308
+ }
309
+ getCurrentContainerSize() {
310
+ const container = this.mapsService.getContainer();
311
+ return {
312
+ containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
313
+ containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
314
+ bounds: this.mapsService.getBounds()
315
+ };
316
+ }
317
+ updateDraggable() {
318
+ const {
319
+ element
320
+ } = this.markerOption;
321
+ element === null || element === void 0 || element.removeEventListener('mousedown', this.onMarkerDragStart);
322
+ this.mapsService.off('mousemove', this.onMarkerDragMove);
323
+ document.removeEventListener('mouseup', this.onMarkerDragEnd);
324
+ if (this.markerOption.draggable) {
325
+ element === null || element === void 0 || element.addEventListener('mousedown', this.onMarkerDragStart);
326
+ }
327
+ }
328
+ updatePosition() {
329
+ if (!this.mapsService) {
330
+ return;
361
331
  }
362
- }, {
363
- key: "updatePosition",
364
- value: function updatePosition() {
365
- if (!this.mapsService) {
332
+ const {
333
+ element,
334
+ offsets
335
+ } = this.markerOption;
336
+ const {
337
+ lng,
338
+ lat
339
+ } = this.lngLat;
340
+ const pos = this.mapsService.lngLatToContainer([lng, lat]);
341
+ if (element) {
342
+ element.style.display = 'block';
343
+ element.style.whiteSpace = 'nowrap';
344
+ const {
345
+ containerHeight,
346
+ containerWidth,
347
+ bounds
348
+ } = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize();
349
+ if (!bounds) {
366
350
  return;
367
351
  }
368
- var _this$markerOption3 = this.markerOption,
369
- element = _this$markerOption3.element,
370
- offsets = _this$markerOption3.offsets;
371
- var _this$lngLat2 = this.lngLat,
372
- lng = _this$lngLat2.lng,
373
- lat = _this$lngLat2.lat;
374
- var pos = this.mapsService.lngLatToContainer([lng, lat]);
375
- if (element) {
376
- element.style.display = 'block';
377
- element.style.whiteSpace = 'nowrap';
378
- var _ref3 = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
379
- containerHeight = _ref3.containerHeight,
380
- containerWidth = _ref3.containerWidth,
381
- bounds = _ref3.bounds;
382
- if (!bounds) {
383
- return;
384
- }
385
- // 当前可视区域包含跨日界线
386
- if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
387
- if (pos.x > containerWidth) {
388
- // 日界线右侧点左移
389
- var newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
390
- pos.x = newPos.x;
391
- }
392
- if (pos.x < 0) {
393
- // 日界线左侧点右移
394
- var _newPos2 = this.mapsService.lngLatToContainer([lng + 360, lat]);
395
- pos.x = _newPos2.x;
396
- }
352
+ // 当前可视区域包含跨日界线
353
+ if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
354
+ if (pos.x > containerWidth) {
355
+ // 日界线右侧点左移
356
+ const newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
357
+ pos.x = newPos.x;
397
358
  }
398
- // 不在当前可视区域内隐藏点
399
- if (pos.x > containerWidth || pos.x < 0 || pos.y > containerHeight || pos.y < 0) {
400
- element.style.display = 'none';
359
+ if (pos.x < 0) {
360
+ // 日界线左侧点右移
361
+ const newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
362
+ pos.x = newPos.x;
401
363
  }
402
- element.style.left = pos.x + offsets[0] + 'px';
403
- element.style.top = pos.y - offsets[1] + 'px';
404
364
  }
405
- }
406
- }, {
407
- key: "init",
408
- value: function init() {
409
- var _this5 = this;
410
- var element = this.markerOption.element;
411
- var _this$markerOption4 = this.markerOption,
412
- color = _this$markerOption4.color,
413
- anchor = _this$markerOption4.anchor;
414
- if (!element) {
415
- element = DOM.create('div');
416
- this.markerOption.element = element;
417
- var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
418
- svg.setAttributeNS(null, 'display', 'block');
419
- svg.setAttributeNS(null, 'height', '48px');
420
- svg.setAttributeNS(null, 'width', '48px');
421
- svg.setAttributeNS(null, 'viewBox', '0 0 1024 1024');
422
- var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
423
- path.setAttributeNS(null, 'd', 'M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z');
424
- path.setAttributeNS(null, 'fill', color);
425
- svg.appendChild(path);
426
- element.appendChild(svg);
365
+ // 不在当前可视区域内隐藏点
366
+ if (pos.x > containerWidth || pos.x < 0 || pos.y > containerHeight || pos.y < 0) {
367
+ element.style.display = 'none';
427
368
  }
428
- DOM.addClass(element, 'l7-marker');
429
- Object.keys(this.markerOption.style || {}).forEach(
430
- // @ts-ignore
431
- function (key) {
432
- var _this5$markerOption, _this5$markerOption2;
433
- var value = ((_this5$markerOption = _this5.markerOption) === null || _this5$markerOption === void 0 ? void 0 : _this5$markerOption.style) && ((_this5$markerOption2 = _this5.markerOption) === null || _this5$markerOption2 === void 0 ? void 0 : _this5$markerOption2.style[key]);
434
- if (element) {
435
- // @ts-ignore
436
- element.style[key] = value;
437
- }
438
- });
439
- applyAnchorClass(element, anchor, 'marker');
369
+ element.style.left = pos.x + offsets[0] + 'px';
370
+ element.style.top = pos.y - offsets[1] + 'px';
440
371
  }
441
- }, {
442
- key: "registerMarkerEvent",
443
- value: function registerMarkerEvent(element) {
444
- element.addEventListener('click', this.onMapClick);
445
- element.addEventListener('mousemove', this.eventHandle);
446
- element.addEventListener('click', this.eventHandle);
447
- element.addEventListener('mousedown', this.eventHandle);
448
- element.addEventListener('mouseup', this.eventHandle);
449
- element.addEventListener('dblclick', this.eventHandle);
450
- element.addEventListener('contextmenu', this.eventHandle);
451
- element.addEventListener('mouseover', this.eventHandle);
452
- element.addEventListener('mouseout', this.eventHandle);
453
- element.addEventListener('touchstart', this.eventHandle);
454
- element.addEventListener('touchend', this.eventHandle);
372
+ }
373
+ init() {
374
+ let {
375
+ element
376
+ } = this.markerOption;
377
+ const {
378
+ color,
379
+ anchor
380
+ } = this.markerOption;
381
+ if (!element) {
382
+ element = DOM.create('div');
383
+ this.markerOption.element = element;
384
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
385
+ svg.setAttributeNS(null, 'display', 'block');
386
+ svg.setAttributeNS(null, 'height', '48px');
387
+ svg.setAttributeNS(null, 'width', '48px');
388
+ svg.setAttributeNS(null, 'viewBox', '0 0 1024 1024');
389
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
390
+ path.setAttributeNS(null, 'd', 'M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z');
391
+ path.setAttributeNS(null, 'fill', color);
392
+ svg.appendChild(path);
393
+ element.appendChild(svg);
455
394
  }
456
- }, {
457
- key: "unRegisterMarkerEvent",
458
- value: function unRegisterMarkerEvent() {
459
- var element = this.getElement();
460
- element.removeEventListener('click', this.onMapClick);
461
- element.removeEventListener('mousemove', this.eventHandle);
462
- element.removeEventListener('click', this.eventHandle);
463
- element.removeEventListener('mousedown', this.eventHandle);
464
- element.removeEventListener('mouseup', this.eventHandle);
465
- element.removeEventListener('dblclick', this.eventHandle);
466
- element.removeEventListener('contextmenu', this.eventHandle);
467
- element.removeEventListener('mouseover', this.eventHandle);
468
- element.removeEventListener('mouseout', this.eventHandle);
469
- element.removeEventListener('touchstart', this.eventHandle);
470
- element.removeEventListener('touchend', this.eventHandle);
395
+ DOM.addClass(element, 'l7-marker');
396
+ Object.keys(this.markerOption.style || {}).forEach(
397
+ // @ts-ignore
398
+ key => {
399
+ var _this$markerOption, _this$markerOption2;
400
+ const value = ((_this$markerOption = this.markerOption) === null || _this$markerOption === void 0 ? void 0 : _this$markerOption.style) && ((_this$markerOption2 = this.markerOption) === null || _this$markerOption2 === void 0 ? void 0 : _this$markerOption2.style[key]);
401
+ if (element) {
402
+ // @ts-ignore
403
+ element.style[key] = value;
404
+ }
405
+ });
406
+ applyAnchorClass(element, anchor, 'marker');
407
+ }
408
+ registerMarkerEvent(element) {
409
+ element.addEventListener('click', this.onMapClick);
410
+ element.addEventListener('mousemove', this.eventHandle);
411
+ element.addEventListener('click', this.eventHandle);
412
+ element.addEventListener('mousedown', this.eventHandle);
413
+ element.addEventListener('mouseup', this.eventHandle);
414
+ element.addEventListener('dblclick', this.eventHandle);
415
+ element.addEventListener('contextmenu', this.eventHandle);
416
+ element.addEventListener('mouseover', this.eventHandle);
417
+ element.addEventListener('mouseout', this.eventHandle);
418
+ element.addEventListener('touchstart', this.eventHandle);
419
+ element.addEventListener('touchend', this.eventHandle);
420
+ }
421
+ unRegisterMarkerEvent() {
422
+ const element = this.getElement();
423
+ element.removeEventListener('click', this.onMapClick);
424
+ element.removeEventListener('mousemove', this.eventHandle);
425
+ element.removeEventListener('click', this.eventHandle);
426
+ element.removeEventListener('mousedown', this.eventHandle);
427
+ element.removeEventListener('mouseup', this.eventHandle);
428
+ element.removeEventListener('dblclick', this.eventHandle);
429
+ element.removeEventListener('contextmenu', this.eventHandle);
430
+ element.removeEventListener('mouseover', this.eventHandle);
431
+ element.removeEventListener('mouseout', this.eventHandle);
432
+ element.removeEventListener('touchstart', this.eventHandle);
433
+ element.removeEventListener('touchend', this.eventHandle);
434
+ }
435
+ polyfillEvent(e) {
436
+ if (!this.mapsService || this.mapsService.version !== 'GAODE2.x') {
437
+ return;
471
438
  }
472
- }, {
473
- key: "polyfillEvent",
474
- value:
475
- /**
476
- * 高德 2.x 使用了 fastClick.js 避免延迟,导致 IOS 移动端的 click 事件不会正常触发,需要手动触发
477
- * @param e
478
- */
479
-
480
- function polyfillEvent(e) {
481
- if (!this.mapsService || this.mapsService.version !== 'GAODE2.x') {
482
- return;
439
+ if (!isPC()) {
440
+ if (e.type === 'touchstart') {
441
+ this.touchStartTime = Date.now();
483
442
  }
484
- if (!isPC()) {
485
- if (e.type === 'touchstart') {
486
- this.touchStartTime = Date.now();
487
- }
488
- if (e.type === 'touchend' && Date.now() - this.touchStartTime < 300) {
489
- this.emit('click', {
490
- target: e,
491
- data: this.markerOption.extData,
492
- lngLat: this.lngLat
493
- });
494
- }
443
+ if (e.type === 'touchend' && Date.now() - this.touchStartTime < 300) {
444
+ this.emit('click', {
445
+ target: e,
446
+ data: this.markerOption.extData,
447
+ lngLat: this.lngLat
448
+ });
495
449
  }
496
450
  }
451
+ }
497
452
 
498
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
499
- }, {
500
- key: "addDragHandler",
501
- value: function addDragHandler(e) {
502
- return null;
503
- }
453
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
454
+ addDragHandler(e) {
455
+ return null;
456
+ }
504
457
 
505
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
506
- }, {
507
- key: "onUp",
508
- value: function onUp(e) {
509
- throw new Error('Method not implemented.');
510
- }
511
- }]);
512
- return Marker;
513
- }(EventEmitter);
514
- export { Marker as default };
458
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
459
+ onUp(e) {
460
+ throw new Error('Method not implemented.');
461
+ }
462
+ }