huweili-cesium 1.2.66 → 1.2.68
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/movePoint.js +29 -103
- package/package.json +1 -1
package/js/movePoint.js
CHANGED
|
@@ -21,6 +21,7 @@ import { groundLinkConfig } from './groundLink'
|
|
|
21
21
|
|
|
22
22
|
const MIN_DRONE_MOVE_DISTANCE = 0.1
|
|
23
23
|
const MIN_DRONE_MOVE_DISTANCE_SQUARED = MIN_DRONE_MOVE_DISTANCE * MIN_DRONE_MOVE_DISTANCE
|
|
24
|
+
const DEFAULT_FAR_FUTURE_SECONDS = 3600
|
|
24
25
|
|
|
25
26
|
export function movePointConfig(baseUrl) {
|
|
26
27
|
// 获取地图store实例
|
|
@@ -239,12 +240,6 @@ export function movePointConfig(baseUrl) {
|
|
|
239
240
|
return modelEntity
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
// 初始化复用对象,避免上百个无人机高频移动时反复创建临时对象
|
|
243
|
-
modelEntity.scratchPosition ||= new Cesium.Cartesian3()
|
|
244
|
-
modelEntity.scratchTargetPosition ||= new Cesium.Cartesian3()
|
|
245
|
-
modelEntity.scratchFlightEndTime ||= new Cesium.JulianDate()
|
|
246
|
-
modelEntity.scratchFarFutureTime ||= new Cesium.JulianDate()
|
|
247
|
-
|
|
248
243
|
// 如果存在实体,确保实体属性实时同步
|
|
249
244
|
const info = modelEntity.info || (modelEntity.info = {})
|
|
250
245
|
info.pointId = pointId
|
|
@@ -259,112 +254,43 @@ export function movePointConfig(baseUrl) {
|
|
|
259
254
|
info.distance = options.distance || ''
|
|
260
255
|
info.receiveTime = options.receiveTime || ''
|
|
261
256
|
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (!currentRealPosition && modelEntity.currentPosition) {
|
|
267
|
-
// 插值属性取不到值时,回退到上一次缓存的真实位置。
|
|
268
|
-
currentRealPosition = Cesium.Cartesian3.clone(modelEntity.currentPosition, modelEntity.scratchPosition)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (!currentRealPosition) {
|
|
272
|
-
// 仍没有当前位置时,使用本次传入坐标作为起点。
|
|
273
|
-
currentRealPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height, modelEntity.scratchPosition)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// getValue 复用 scratchPosition,后续 targetPosition 也会复用其它 scratch,先把当前位置固定到独立对象,避免被后续计算覆盖。
|
|
277
|
-
currentRealPosition = Cesium.Cartesian3.clone(currentRealPosition, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
278
|
-
modelEntity.currentPosition = currentRealPosition
|
|
279
|
-
// ========== 实时位置获取结束 ==========
|
|
280
|
-
|
|
281
|
-
// ========== 保留轨迹 ==========
|
|
282
|
-
// 在飞行开始前,先记录当前点,保证轨迹不会从新目标点突兀开始。
|
|
283
|
-
moveDroneTrail({
|
|
284
|
-
pointId,
|
|
285
|
-
newPosition: currentRealPosition,
|
|
286
|
-
mapId
|
|
287
|
-
})
|
|
257
|
+
// 约定:收到一次无人机数据,就立刻把无人机定位到这个点,同时拖尾追加同一个点。
|
|
258
|
+
// 不再做平滑插值,避免无人机和轨迹之间出现滞后。
|
|
259
|
+
const targetPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height)
|
|
288
260
|
|
|
289
|
-
//
|
|
290
|
-
// 新坐标一到,立即打断旧的插值/续航逻辑,优先追最新点位。
|
|
261
|
+
// 终止旧飞行监听,避免历史插值逻辑继续影响当前定位。
|
|
291
262
|
if (modelEntity.flightEndListener) {
|
|
292
263
|
map.clock.onTick.removeEventListener(modelEntity.flightEndListener)
|
|
293
264
|
modelEntity.flightEndListener = null
|
|
294
265
|
}
|
|
295
266
|
|
|
296
267
|
modelEntity.isFlying = false
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
modelEntity.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
268
|
+
modelEntity.currentPosition = Cesium.Cartesian3.clone(targetPosition, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
269
|
+
modelEntity.info = modelEntity.info || {}
|
|
270
|
+
modelEntity.info.pointId = pointId
|
|
271
|
+
modelEntity.info.lng = lng
|
|
272
|
+
modelEntity.info.lat = lat
|
|
273
|
+
modelEntity.info.height = height
|
|
274
|
+
modelEntity.info.speed = speed
|
|
275
|
+
modelEntity.info.flyingHandName = options.flyingHandName || ''
|
|
276
|
+
modelEntity.info.flyingHandPhone = options.flyingHandPhone || ''
|
|
277
|
+
modelEntity.info.flyingHandPosition = options.flyingHandPosition || ''
|
|
278
|
+
modelEntity.info.frequencyBand = options.frequencyBand || ''
|
|
279
|
+
modelEntity.info.distance = options.distance || ''
|
|
280
|
+
modelEntity.info.receiveTime = options.receiveTime || ''
|
|
281
|
+
|
|
282
|
+
// 直接使用当前点覆盖实体位置,不再依赖 SampledPositionProperty 做插值。
|
|
283
|
+
if (modelEntity.entity) {
|
|
284
|
+
modelEntity.entity.position = targetPosition
|
|
313
285
|
}
|
|
314
|
-
modelEntity.
|
|
286
|
+
modelEntity.positionProperty = null
|
|
315
287
|
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (!map.clock.shouldAnimate) {
|
|
324
|
-
map.clock.shouldAnimate = true
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
modelEntity.isFlying = true
|
|
328
|
-
|
|
329
|
-
const applyDronePosition = (position) => {
|
|
330
|
-
modelEntity.currentPosition = Cesium.Cartesian3.clone(position, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
331
|
-
// 直接用每帧真实位置驱动无人机显示,确保无人机和拖尾完全同源,拖尾不会领先于无人机。
|
|
332
|
-
modelEntity.entity.position = modelEntity.currentPosition
|
|
333
|
-
moveDroneTrail({
|
|
334
|
-
pointId,
|
|
335
|
-
newPosition: modelEntity.currentPosition,
|
|
336
|
-
mapId
|
|
337
|
-
})
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const flightTickListener = (clock) => {
|
|
341
|
-
if (!modelEntity.isFlying) return
|
|
342
|
-
|
|
343
|
-
let tickPosition = targetPosition
|
|
344
|
-
const isArriving = fastArriveDuration > 0 && Cesium.JulianDate.compare(clock.currentTime, flightEndTime) < 0
|
|
345
|
-
|
|
346
|
-
if (isArriving) {
|
|
347
|
-
const elapsedSeconds = Math.max(0, Cesium.JulianDate.secondsDifference(clock.currentTime, flightStartTime))
|
|
348
|
-
const progress = Math.min(1, elapsedSeconds / fastArriveDuration)
|
|
349
|
-
tickPosition = Cesium.Cartesian3.lerp(startPosition, targetPosition, progress, modelEntity.scratchPosition)
|
|
350
|
-
} else if (modelEntity.lastMoveDirection && modelEntity.lastSpeed > 0) {
|
|
351
|
-
// 下一秒坐标迟迟不来时,无人机实体和拖尾一起按上一次航向、速度继续向前插值。
|
|
352
|
-
const extraSeconds = Math.max(0, Cesium.JulianDate.secondsDifference(clock.currentTime, flightEndTime))
|
|
353
|
-
const extraDistance = modelEntity.lastSpeed * extraSeconds
|
|
354
|
-
tickPosition = Cesium.Cartesian3.add(
|
|
355
|
-
targetPosition,
|
|
356
|
-
Cesium.Cartesian3.multiplyByScalar(modelEntity.lastMoveDirection, extraDistance, modelEntity.scratchTargetPosition),
|
|
357
|
-
modelEntity.scratchPosition
|
|
358
|
-
)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (!tickPosition) return
|
|
362
|
-
|
|
363
|
-
applyDronePosition(tickPosition)
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
modelEntity.flightEndListener = flightTickListener
|
|
367
|
-
map.clock.onTick.addEventListener(flightTickListener)
|
|
288
|
+
// 拖尾直接追加同一个点。
|
|
289
|
+
moveDroneTrail({
|
|
290
|
+
pointId,
|
|
291
|
+
newPosition: modelEntity.currentPosition,
|
|
292
|
+
mapId
|
|
293
|
+
})
|
|
368
294
|
|
|
369
295
|
return modelEntity
|
|
370
296
|
};
|