huweili-cesium 1.2.65 → 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 -98
- 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实例
|
|
@@ -260,112 +259,28 @@ export function movePointConfig(baseUrl) {
|
|
|
260
259
|
info.distance = options.distance || ''
|
|
261
260
|
info.receiveTime = options.receiveTime || ''
|
|
262
261
|
|
|
263
|
-
// ========== 实时位置获取开始 ==========
|
|
264
|
-
const positionProperty = modelEntity.positionProperty || modelEntity.entity?.position
|
|
265
|
-
let currentRealPosition = positionProperty?.getValue?.(currentTime, modelEntity.scratchPosition)
|
|
266
|
-
|
|
267
|
-
if (!currentRealPosition && modelEntity.currentPosition) {
|
|
268
|
-
// 插值属性取不到值时,回退到上一次缓存的真实位置。
|
|
269
|
-
currentRealPosition = Cesium.Cartesian3.clone(modelEntity.currentPosition, modelEntity.scratchPosition)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (!currentRealPosition) {
|
|
273
|
-
// 仍没有当前位置时,使用本次传入坐标作为起点。
|
|
274
|
-
currentRealPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height, modelEntity.scratchPosition)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// getValue 复用 scratchPosition,后续 targetPosition 也会复用其它 scratch,先把当前位置固定到独立对象,避免被后续计算覆盖。
|
|
278
|
-
currentRealPosition = Cesium.Cartesian3.clone(currentRealPosition, modelEntity.currentPosition || new Cesium.Cartesian3())
|
|
279
|
-
modelEntity.currentPosition = currentRealPosition
|
|
280
|
-
// ========== 实时位置获取结束 ==========
|
|
281
|
-
|
|
282
|
-
// ========== 保留轨迹 ==========
|
|
283
|
-
// 在飞行开始前,先记录当前点,保证轨迹不会从新目标点突兀开始。
|
|
284
|
-
moveDroneTrail({
|
|
285
|
-
pointId,
|
|
286
|
-
newPosition: currentRealPosition,
|
|
287
|
-
mapId
|
|
288
|
-
})
|
|
289
|
-
|
|
290
262
|
// ========== 终止当前所有飞行状态 ==========
|
|
291
|
-
//
|
|
263
|
+
// 本方案不再做平滑插值和断流续航:来一个新经纬度,无人机和拖尾就同步落到该经纬度。
|
|
292
264
|
if (modelEntity.flightEndListener) {
|
|
293
265
|
map.clock.onTick.removeEventListener(modelEntity.flightEndListener)
|
|
294
266
|
modelEntity.flightEndListener = null
|
|
295
267
|
}
|
|
296
268
|
|
|
297
269
|
modelEntity.isFlying = false
|
|
298
|
-
|
|
299
|
-
modelEntity.
|
|
300
|
-
modelEntity.
|
|
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
|
-
|
|
307
|
-
// ========== 计算新的飞行路径 ==========
|
|
308
|
-
const targetPosition = Cesium.Cartesian3.fromDegrees(lng, lat, height)
|
|
309
|
-
const distanceSquared = Cesium.Cartesian3.distanceSquared(currentRealPosition, targetPosition)
|
|
310
|
-
const distance = Math.sqrt(distanceSquared)
|
|
311
|
-
const cruiseSpeed = Math.max(speed, 0)
|
|
312
|
-
const moveDirection = distanceSquared >= MIN_DRONE_MOVE_DISTANCE_SQUARED
|
|
313
|
-
? Cesium.Cartesian3.normalize(
|
|
314
|
-
Cesium.Cartesian3.subtract(targetPosition, currentRealPosition, modelEntity.scratchTargetPosition),
|
|
315
|
-
new Cesium.Cartesian3()
|
|
316
|
-
)
|
|
317
|
-
: modelEntity.lastMoveDirection
|
|
318
|
-
|
|
319
|
-
if (moveDirection) {
|
|
320
|
-
modelEntity.lastMoveDirection = Cesium.Cartesian3.clone(moveDirection, modelEntity.lastMoveDirection || new Cesium.Cartesian3())
|
|
321
|
-
}
|
|
322
|
-
modelEntity.lastSpeed = cruiseSpeed
|
|
270
|
+
modelEntity.positionProperty = null
|
|
271
|
+
modelEntity.lastMoveDirection = null
|
|
272
|
+
modelEntity.lastSpeed = 0
|
|
323
273
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const flightEndTime = Cesium.JulianDate.addSeconds(currentTime, fastArriveDuration, modelEntity.scratchFlightEndTime)
|
|
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())
|
|
327
276
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
// currentPosition 必须只缓存无人机每帧真实显示位置,否则下一次更新拖尾时会读到未来目标点,导致轨迹跑到无人机前面。
|
|
336
|
-
|
|
337
|
-
const flightTickListener = (clock) => {
|
|
338
|
-
if (!modelEntity.isFlying) return
|
|
339
|
-
|
|
340
|
-
const isArriving = Cesium.JulianDate.compare(clock.currentTime, flightEndTime) < 0
|
|
341
|
-
let tickPosition = isArriving
|
|
342
|
-
? modelEntity.positionProperty.getValue(clock.currentTime, modelEntity.scratchPosition)
|
|
343
|
-
: targetPosition
|
|
344
|
-
|
|
345
|
-
if (!isArriving && modelEntity.lastMoveDirection && modelEntity.lastSpeed > 0) {
|
|
346
|
-
// 下一秒坐标迟迟不来时,按上一次航向和速度继续向前慢速插值飞行。
|
|
347
|
-
const extraSeconds = Math.max(0, Cesium.JulianDate.secondsDifference(clock.currentTime, flightEndTime))
|
|
348
|
-
const extraDistance = modelEntity.lastSpeed * extraSeconds
|
|
349
|
-
tickPosition = Cesium.Cartesian3.add(
|
|
350
|
-
targetPosition,
|
|
351
|
-
Cesium.Cartesian3.multiplyByScalar(modelEntity.lastMoveDirection, extraDistance, modelEntity.scratchTargetPosition),
|
|
352
|
-
modelEntity.scratchPosition
|
|
353
|
-
)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (!tickPosition) return
|
|
357
|
-
|
|
358
|
-
// 每帧缓存真实位置,并同步追加轨迹点。
|
|
359
|
-
modelEntity.currentPosition = Cesium.Cartesian3.clone(tickPosition, modelEntity.currentPosition)
|
|
360
|
-
moveDroneTrail({
|
|
361
|
-
pointId,
|
|
362
|
-
newPosition: modelEntity.currentPosition,
|
|
363
|
-
mapId
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
modelEntity.flightEndListener = flightTickListener
|
|
368
|
-
map.clock.onTick.addEventListener(flightTickListener)
|
|
277
|
+
// 无人机实体和拖尾使用同一个目标点同步更新,不保留任何预测点,避免拖尾领先或回头找无人机。
|
|
278
|
+
modelEntity.entity.position = modelEntity.currentPosition
|
|
279
|
+
moveDroneTrail({
|
|
280
|
+
pointId,
|
|
281
|
+
newPosition: modelEntity.currentPosition,
|
|
282
|
+
mapId
|
|
283
|
+
})
|
|
369
284
|
|
|
370
285
|
return modelEntity
|
|
371
286
|
};
|