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.
Files changed (2) hide show
  1. package/js/movePoint.js +29 -103
  2. 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
- const positionProperty = modelEntity.positionProperty || modelEntity.entity?.position
264
- let currentRealPosition = positionProperty?.getValue?.(currentTime, modelEntity.scratchPosition)
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
- const targetPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height)
300
- const startPosition = Cesium.Cartesian3.clone(currentRealPosition, modelEntity.startPosition || new Cesium.Cartesian3())
301
- modelEntity.startPosition = startPosition
302
- const distanceSquared = Cesium.Cartesian3.distanceSquared(startPosition, targetPosition)
303
- const cruiseSpeed = Math.max(speed, 0)
304
- const moveDirection = distanceSquared >= MIN_DRONE_MOVE_DISTANCE_SQUARED
305
- ? Cesium.Cartesian3.normalize(
306
- Cesium.Cartesian3.subtract(targetPosition, startPosition, modelEntity.scratchTargetPosition),
307
- new Cesium.Cartesian3()
308
- )
309
- : modelEntity.lastMoveDirection
310
-
311
- if (moveDirection) {
312
- modelEntity.lastMoveDirection = Cesium.Cartesian3.clone(moveDirection, modelEntity.lastMoveDirection || new Cesium.Cartesian3())
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.lastSpeed = cruiseSpeed
286
+ modelEntity.positionProperty = null
315
287
 
316
- // 新坐标进来时不再按业务速度慢慢飞过去,而是用极短追踪时间快速贴到最新经纬度。
317
- // 关键:无人机实体位置和拖尾必须使用同一个 tickPosition 驱动,不能实体用 SampledPositionProperty、拖尾用预测位置各跑各的。
318
- const fastArriveDuration = distanceSquared < MIN_DRONE_MOVE_DISTANCE_SQUARED ? 0 : 0.05
319
- const flightStartTime = Cesium.JulianDate.clone(currentTime, modelEntity.flightStartTime || new Cesium.JulianDate())
320
- const flightEndTime = Cesium.JulianDate.addSeconds(currentTime, fastArriveDuration, modelEntity.scratchFlightEndTime)
321
- modelEntity.flightStartTime = flightStartTime
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huweili-cesium",
3
- "version": "1.2.66",
3
+ "version": "1.2.68",
4
4
  "description": "基于 Cesium 的地图工具库(无人机态势、轨迹、围栏、工具栏等)",
5
5
  "type": "module",
6
6
  "main": "./index.js",