huweili-cesium 1.2.66 → 1.2.67
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 +13 -97
- package/package.json +1 -1
package/js/movePoint.js
CHANGED
|
@@ -259,112 +259,28 @@ export function movePointConfig(baseUrl) {
|
|
|
259
259
|
info.distance = options.distance || ''
|
|
260
260
|
info.receiveTime = options.receiveTime || ''
|
|
261
261
|
|
|
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
|
-
})
|
|
288
|
-
|
|
289
262
|
// ========== 终止当前所有飞行状态 ==========
|
|
290
|
-
//
|
|
263
|
+
// 本方案不再做平滑插值和断流续航:来一个新经纬度,无人机和拖尾就同步落到该经纬度。
|
|
291
264
|
if (modelEntity.flightEndListener) {
|
|
292
265
|
map.clock.onTick.removeEventListener(modelEntity.flightEndListener)
|
|
293
266
|
modelEntity.flightEndListener = null
|
|
294
267
|
}
|
|
295
268
|
|
|
296
269
|
modelEntity.isFlying = false
|
|
270
|
+
modelEntity.positionProperty = null
|
|
271
|
+
modelEntity.lastMoveDirection = null
|
|
272
|
+
modelEntity.lastSpeed = 0
|
|
297
273
|
|
|
298
|
-
|
|
299
|
-
|
|
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())
|
|
313
|
-
}
|
|
314
|
-
modelEntity.lastSpeed = cruiseSpeed
|
|
315
|
-
|
|
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
|
-
}
|
|
274
|
+
const targetPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
275
|
+
modelEntity.currentPosition = Cesium.Cartesian3.clone(targetPosition, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
326
276
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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)
|
|
277
|
+
// 无人机实体和拖尾使用同一个目标点同步更新,不保留任何预测点,避免拖尾领先或回头找无人机。
|
|
278
|
+
modelEntity.entity.position = modelEntity.currentPosition
|
|
279
|
+
moveDroneTrail({
|
|
280
|
+
pointId,
|
|
281
|
+
newPosition: modelEntity.currentPosition,
|
|
282
|
+
mapId
|
|
283
|
+
})
|
|
368
284
|
|
|
369
285
|
return modelEntity
|
|
370
286
|
};
|