huweili-cesium 1.2.65 → 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.
Files changed (2) hide show
  1. package/js/movePoint.js +27 -28
  2. 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 distanceSquared = Cesium.Cartesian3.distanceSquared(currentRealPosition, targetPosition)
310
- const distance = Math.sqrt(distanceSquared)
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, currentRealPosition, modelEntity.scratchTargetPosition),
306
+ Cesium.Cartesian3.subtract(targetPosition, startPosition, modelEntity.scratchTargetPosition),
315
307
  new Cesium.Cartesian3()
316
308
  )
317
309
  : modelEntity.lastMoveDirection
@@ -322,28 +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
- // 注意:这里不能提前把 currentPosition 写成 targetPosition。
335
- // currentPosition 必须只缓存无人机每帧真实显示位置,否则下一次更新拖尾时会读到未来目标点,导致轨迹跑到无人机前面。
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
+ }
336
339
 
337
340
  const flightTickListener = (clock) => {
338
341
  if (!modelEntity.isFlying) return
339
342
 
340
- const isArriving = Cesium.JulianDate.compare(clock.currentTime, flightEndTime) < 0
341
- let tickPosition = isArriving
342
- ? modelEntity.positionProperty.getValue(clock.currentTime, modelEntity.scratchPosition)
343
- : targetPosition
343
+ let tickPosition = targetPosition
344
+ const isArriving = fastArriveDuration > 0 && Cesium.JulianDate.compare(clock.currentTime, flightEndTime) < 0
344
345
 
345
- if (!isArriving && modelEntity.lastMoveDirection && modelEntity.lastSpeed > 0) {
346
- // 下一秒坐标迟迟不来时,按上一次航向和速度继续向前慢速插值飞行。
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
+ // 下一秒坐标迟迟不来时,无人机实体和拖尾一起按上一次航向、速度继续向前插值。
347
352
  const extraSeconds = Math.max(0, Cesium.JulianDate.secondsDifference(clock.currentTime, flightEndTime))
348
353
  const extraDistance = modelEntity.lastSpeed * extraSeconds
349
354
  tickPosition = Cesium.Cartesian3.add(
@@ -355,13 +360,7 @@ export function movePointConfig(baseUrl) {
355
360
 
356
361
  if (!tickPosition) return
357
362
 
358
- // 每帧缓存真实位置,并同步追加轨迹点。
359
- modelEntity.currentPosition = Cesium.Cartesian3.clone(tickPosition, modelEntity.currentPosition)
360
- moveDroneTrail({
361
- pointId,
362
- newPosition: modelEntity.currentPosition,
363
- mapId
364
- })
363
+ applyDronePosition(tickPosition)
365
364
  }
366
365
 
367
366
  modelEntity.flightEndListener = flightTickListener
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.65",
3
+ "version": "1.2.66",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",