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