-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathVideoMarker.js
More file actions
207 lines (202 loc) · 5.73 KB
/
Copy pathVideoMarker.js
File metadata and controls
207 lines (202 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import mapboxgl from 'mapbox-gl';
import { transformCoord } from './util';
import VideoMapPopup from './VideoMapPopup';
import { SuperMap } from '@supermap/iclient-common';
const MARKER_EVENTS = ['drag', 'dragstart', 'dragend'];
/**
* @class SuperMap.VideoMarker
* @classdesc 视频 Marker
* @param {Object} videoMap - 视频地图实例。
* @param {Object} options - Marker 配置 详见:{@link https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker-parameters}。
**/
export default class VideoMarker extends mapboxgl.Evented {
constructor(videoMap, options) {
super();
const { coordTransfer, originCoordsRightBottom, originCoordsLeftTop, videoWidth, videoHeight, map } = videoMap;
this.map = map;
this.coordTransfer = coordTransfer;
this.originCoordsRightBottom = originCoordsRightBottom;
this.originCoordsLeftTop = originCoordsLeftTop;
this.videoWidth = videoWidth;
this.videoHeight = videoHeight;
this.setDataFn = this._setData.bind(this);
this.markerEventFn = this.markerEvent.bind(this);
this.marker = new mapboxgl.Marker(options);
MARKER_EVENTS.forEach((eventName) => {
this.marker.on(eventName, this.markerEventFn);
});
this.map.on('videoparameterchange', this.setDataFn);
}
markerEvent(e) {
this.fire(e.type, { e });
}
/**
* @function SuperMap.VideoMarker.prototype.setCoordinate
* @description 设置坐标。
* @returns {Marker} Marker 实例。
*/
setCoordinate(coordinate) {
this.cacheCoord = coordinate;
this._setData();
return this;
}
getCoordinate() {}
/**
* @function SuperMap.VideoMarker.prototype.setPopup
* @description 设置 Popup。
* @returns {Marker} Marker 实例。
*/
setPopup(popup) {
if (popup instanceof VideoMapPopup) {
this.marker.setPopup(popup.popup);
return this;
}
}
/**
* @function SuperMap.VideoMarker.prototype.getPopup
* @description 获取 Popup 实例。
*/
getPopup() {
return this.marker.getPopup();
}
/**
* @function SuperMap.VideoMarker.prototype.addToMap
* @description 添加到视频地图。
* @returns {Marker} Marker 实例。
*/
addToMap() {
this.marker.addTo(this.map);
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.remove
* @description 移除 Marker。
*/
remove() {
MARKER_EVENTS.forEach((eventName) => {
this.marker.off(eventName, this.markerEventFn);
});
this.marker.remove();
this.map.off('videoparameterchange', this.setDataFn);
}
/**
* @function SuperMap.VideoMarker.prototype.setDraggable
* @description 设置 Marker 是否可以拖拽。
* @returns {Marker} Marker 实例。
*/
setDraggable(shouldBeDraggable) {
this.marker.setDraggable(shouldBeDraggable);
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.isDraggable
* @description 设置坐标。
* @returns {Marker} Marker 实例。
*/
isDraggable() {
this.marker.isDraggable();
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.setRotation
* @description 设置旋转角度。
* @returns {Marker} Marker 实例。
*/
setRotation(rotation) {
return this.marker.setRotation(rotation);
}
/**
* @function SuperMap.VideoMarker.prototype.getRotation
* @description 获取旋转角度。
* @returns {Marker} Marker 实例。
*/
getRotation() {
return this.marker.getRotation();
}
/**
* @function SuperMap.VideoMarker.prototype.setRotationAlignment
* @description 设置旋转。
* @returns {Marker} Marker 实例。
*/
setRotationAlignment(alignment) {
this.marker.setRotationAlignment(alignment);
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.getRotationAlignment
* @description 设置坐标。
* @returns {Marker} Marker 实例。
*/
getRotationAlignment() {
return this.marker.getRotationAlignment();
}
/**
* @function SuperMap.VideoMarker.prototype.setPitchAlignment
* @description 设置坐标。
* @returns {Marker} Marker 实例。
*/
setPitchAlignment(alignment) {
this.marker.setPitchAlignment(alignment);
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.setCoordinate
* @description 获取方位角居中。
* @returns {Marker} Marker 实例。
*/
getPitchAlignment() {
return this.marker.getPitchAlignment();
}
/**
* @function SuperMap.VideoMarker.prototype.getElement
* @description 获取 Marker 元素。
* @returns {Marker} Marker 实例。
*/
getElement() {
return this.marker.getElement();
}
/**
* @function SuperMap.VideoMarker.prototype.togglePopup
* @description 切换 Popup 的显示隐藏。
* @returns {Marker} Marker 实例。
*/
togglePopup() {
this.marker.togglePopup();
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.getOffset
* @description 获取偏移。
* @returns {Marker} Marker 实例。
*/
getOffset() {
this.marker.getOffset();
return this;
}
/**
* @function SuperMap.VideoMarker.prototype.setOffset
* @description 设置偏移。
* @returns {Marker} Marker 实例。
*/
setOffset(offset) {
this.marker.setOffset(offset);
return this;
}
_setData() {
if (!this.coordTransfer) {
return;
}
if (this.cacheCoord) {
let transCoords = this.coordTransfer.toVideoCoordinate(this.cacheCoord);
transCoords = transformCoord({
videoPoint: transCoords.data64F,
videoWidth: this.videoWidth,
videoHeight: this.videoHeight,
originCoordsRightBottom: this.originCoordsRightBottom,
originCoordsLeftTop: this.originCoordsLeftTop
});
this.marker.setLngLat(transCoords);
}
}
}
SuperMap.VideoMarker = VideoMarker;