huweili-cesium 1.2.64 → 1.2.66
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 +27 -27
- package/package.json +1 -1
package/js/movePoint.js
CHANGED
|
@@ -21,7 +21,6 @@ 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
|
|
25
24
|
|
|
26
25
|
export function movePointConfig(baseUrl) {
|
|
27
26
|
// 获取地图store实例
|
|
@@ -295,23 +294,16 @@ export function movePointConfig(baseUrl) {
|
|
|
295
294
|
}
|
|
296
295
|
|
|
297
296
|
modelEntity.isFlying = false
|
|
298
|
-
// 每次移动都重建采样属性,只保留“当前位置 -> 最新目标点”的快速追踪段。
|
|
299
|
-
modelEntity.positionProperty = new Cesium.SampledPositionProperty()
|
|
300
|
-
modelEntity.positionProperty.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD
|
|
301
|
-
modelEntity.positionProperty.backwardExtrapolationType = Cesium.ExtrapolationType.HOLD
|
|
302
|
-
modelEntity.positionProperty.forwardExtrapolationDuration = Number.POSITIVE_INFINITY
|
|
303
|
-
modelEntity.positionProperty.backwardExtrapolationDuration = Number.POSITIVE_INFINITY
|
|
304
|
-
modelEntity.positionProperty.addSample(currentTime, currentRealPosition)
|
|
305
|
-
modelEntity.entity.position = modelEntity.positionProperty
|
|
306
297
|
|
|
307
298
|
// ========== 计算新的飞行路径 ==========
|
|
308
299
|
const targetPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height)
|
|
309
|
-
const
|
|
310
|
-
|
|
300
|
+
const startPosition = Cesium.Cartesian3.clone(currentRealPosition, modelEntity.startPosition || new Cesium.Cartesian3())
|
|
301
|
+
modelEntity.startPosition = startPosition
|
|
302
|
+
const distanceSquared = Cesium.Cartesian3.distanceSquared(startPosition, targetPosition)
|
|
311
303
|
const cruiseSpeed = Math.max(speed, 0)
|
|
312
304
|
const moveDirection = distanceSquared >= MIN_DRONE_MOVE_DISTANCE_SQUARED
|
|
313
305
|
? Cesium.Cartesian3.normalize(
|
|
314
|
-
Cesium.Cartesian3.subtract(targetPosition,
|
|
306
|
+
Cesium.Cartesian3.subtract(targetPosition, startPosition, modelEntity.scratchTargetPosition),
|
|
315
307
|
new Cesium.Cartesian3()
|
|
316
308
|
)
|
|
317
309
|
: modelEntity.lastMoveDirection
|
|
@@ -322,27 +314,41 @@ export function movePointConfig(baseUrl) {
|
|
|
322
314
|
modelEntity.lastSpeed = cruiseSpeed
|
|
323
315
|
|
|
324
316
|
// 新坐标进来时不再按业务速度慢慢飞过去,而是用极短追踪时间快速贴到最新经纬度。
|
|
317
|
+
// 关键:无人机实体位置和拖尾必须使用同一个 tickPosition 驱动,不能实体用 SampledPositionProperty、拖尾用预测位置各跑各的。
|
|
325
318
|
const fastArriveDuration = distanceSquared < MIN_DRONE_MOVE_DISTANCE_SQUARED ? 0 : 0.05
|
|
319
|
+
const flightStartTime = Cesium.JulianDate.clone(currentTime, modelEntity.flightStartTime || new Cesium.JulianDate())
|
|
326
320
|
const flightEndTime = Cesium.JulianDate.addSeconds(currentTime, fastArriveDuration, modelEntity.scratchFlightEndTime)
|
|
321
|
+
modelEntity.flightStartTime = flightStartTime
|
|
327
322
|
|
|
328
323
|
if (!map.clock.shouldAnimate) {
|
|
329
324
|
map.clock.shouldAnimate = true
|
|
330
325
|
}
|
|
331
326
|
|
|
332
|
-
modelEntity.positionProperty.addSample(flightEndTime, targetPosition)
|
|
333
327
|
modelEntity.isFlying = true
|
|
334
|
-
|
|
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
|
+
}
|
|
335
339
|
|
|
336
340
|
const flightTickListener = (clock) => {
|
|
337
341
|
if (!modelEntity.isFlying) return
|
|
338
342
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
? modelEntity.positionProperty.getValue(clock.currentTime, modelEntity.scratchPosition)
|
|
342
|
-
: targetPosition
|
|
343
|
+
let tickPosition = targetPosition
|
|
344
|
+
const isArriving = fastArriveDuration > 0 && Cesium.JulianDate.compare(clock.currentTime, flightEndTime) < 0
|
|
343
345
|
|
|
344
|
-
if (
|
|
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
|
+
// 下一秒坐标迟迟不来时,无人机实体和拖尾一起按上一次航向、速度继续向前插值。
|
|
346
352
|
const extraSeconds = Math.max(0, Cesium.JulianDate.secondsDifference(clock.currentTime, flightEndTime))
|
|
347
353
|
const extraDistance = modelEntity.lastSpeed * extraSeconds
|
|
348
354
|
tickPosition = Cesium.Cartesian3.add(
|
|
@@ -354,13 +360,7 @@ export function movePointConfig(baseUrl) {
|
|
|
354
360
|
|
|
355
361
|
if (!tickPosition) return
|
|
356
362
|
|
|
357
|
-
|
|
358
|
-
modelEntity.currentPosition = Cesium.Cartesian3.clone(tickPosition, modelEntity.currentPosition)
|
|
359
|
-
moveDroneTrail({
|
|
360
|
-
pointId,
|
|
361
|
-
newPosition: modelEntity.currentPosition,
|
|
362
|
-
mapId
|
|
363
|
-
})
|
|
363
|
+
applyDronePosition(tickPosition)
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
modelEntity.flightEndListener = flightTickListener
|