huweili-cesium 1.3.6 → 1.3.7
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/js/labelDiv.js +59 -27
- package/package.json +1 -1
package/js/labelDiv.js
CHANGED
|
@@ -9,6 +9,8 @@ import { useMapStore } from './stores/mapStore.js'
|
|
|
9
9
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
10
10
|
// 详情面板文字刷新最小间隔(毫秒),避免每帧跑逻辑
|
|
11
11
|
const DRONE_INFO_UPDATE_MIN_MS = 1000;
|
|
12
|
+
// 接收时间单独快更新(与界面列表对齐,不拖累其它字段的节流)
|
|
13
|
+
const DRONE_RECEIVE_TIME_UPDATE_MIN_MS = 100;
|
|
12
14
|
|
|
13
15
|
/** @typedef {{ lng: string, lat: string, alt: string, speed: string, flyingHandName: string, flyingHandPhone: string, flyingHandPosition: string, frequencyBand: string, distance: string, receiveTime: string }} DroneInfoDisplay */
|
|
14
16
|
|
|
@@ -78,7 +80,16 @@ function formatDroneInfoDisplay(info) {
|
|
|
78
80
|
* @returns {string}
|
|
79
81
|
*/
|
|
80
82
|
function buildInfoFingerprint(display) {
|
|
81
|
-
return `${display
|
|
83
|
+
return `${buildInfoFingerprintWithoutTime(display)}|${display.receiveTime}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 详情面板指纹(不含接收时间,供慢更新通道比对)
|
|
88
|
+
* @param {DroneInfoDisplay} display
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
function buildInfoFingerprintWithoutTime(display) {
|
|
92
|
+
return `${display.lng}|${display.lat}|${display.alt}|${display.speed}|${display.flyingHandName}|${display.flyingHandPhone}|${display.frequencyBand}|${display.distance}|${display.flyingHandPosition}`;
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
/**
|
|
@@ -169,7 +180,9 @@ export function labelDiv() {
|
|
|
169
180
|
let dragRafId = 0;
|
|
170
181
|
let rafId = 0; // 是用来存储 requestAnimationFrame 的返回ID,用于管理无人机信息的实时刷新
|
|
171
182
|
let lastInfoText = '';
|
|
183
|
+
let lastReceiveTimeText = '';
|
|
172
184
|
let lastInfoTick = 0;
|
|
185
|
+
let lastReceiveTimeTick = 0;
|
|
173
186
|
/** @type {DroneInfoDisplay|null} */
|
|
174
187
|
let cachedInfoDisplay = null;
|
|
175
188
|
let infoDiv = null;
|
|
@@ -231,37 +244,54 @@ export function labelDiv() {
|
|
|
231
244
|
document.removeEventListener('pointerup', onPointerEnd);
|
|
232
245
|
};
|
|
233
246
|
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
if (!
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
247
|
+
// 接收时间快通道:100ms 轮询,与界面列表更接近
|
|
248
|
+
const updateReceiveTime = (display, now) => {
|
|
249
|
+
if (!infoFieldEls?.receiveTimeEl) return;
|
|
250
|
+
if (now - lastReceiveTimeTick < DRONE_RECEIVE_TIME_UPDATE_MIN_MS) return;
|
|
251
|
+
|
|
252
|
+
lastReceiveTimeTick = now;
|
|
253
|
+
const nextReceiveTime = display.receiveTime;
|
|
254
|
+
if (nextReceiveTime === lastReceiveTimeText) return;
|
|
255
|
+
|
|
256
|
+
infoFieldEls.receiveTimeEl.textContent = nextReceiveTime;
|
|
257
|
+
lastReceiveTimeText = nextReceiveTime;
|
|
258
|
+
if (cachedInfoDisplay) {
|
|
259
|
+
cachedInfoDisplay.receiveTime = nextReceiveTime;
|
|
241
260
|
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// 其它字段慢通道:1s 节流,避免每帧跑逻辑
|
|
264
|
+
const updateOtherDroneInfo = (display, now) => {
|
|
265
|
+
if (!infoFieldEls || now - lastInfoTick < DRONE_INFO_UPDATE_MIN_MS) return;
|
|
242
266
|
|
|
243
267
|
lastInfoTick = now;
|
|
268
|
+
const nextInfoText = buildInfoFingerprintWithoutTime(display);
|
|
269
|
+
if (nextInfoText === lastInfoText) return;
|
|
270
|
+
|
|
271
|
+
const {
|
|
272
|
+
lngEl, latEl, altEl, speedEl, flyingHandNameEl, flyingHandPhoneEl, flyingHandPositionEl, distanceEl
|
|
273
|
+
} = infoFieldEls;
|
|
274
|
+
if (lngEl) lngEl.textContent = display.lng;
|
|
275
|
+
if (latEl) latEl.textContent = display.lat;
|
|
276
|
+
if (altEl) altEl.textContent = display.alt;
|
|
277
|
+
if (speedEl) speedEl.textContent = display.speed;
|
|
278
|
+
if (flyingHandNameEl) flyingHandNameEl.textContent = display.flyingHandName;
|
|
279
|
+
if (flyingHandPhoneEl) flyingHandPhoneEl.textContent = display.flyingHandPhone;
|
|
280
|
+
if (distanceEl) distanceEl.textContent = display.distance;
|
|
281
|
+
if (flyingHandPositionEl) flyingHandPositionEl.textContent = display.flyingHandPosition;
|
|
282
|
+
lastInfoText = nextInfoText;
|
|
283
|
+
cachedInfoDisplay = display;
|
|
284
|
+
lastReceiveTimeText = display.receiveTime;
|
|
285
|
+
};
|
|
244
286
|
|
|
287
|
+
function updateDroneInfo(ts) {
|
|
288
|
+
if (!infoDiv) return;
|
|
289
|
+
const now = ts ?? performance.now();
|
|
245
290
|
const info = labelItem.getInfo ? labelItem.getInfo() : null;
|
|
246
291
|
const display = resolveInfoDisplay(info, cachedInfoDisplay);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const {
|
|
251
|
-
lngEl, latEl, altEl, speedEl, flyingHandNameEl, flyingHandPhoneEl, flyingHandPositionEl, distanceEl, receiveTimeEl
|
|
252
|
-
} = infoFieldEls;
|
|
253
|
-
if (lngEl) lngEl.textContent = display.lng;
|
|
254
|
-
if (latEl) latEl.textContent = display.lat;
|
|
255
|
-
if (altEl) altEl.textContent = display.alt;
|
|
256
|
-
if (receiveTimeEl) receiveTimeEl.textContent = display.receiveTime;
|
|
257
|
-
if (speedEl) speedEl.textContent = display.speed;
|
|
258
|
-
if (flyingHandNameEl) flyingHandNameEl.textContent = display.flyingHandName;
|
|
259
|
-
if (flyingHandPhoneEl) flyingHandPhoneEl.textContent = display.flyingHandPhone;
|
|
260
|
-
if (distanceEl) distanceEl.textContent = display.distance;
|
|
261
|
-
if (flyingHandPositionEl) flyingHandPositionEl.textContent = display.flyingHandPosition;
|
|
262
|
-
lastInfoText = nextInfoText;
|
|
263
|
-
cachedInfoDisplay = display;
|
|
264
|
-
}
|
|
292
|
+
|
|
293
|
+
updateReceiveTime(display, now);
|
|
294
|
+
updateOtherDroneInfo(display, now);
|
|
265
295
|
|
|
266
296
|
rafId = requestAnimationFrame(updateDroneInfo);
|
|
267
297
|
}
|
|
@@ -392,9 +422,11 @@ export function labelDiv() {
|
|
|
392
422
|
};
|
|
393
423
|
}
|
|
394
424
|
|
|
395
|
-
lastInfoText =
|
|
425
|
+
lastInfoText = buildInfoFingerprintWithoutTime(initialDisplay);
|
|
426
|
+
lastReceiveTimeText = initialDisplay.receiveTime;
|
|
396
427
|
cachedInfoDisplay = initialDisplay;
|
|
397
428
|
lastInfoTick = 0;
|
|
429
|
+
lastReceiveTimeTick = 0;
|
|
398
430
|
updateDroneInfo();
|
|
399
431
|
|
|
400
432
|
// 关闭时移除动画帧
|