-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathVideoMapPopup.js
More file actions
193 lines (186 loc) · 5.22 KB
/
Copy pathVideoMapPopup.js
File metadata and controls
193 lines (186 loc) · 5.22 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
import mapboxgl from 'mapbox-gl';
import { transformCoord, validLnglat } from './util';
import { SuperMap } from '@supermap/iclient-common';
const POPUP_EVENTS = ['open', 'close'];
/**
* @class SuperMap.VideoMapPopup
* @classdesc 视频地图 popup
* @param {Object} videoMap - 视频地图实例。
* @param {Object} options - Marker 配置 详见:{@link https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup-parameters}。
* @extends {mapboxgl.Evented}
*/
export default class VideoMapPopup 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.cacheCoords = null;
this.popupEventFn = this.popupEvent.bind(this);
this.popup = new mapboxgl.Popup(options);
POPUP_EVENTS.forEach((eventName) => {
this.popup.on(eventName, this.popupEventFn);
});
this.setDataFn = this._setData.bind(this);
this.map.on('videoparameterchange', this.setDataFn);
}
popupEvent(e) {
this.fire(e.type, { e });
}
/**
* @function SuperMap.VideoMapPopup.prototype.setCoordinate
* @description 设置坐标。
* @param {Array} coordinate - 坐标。
*/
setCoordinate(coordinate) {
this.cacheCoords = coordinate;
this._setData();
return this;
}
getCoordinate() {}
trackPointer() {
this.popup.trackPointer();
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.getElement
* @description 获取 popup 元素。
*/
getElement() {
return this.popup.getElement();
}
/**
* @function SuperMap.VideoMapPopup.prototype.setOffset
* @description 设置偏移值。
* @returns {Popup} Popup 实例。
*/
setOffset(offset) {
this.popup.setOffset(offset);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.addClassName
* @description 添加类名。
* @returns {Popup} Popup 实例。
*/
addClassName(className) {
this.popup.addClassName(className);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.removeClassName
* @description 移除类名。
* @returns {Popup} Popup 实例。
*/
removeClassName(className) {
this.popup.removeClassName(className);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.toggleClassName
* @description 切换类名。
*/
toggleClassName(className) {
this.popup.toggleClassName(className);
}
/**
* @function SuperMap.VideoMapPopup.prototype.getMaxWidth
* @description 获取最大宽度。
* @returns {string} 最大宽度值。
*/
getMaxWidth(maxWidth) {
return this.popup.getMaxWidth(maxWidth);
}
/**
* @function SuperMap.VideoMapPopup.prototype.setMaxWidth
* @description 设置最大宽度。
* @param {string} maxWidth - 宽度值
* @returns {Popup} Popup 实例。
*/
setMaxWidth(maxWidth) {
this.popup.setMaxWidth(maxWidth);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.setDOMContent
* @description 设置 dom 元素。
* @param {Element} htmlNode
* @returns {Popup} Popup 实例。
*/
setDOMContent(htmlNode) {
this.popup.setDOMContent(htmlNode);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.setText
* @description 设置 text。
* @param {string} text
* @returns {Popup} Popup 实例。
*/
setText(text) {
this.popup.setText(text);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.setHTML
* @description 设置 html。
* @param {string} html
* @returns {Popup} Popup 实例。
*/
setHTML(html) {
this.popup.setHTML(html);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.addToMap
* @description popup 添加到地图。
* @returns {Popup} Popup 实例。
*/
addToMap() {
this.popup.addTo(this.map);
return this;
}
/**
* @function SuperMap.VideoMapPopup.prototype.isOpen
* @description Popup 是否展开。
* @returns {boolean} 展开状态。
*/
isOpen() {
return this.popup.isOpen();
}
_setData() {
if (!this.coordTransfer) {
return;
}
if (this.cacheCoords) {
let transCoords = this.coordTransfer.toVideoCoordinate(this.cacheCoords);
transCoords = transformCoord({
videoPoint: transCoords.data64F,
videoWidth: this.videoWidth,
videoHeight: this.videoHeight,
originCoordsRightBottom: this.originCoordsRightBottom,
originCoordsLeftTop: this.originCoordsLeftTop
});
if (!validLnglat(transCoords)) {
return;
}
this.popup.setLngLat(transCoords).addTo(this.map);
}
}
/**
* @function SuperMap.VideoMapPopup.prototype.remove
* @description 移除 Popup。
*/
remove() {
POPUP_EVENTS.forEach((eventName) => {
this.popup.off(eventName, this.popupEventFn);
});
this.popup.remove();
this.map.off('videoparameterchange', this.setDataFn);
}
}
SuperMap.VideoMapPopup = VideoMapPopup;