@aibee/crc-bmap 0.0.31 → 0.0.33

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
@@ -160,6 +160,7 @@ function initControl(camera, domElement) {
160
160
  control.enableDamping = false;
161
161
  control.maxPolarAngle = 0;
162
162
  control.minPolarAngle = 0;
163
+ control.zoomSpeed = 2;
163
164
  return control;
164
165
  }
165
166
  function initShape(path, holePath = []) {
@@ -368,6 +369,11 @@ function setRectPosition(rect, x, y, w, h) {
368
369
  rect.setAttribute("height", `${h}`);
369
370
  }
370
371
 
372
+ // src/utils/sleep.ts
373
+ function sleepOnePromise() {
374
+ return Promise.resolve();
375
+ }
376
+
371
377
  // src/context.ts
372
378
  import {
373
379
  EventDispatcher as EventDispatcher5,
@@ -655,6 +661,9 @@ var Overlay = class extends EventDispatcher {
655
661
  const vector = this.getPosition();
656
662
  const { width, height } = this.context.clientSize;
657
663
  const { x, y } = vector3ToDevice(vector, this.context.camera, width, height);
664
+ if (this.clientPos.x === x && this.clientPos.y === y) {
665
+ return;
666
+ }
658
667
  this.clientPos = { x, y };
659
668
  this.div.style.left = `${x}px`;
660
669
  this.div.style.top = `${y}px`;
@@ -697,6 +706,11 @@ var Overlay = class extends EventDispatcher {
697
706
  return this.position;
698
707
  }
699
708
  }
709
+ get withinDisplayRange() {
710
+ const { x, y } = this.clientPos;
711
+ const { width, height } = this.context.clientSize;
712
+ return x >= 0 && x <= width && y >= 0 && y <= height;
713
+ }
700
714
  registryEvent() {
701
715
  this.context.addEventListener("update", this.onUpdate);
702
716
  }
@@ -768,13 +782,23 @@ var Poi = class extends Object3D4 {
768
782
  }
769
783
  });
770
784
  }
785
+ get withinDisplayRange() {
786
+ return this.overlay.withinDisplayRange;
787
+ }
771
788
  resetSize() {
772
- const { width, height } = this.overlay.div.getBoundingClientRect();
773
- this.size = {
774
- width,
775
- height
776
- };
777
- this._changePosition();
789
+ return __async(this, null, function* () {
790
+ const visible = this.overlay.visible;
791
+ this.setVisible(true);
792
+ yield sleepOnePromise();
793
+ const { width, height } = this.overlay.div.getBoundingClientRect();
794
+ this.size = {
795
+ width,
796
+ height
797
+ };
798
+ yield sleepOnePromise();
799
+ this._changePosition();
800
+ this.setVisible(visible);
801
+ });
778
802
  }
779
803
  get clientPos() {
780
804
  return this.overlay.clientPos;
@@ -934,8 +958,9 @@ var PoiLayer = class extends Layer {
934
958
  super(context);
935
959
  __publicField(this, "pois", []);
936
960
  __publicField(this, "debounceCollisionDetection");
961
+ __publicField(this, "timer", new Timer());
937
962
  __publicField(this, "onUpdate", () => {
938
- Promise.resolve().then(() => {
963
+ this.timer.requestAnimationFrame(() => {
939
964
  this.collisionDetection();
940
965
  });
941
966
  });
@@ -1022,10 +1047,7 @@ var PoiLayer = class extends Layer {
1022
1047
  collisionDetection() {
1023
1048
  const { clientSize: { width, height } } = this.context;
1024
1049
  const range = [];
1025
- const pois = this.pois.filter((item) => {
1026
- const { x, y } = item.clientPos;
1027
- return !(x < 0 || x > width || y < 0 || y > height);
1028
- });
1050
+ const pois = this.pois.filter((item) => item.withinDisplayRange);
1029
1051
  pois.forEach((item, index) => {
1030
1052
  const { left, right, top, bottom } = item.getBox();
1031
1053
  if (index === 0) {
@@ -1051,6 +1073,7 @@ var PoiLayer = class extends Layer {
1051
1073
  this.context.removeEventListener("update", this.onUpdate);
1052
1074
  }
1053
1075
  dispose() {
1076
+ this.timer.dispose();
1054
1077
  this.pois.forEach((item) => item.dispose());
1055
1078
  this.pois.length = 0;
1056
1079
  this.debounceCollisionDetection = () => {
@@ -2289,9 +2312,21 @@ var BMap = class extends EventDispatcher6 {
2289
2312
  __publicField(this, "svgLine");
2290
2313
  __publicField(this, "svgPolygon");
2291
2314
  __publicField(this, "basicZoom", 1);
2315
+ __publicField(this, "prevCameraZoom", 1);
2292
2316
  __publicField(this, "floorDataMap", /* @__PURE__ */ new Map());
2293
2317
  __publicField(this, "buildingGroundMap", /* @__PURE__ */ new Map());
2294
2318
  __publicField(this, "currentBuildGround", null);
2319
+ __publicField(this, "onControlChange", () => {
2320
+ const { camera: { zoom } } = this.context;
2321
+ if (zoom !== this.prevCameraZoom) {
2322
+ this.dispatchEvent({
2323
+ type: "zoom-change",
2324
+ basicZoom: this.basicZoom,
2325
+ cameraZoom: this.context.camera.zoom
2326
+ });
2327
+ this.prevCameraZoom = zoom;
2328
+ }
2329
+ });
2295
2330
  __publicField(this, "onKeydown", (e) => {
2296
2331
  if (this.polarKeys.includes(e.code)) {
2297
2332
  this.context.control.maxPolarAngle = this.config.control.maxPolar;
@@ -2417,6 +2452,7 @@ var BMap = class extends EventDispatcher6 {
2417
2452
  return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts, resource_type_list }) {
2418
2453
  const floorKey = this.getFloorKey({ brand, project, phase, building, floor, ts, resource_type_list });
2419
2454
  const curFloorData = this.floorDataMap.get(floorKey);
2455
+ this.context.control.removeEventListener("change", this.onControlChange);
2420
2456
  if (curFloorData) {
2421
2457
  const buildingKey = this.getBuildingKey({ brand, project, phase, building });
2422
2458
  this.currentBuildGround = this.buildingGroundMap.get(buildingKey) || null;
@@ -2429,6 +2465,8 @@ var BMap = class extends EventDispatcher6 {
2429
2465
  this.basicZoom = this.context.camera.zoom;
2430
2466
  this.context.control.minZoom = this.basicZoom;
2431
2467
  this.context.control.maxZoom = this.basicZoom * 25;
2468
+ this.context.control.addEventListener("change", this.onControlChange);
2469
+ this.onControlChange();
2432
2470
  } else {
2433
2471
  console.warn("[switchFloor error] [" + floor + "] \u697C\u5C42\u6CA1\u6709\u6570\u636E");
2434
2472
  }
@@ -2729,6 +2767,7 @@ export {
2729
2767
  setCirclePosition,
2730
2768
  setLineStartEnd,
2731
2769
  setRectPosition,
2770
+ sleepOnePromise,
2732
2771
  timeoutPromise,
2733
2772
  vector3ToDevice
2734
2773
  };