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