@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.
- package/es/assets/iconfont/iconfont.js +6 -6
- package/es/constants/index.js +2 -2
- package/es/control/baseControl/buttonControl.js +109 -144
- package/es/control/baseControl/control.js +212 -258
- package/es/control/baseControl/popperControl.js +67 -95
- package/es/control/baseControl/selectControl.js +132 -178
- package/es/control/exportImage.js +59 -142
- package/es/control/fullscreen.js +69 -100
- package/es/control/geoLocate.js +37 -84
- package/es/control/layerSwitch.js +111 -154
- package/es/control/logo.js +43 -69
- package/es/control/mapTheme.js +57 -98
- package/es/control/mouseLocation.js +37 -69
- package/es/control/scale.js +107 -135
- package/es/control/swipe.js +297 -393
- package/es/control/zoom.js +80 -112
- package/es/css/index.css +10 -7
- package/es/index.js +667 -1
- package/es/marker-layer.js +274 -326
- package/es/marker.d.ts +0 -2
- package/es/marker.js +394 -453
- package/es/popup/layerPopup.js +277 -321
- package/es/popup/popup.js +422 -482
- package/es/utils/anchor.js +6 -6
- package/es/utils/icon.js +4 -4
- package/es/utils/popper.js +180 -196
- package/es/utils/screenfull.js +29 -51
- package/lib/assets/iconfont/iconfont.js +6 -6
- package/lib/constants/index.d.ts +60 -0
- package/lib/constants/index.js +2 -2
- package/lib/control/baseControl/buttonControl.d.ts +60 -0
- package/lib/control/baseControl/buttonControl.js +110 -143
- package/lib/control/baseControl/control.d.ts +112 -0
- package/lib/control/baseControl/control.js +213 -257
- package/lib/control/baseControl/index.d.ts +4 -0
- package/lib/control/baseControl/index.js +5 -5
- package/lib/control/baseControl/popperControl.d.ts +28 -0
- package/lib/control/baseControl/popperControl.js +68 -94
- package/lib/control/baseControl/selectControl.d.ts +53 -0
- package/lib/control/baseControl/selectControl.js +133 -177
- package/lib/control/exportImage.d.ts +19 -0
- package/lib/control/exportImage.js +60 -141
- package/lib/control/fullscreen.d.ts +20 -0
- package/lib/control/fullscreen.js +70 -99
- package/lib/control/geoLocate.d.ts +17 -0
- package/lib/control/geoLocate.js +38 -83
- package/lib/control/layerSwitch.d.ts +27 -0
- package/lib/control/layerSwitch.js +112 -153
- package/lib/control/logo.d.ts +14 -0
- package/lib/control/logo.js +44 -69
- package/lib/control/mapTheme.d.ts +11 -0
- package/lib/control/mapTheme.js +58 -97
- package/lib/control/mouseLocation.d.ts +16 -0
- package/lib/control/mouseLocation.js +38 -68
- package/lib/control/scale.d.ts +35 -0
- package/lib/control/scale.js +108 -134
- package/lib/control/swipe.d.ts +66 -0
- package/lib/control/swipe.js +298 -392
- package/lib/control/zoom.d.ts +39 -0
- package/lib/control/zoom.js +81 -111
- package/lib/css/index.css +10 -7
- package/lib/index.d.ts +19 -0
- package/lib/index.js +683 -17
- package/lib/interface.d.ts +18 -0
- package/lib/marker-layer.d.ts +55 -0
- package/lib/marker-layer.js +276 -324
- package/lib/marker.d.ts +58 -0
- package/lib/marker.js +395 -452
- package/lib/popup/layerPopup.d.ts +99 -0
- package/lib/popup/layerPopup.js +278 -320
- package/lib/popup/popup.d.ts +142 -0
- package/lib/popup/popup.js +423 -481
- package/lib/utils/anchor.d.ts +22 -0
- package/lib/utils/anchor.js +6 -6
- package/lib/utils/icon.d.ts +1 -0
- package/lib/utils/icon.js +6 -5
- package/lib/utils/popper.d.ts +76 -0
- package/lib/utils/popper.js +184 -196
- package/lib/utils/screenfull.d.ts +2 -0
- package/lib/utils/screenfull.js +29 -52
- package/package.json +16 -20
- package/CHANGELOG.md +0 -325
- 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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0,
|
|
27
|
-
|
|
28
|
-
(0, _defineProperty2.default)(
|
|
29
|
-
(0, _defineProperty2.default)(
|
|
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)(
|
|
34
|
-
|
|
28
|
+
(0, _defineProperty2.default)(this, "onMarkerDragStart", e => {
|
|
29
|
+
const mapContainer = this.mapsService.getContainer();
|
|
35
30
|
if (!mapContainer) {
|
|
36
31
|
return;
|
|
37
32
|
}
|
|
38
|
-
|
|
33
|
+
this.mapsService.setMapStatus({
|
|
39
34
|
dragEnable: false,
|
|
40
35
|
zoomEnable: false
|
|
41
36
|
});
|
|
42
|
-
|
|
43
|
-
containerX
|
|
44
|
-
containerY
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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)(
|
|
53
|
-
|
|
54
|
-
preLng
|
|
55
|
-
preLat
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
this.setLnglat(newLngLat);
|
|
64
|
+
this.preLngLat = e.lnglat;
|
|
65
|
+
this.emit('dragging', newLngLat);
|
|
66
66
|
});
|
|
67
|
-
(0, _defineProperty2.default)(
|
|
68
|
-
|
|
67
|
+
(0, _defineProperty2.default)(this, "onMarkerDragEnd", () => {
|
|
68
|
+
this.mapsService.setMapStatus({
|
|
69
69
|
dragEnable: true,
|
|
70
70
|
zoomEnable: true
|
|
71
71
|
});
|
|
72
|
-
|
|
73
|
-
document.removeEventListener('mouseup',
|
|
74
|
-
|
|
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)(
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
(0, _defineProperty2.default)(this, "eventHandle", e => {
|
|
77
|
+
this.polyfillEvent(e);
|
|
78
|
+
this.emit(e.type, {
|
|
79
79
|
target: e,
|
|
80
|
-
data:
|
|
81
|
-
lngLat:
|
|
80
|
+
data: this.markerOption.extData,
|
|
81
|
+
lngLat: this.lngLat
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.mapsService.
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
165
|
-
value: function getLnglat() {
|
|
166
|
-
return this.lngLat;
|
|
133
|
+
if (this.popup) {
|
|
134
|
+
this.popup.remove();
|
|
167
135
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
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
|
-
|
|
253
|
-
value: function getPopup() {
|
|
254
|
-
return this.popup;
|
|
190
|
+
if (!popup.isOpen()) {
|
|
191
|
+
popup.addTo(this.scene);
|
|
255
192
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
closePopup() {
|
|
196
|
+
if (!this.added) {
|
|
197
|
+
this.once('added', () => {
|
|
198
|
+
this.closePopup();
|
|
199
|
+
});
|
|
260
200
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
this.markerOption.draggable = draggable;
|
|
265
|
-
this.updateDraggable();
|
|
201
|
+
const popup = this.popup;
|
|
202
|
+
if (popup) {
|
|
203
|
+
popup.remove();
|
|
266
204
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
|
337
|
-
|
|
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
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
-
|
|
412
|
-
|
|
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
|
-
|
|
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
|
-
|
|
442
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
element
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
element.
|
|
465
|
-
element
|
|
466
|
-
|
|
467
|
-
|
|
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
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
element
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
487
|
-
|
|
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 (
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
return null;
|
|
516
|
-
}
|
|
459
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
460
|
+
addDragHandler(e) {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
517
463
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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;
|