@aibee/crc-bmap 0.6.4 → 0.6.6

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/lib/bmap.esm.js CHANGED
@@ -6499,7 +6499,7 @@ var Control = class extends MapControls {
6499
6499
  * @param center
6500
6500
  * @returns
6501
6501
  */
6502
- setZoomByDuration(zoom, center2, force = false, duration = 500) {
6502
+ async setZoomByDuration(zoom, center2, force = false, duration = 500) {
6503
6503
  const lookAtVector = this.getCameraLookAt();
6504
6504
  const start = {
6505
6505
  zoom: this.camera.zoom,
@@ -8408,6 +8408,7 @@ var PositionNavigation = class extends EventDispatcher10 {
8408
8408
  this.offset = false;
8409
8409
  this.reset = false;
8410
8410
  this.routeIndex = 0;
8411
+ this.pointIndex = 0;
8411
8412
  if (!paths.length) {
8412
8413
  return;
8413
8414
  }
@@ -8441,7 +8442,6 @@ var PositionNavigation = class extends EventDispatcher10 {
8441
8442
  ...allPath.slice(routeIndex + 1)
8442
8443
  ];
8443
8444
  const { distance, closestPoint, index, i } = paths.reduce((obj, cur, index2) => {
8444
- console.log("cur", cur.floor, floor);
8445
8445
  if (cur.floor !== floor) {
8446
8446
  return obj;
8447
8447
  }
@@ -8584,6 +8584,7 @@ var PositionNavigation = class extends EventDispatcher10 {
8584
8584
  }
8585
8585
  getNavigationInfo() {
8586
8586
  const { total: remainDistance, curRoute: curRouteRemainDistance } = this.getRemainDistance();
8587
+ console.log(remainDistance, curRouteRemainDistance, this.paths);
8587
8588
  const nextDirInfo = this.getNextDirDistance();
8588
8589
  if (!nextDirInfo) {
8589
8590
  return null;
@@ -8616,6 +8617,150 @@ var PositionNavigation = class extends EventDispatcher10 {
8616
8617
  }
8617
8618
  };
8618
8619
 
8620
+ // src/utils/taskQueue.ts
8621
+ import { EventDispatcher as EventDispatcher11 } from "three";
8622
+ var TaskQueue = class extends EventDispatcher11 {
8623
+ // 任务队列
8624
+ _task = [];
8625
+ // 是否开始执行任务
8626
+ started = false;
8627
+ // 当前正在执行的任务
8628
+ activeTask = null;
8629
+ _id = 0;
8630
+ constructor(start = true) {
8631
+ super();
8632
+ if (start) {
8633
+ this.start();
8634
+ }
8635
+ }
8636
+ /**
8637
+ * 判断任务是否有效
8638
+ * @param task
8639
+ * @return {boolean}
8640
+ * @private
8641
+ */
8642
+ _isEffectiveTask(task) {
8643
+ return task && typeof task.run === "function";
8644
+ }
8645
+ /**
8646
+ * 根据tid获取元素的位置
8647
+ * @param tid
8648
+ * @return {number}
8649
+ * @private
8650
+ */
8651
+ _getIndexByTid(tid) {
8652
+ return this._task.findIndex((task) => task.tid === tid);
8653
+ }
8654
+ /**
8655
+ * 创建任务
8656
+ * @param task
8657
+ * @private
8658
+ */
8659
+ _createTask(task) {
8660
+ if (this._isEffectiveTask(task)) {
8661
+ return { ...task, tid: ++this._id, meta: task.meta || {} };
8662
+ }
8663
+ return false;
8664
+ }
8665
+ get task() {
8666
+ return [...this._task];
8667
+ }
8668
+ /**
8669
+ * 获取当前队列中的任务
8670
+ */
8671
+ getTasks() {
8672
+ return [...this._task];
8673
+ }
8674
+ /**
8675
+ * 添加任务
8676
+ * @param task
8677
+ * @return
8678
+ */
8679
+ add(task) {
8680
+ if (this._isEffectiveTask(task)) {
8681
+ const $task = this._createTask(task);
8682
+ this._task.push($task);
8683
+ if (this.started && !this.activeTask) {
8684
+ this.start();
8685
+ }
8686
+ return $task.tid;
8687
+ }
8688
+ return false;
8689
+ }
8690
+ /**
8691
+ * 替换队列中的某个任务
8692
+ * @param id
8693
+ * @param task
8694
+ */
8695
+ replace(id, task) {
8696
+ if (!this._isEffectiveTask(task)) {
8697
+ console.warn("[TaskQueue] replace\u65B9\u6CD5\u4F20\u5165\u7684task\u53C2\u6570\u683C\u5F0F\u4E0D\u6B63\u786E");
8698
+ return false;
8699
+ }
8700
+ const index = this._getIndexByTid(id);
8701
+ if (index === -1) {
8702
+ console.warn(`[TaskQueue] \u6CA1\u6709\u627E\u5230id=${id}\u7684\u4EFB\u52A1`);
8703
+ return false;
8704
+ }
8705
+ const $task = this._createTask(task);
8706
+ this._task.splice(index, 1, $task);
8707
+ return $task.tid;
8708
+ }
8709
+ /**
8710
+ * 根据id删除对应的task
8711
+ * @param id
8712
+ */
8713
+ remove(id) {
8714
+ const index = this._getIndexByTid(id);
8715
+ if (index === -1) {
8716
+ console.warn(`[TaskQueue] remove\u65B9\u6CD5\u4F20\u5165\u7684id\uFF1A${id}\u627E\u4E0D\u5230\u5BF9\u5E94\u7684task`);
8717
+ return false;
8718
+ }
8719
+ this._task.splice(index, 1);
8720
+ return true;
8721
+ }
8722
+ /**
8723
+ * 清空队列
8724
+ */
8725
+ clear() {
8726
+ this._task.length = 0;
8727
+ }
8728
+ /**
8729
+ * 开始执行任务,默认在构造函数中执行
8730
+ */
8731
+ start() {
8732
+ this.started = true;
8733
+ if (!this.activeTask && this._task.length) {
8734
+ this.exec();
8735
+ }
8736
+ }
8737
+ /**
8738
+ * 停止执行队列中的任务,不包括当前执行中的任务
8739
+ */
8740
+ stop() {
8741
+ this.started = false;
8742
+ }
8743
+ /**
8744
+ * 从任务队列中的第一个任务开始执行
8745
+ */
8746
+ async exec() {
8747
+ if (!this.started || !this._task.length) {
8748
+ return false;
8749
+ }
8750
+ const $task = this._task.shift();
8751
+ this.activeTask = $task;
8752
+ this.dispatchEvent({ type: "active-task-start", task: $task });
8753
+ try {
8754
+ await $task.run();
8755
+ } catch (e) {
8756
+ console.warn("[task run err]", e, $task);
8757
+ }
8758
+ this.activeTask = null;
8759
+ this.dispatchEvent({ type: "active-task-end", task: $task });
8760
+ return this.exec();
8761
+ }
8762
+ };
8763
+
8619
8764
  // src/plugins/navigation/navigation.ts
8620
8765
  var defaultConfig4 = {
8621
8766
  path: {},
@@ -8647,7 +8792,8 @@ var Navigation = class extends Plugin {
8647
8792
  movedDistance = 0;
8648
8793
  pathStart = [0, 0];
8649
8794
  tweenUtil = new TweenUtil();
8650
- toPositionPromise;
8795
+ taskQueue = new TaskQueue();
8796
+ // toPositionPromise?: Promise<any> | null
8651
8797
  // 处理路线动画
8652
8798
  animationPathOptions = {
8653
8799
  cPathIndex: 0
@@ -8695,15 +8841,24 @@ var Navigation = class extends Plugin {
8695
8841
  if (info.routeIndex !== this.curPathIndex) {
8696
8842
  return;
8697
8843
  }
8698
- if (!this.toPositionPromise) {
8699
- this.toPositionPromise = this.toPositionBySpeed(info.pos, this.options.speed);
8700
- } else {
8701
- this.toPositionPromise.finally(() => {
8702
- return this.toPositionBySpeed(info.pos, this.options.speed);
8703
- });
8704
- }
8844
+ this.toPositionByTask(info.pos);
8705
8845
  }
8706
8846
  };
8847
+ toPositionByTask(pos) {
8848
+ const tasks = this.taskQueue.getTasks();
8849
+ const tid = tasks.find((item) => item.meta.type === "toPosition")?.tid;
8850
+ const newTask = {
8851
+ run: () => this.toPositionBySpeed(pos, this.options.speed),
8852
+ meta: {
8853
+ type: "toPosition"
8854
+ }
8855
+ };
8856
+ if (tid) {
8857
+ this.taskQueue.replace(tid, newTask);
8858
+ } else {
8859
+ this.taskQueue.add(newTask);
8860
+ }
8861
+ }
8707
8862
  pauseAnimation() {
8708
8863
  this.tweenUtil.pause();
8709
8864
  this.positionNavigation.tweenUtil.pause();
@@ -8714,7 +8869,8 @@ var Navigation = class extends Plugin {
8714
8869
  }
8715
8870
  clearTween() {
8716
8871
  this.tweenUtil.clear();
8717
- this.toPositionPromise = null;
8872
+ this.taskQueue.clear();
8873
+ this.bmap.context.control.enabled = true;
8718
8874
  }
8719
8875
  unRegistryEvent() {
8720
8876
  this.bmap.context.removeEventListener("update", this.onUpdate);
@@ -8762,7 +8918,6 @@ var Navigation = class extends Plugin {
8762
8918
  }
8763
8919
  onSwitchFloor = ({ data: { curFloor } }) => {
8764
8920
  this.clearTween();
8765
- this.toPositionPromise = null;
8766
8921
  if (this.paths[this.curPathIndex]) {
8767
8922
  const curFloorPathData = this.paths[this.curPathIndex];
8768
8923
  this.setCurFloorPath(curFloorPathData ?? null);
@@ -8880,7 +9035,7 @@ var Navigation = class extends Plugin {
8880
9035
  }
8881
9036
  const { control } = this.bmap.context;
8882
9037
  const time = duration / Math.PI * 6 * diffAngle;
8883
- return new Promise((resolve) => {
9038
+ return timeoutPromise(new Promise((resolve) => {
8884
9039
  const start = { azimuthal: control.getAzimuthalAngle() };
8885
9040
  const end = { azimuthal: angle };
8886
9041
  const tween = new Tween4(start, this.tweenUtil.group).to(end, time).easing(Easing.Quadratic.InOut).onUpdate(async () => {
@@ -8896,14 +9051,30 @@ var Navigation = class extends Plugin {
8896
9051
  }).onStart(() => {
8897
9052
  control.enabled = false;
8898
9053
  }).start();
9054
+ }), time + 500).finally(() => {
9055
+ this.bmap.context.control.enabled = true;
8899
9056
  });
8900
9057
  }
8901
9058
  async initNavigationCamera(duration = 1e3) {
8902
- this.clearTween();
8903
- this.bmap.context.control.clearTween();
8904
- await this.initCameraZoom(duration / 2);
8905
- await this.changeCameraToPathUp(duration / 4);
8906
- await this.translateCameraToStartPoi(duration / 4);
9059
+ const tasks = this.taskQueue.getTasks();
9060
+ const tid = tasks.find((item) => item.meta.type === "initNavigationCamera")?.tid;
9061
+ const newTask = {
9062
+ run: () => timeoutPromise((async () => {
9063
+ await this.initCameraZoom(duration / 2);
9064
+ await this.changeCameraToPathUp(duration / 4);
9065
+ await this.translateCameraToStartPoi(duration / 4);
9066
+ })(), duration + 500).finally(() => {
9067
+ this.bmap.context.control.enabled = true;
9068
+ }),
9069
+ meta: {
9070
+ type: "initNavigationCamera"
9071
+ }
9072
+ };
9073
+ if (tid) {
9074
+ this.taskQueue.replace(tid, newTask);
9075
+ } else {
9076
+ this.taskQueue.add(newTask);
9077
+ }
8907
9078
  }
8908
9079
  async translateCameraToStartPoi(duration = 100) {
8909
9080
  if (!this.startPoi) {
@@ -8955,7 +9126,9 @@ var Navigation = class extends Plugin {
8955
9126
  }).start();
8956
9127
  }),
8957
9128
  duration + 500
8958
- );
9129
+ ).then(() => {
9130
+ this.bmap.context.control.enabled = true;
9131
+ });
8959
9132
  }
8960
9133
  async initCameraZoom(duration = 100) {
8961
9134
  if (!this.startPoi) {
@@ -8969,7 +9142,9 @@ var Navigation = class extends Plugin {
8969
9142
  zoom,
8970
9143
  this.startPoi.position,
8971
9144
  duration
8972
- );
9145
+ ).finally(() => {
9146
+ this.bmap.context.control.enabled = true;
9147
+ });
8973
9148
  }
8974
9149
  // 根据定位 实时导航
8975
9150
  toPosition(floor, pos) {
@@ -9011,7 +9186,9 @@ var Navigation = class extends Plugin {
9011
9186
  this.tweenUtil.remove(tween);
9012
9187
  resolve(true);
9013
9188
  }).start();
9014
- }), time * 1e3 + 500);
9189
+ }), time * 1e3 + 500).finally(() => {
9190
+ this.bmap.context.control.enabled = true;
9191
+ });
9015
9192
  }
9016
9193
  async moveDistance(distance, tween) {
9017
9194
  this.movedDistance = distance;
@@ -9127,7 +9304,7 @@ var MulFloors = class extends Plugin {
9127
9304
  };
9128
9305
 
9129
9306
  // src/plugins/nav-path/nav-path.ts
9130
- import { EventDispatcher as EventDispatcher11 } from "three";
9307
+ import { EventDispatcher as EventDispatcher12 } from "three";
9131
9308
 
9132
9309
  // inline-worker:__inline-worker
9133
9310
  function inlineWorker(scriptText) {
@@ -9144,7 +9321,7 @@ function Worker2() {
9144
9321
  }
9145
9322
 
9146
9323
  // src/plugins/nav-path/nav-path.ts
9147
- var NavPath = class extends EventDispatcher11 {
9324
+ var NavPath = class extends EventDispatcher12 {
9148
9325
  worker = Worker2();
9149
9326
  initRoadStatus = false;
9150
9327
  constructor() {
@@ -9194,7 +9371,7 @@ var NavPath = class extends EventDispatcher11 {
9194
9371
  };
9195
9372
 
9196
9373
  // src/plugins/cr-nav-path/cr-nav-path.ts
9197
- import { EventDispatcher as EventDispatcher12 } from "three";
9374
+ import { EventDispatcher as EventDispatcher13 } from "three";
9198
9375
 
9199
9376
  // src/plugins/cr-nav-path/cr-path.worker.ts
9200
9377
  function Worker3() {
@@ -9202,7 +9379,7 @@ function Worker3() {
9202
9379
  }
9203
9380
 
9204
9381
  // src/plugins/cr-nav-path/cr-nav-path.ts
9205
- var CrNavPath = class extends EventDispatcher12 {
9382
+ var CrNavPath = class extends EventDispatcher13 {
9206
9383
  worker = Worker3();
9207
9384
  initRoadStatus = false;
9208
9385
  constructor() {
@@ -9540,12 +9717,12 @@ var BMapSelect = class extends Plugin {
9540
9717
 
9541
9718
  // src/plugins/pdr-position/sensor.ts
9542
9719
  import { cloneDeep as cloneDeep4, isNil, throttle as throttle2 } from "lodash";
9543
- import { EventDispatcher as EventDispatcher13 } from "three";
9720
+ import { EventDispatcher as EventDispatcher14 } from "three";
9544
9721
  var defaultSensorOptions = {
9545
9722
  time: 1e3,
9546
9723
  elements: ["compass" /* COMPASS */, "deviceMotion" /* DEVICE_MOTION */, "acceleration" /* ACCELERATION */, "gps" /* GPS */]
9547
9724
  };
9548
- var Sensor = class extends EventDispatcher13 {
9725
+ var Sensor = class extends EventDispatcher14 {
9549
9726
  options;
9550
9727
  gpsTimer = null;
9551
9728
  data = [];
@@ -9677,7 +9854,7 @@ var Sensor = class extends EventDispatcher13 {
9677
9854
  };
9678
9855
 
9679
9856
  // src/plugins/pdr-position/position.ts
9680
- import { EventDispatcher as EventDispatcher14 } from "three";
9857
+ import { EventDispatcher as EventDispatcher15 } from "three";
9681
9858
 
9682
9859
  // src/plugins/pdr-position/utils.ts
9683
9860
  function gaussLikelihood(avg, std) {
@@ -10543,7 +10720,7 @@ var PositioningSystem = class {
10543
10720
  };
10544
10721
 
10545
10722
  // src/plugins/pdr-position/position.ts
10546
- var PdrPosition = class extends EventDispatcher14 {
10723
+ var PdrPosition = class extends EventDispatcher15 {
10547
10724
  sensor;
10548
10725
  pdr;
10549
10726
  _pause = false;