@aibee/crc-bmap 0.0.74 → 0.0.75

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
@@ -44,7 +44,7 @@ var __async = (__this, __arguments, generator) => {
44
44
  };
45
45
 
46
46
  // src/bmap.ts
47
- import { EventDispatcher as EventDispatcher7, Vector3 as Vector313 } from "three";
47
+ import { EventDispatcher as EventDispatcher7 } from "three";
48
48
 
49
49
  // src/utils/timer.ts
50
50
  var Timer = class {
@@ -991,18 +991,13 @@ var Poi = class extends EventDispatcher2 {
991
991
  return __async(this, null, function* () {
992
992
  yield sleepOnePromise();
993
993
  const { width, height } = this.div.getBoundingClientRect();
994
- const { boxScale } = this.context.config.poi;
995
994
  this.size = {
996
- width: width * boxScale,
997
- height: height * boxScale
995
+ width: width + 2,
996
+ height: height + 2
998
997
  };
999
998
  });
1000
999
  }
1001
1000
  renderHelperBox() {
1002
- const div = document.createElement("div");
1003
- const box = this.getBox();
1004
- div.style.cssText = `position: absolute; top: ${box.top}px;left: ${box.left}px;width: ${box.right - box.left}px;height: ${box.bottom - box.top}px;border: 1px solid red;`;
1005
- this.context.container.appendChild(div);
1006
1001
  }
1007
1002
  get clientPos() {
1008
1003
  return this.overlay.clientPos;
@@ -1066,7 +1061,6 @@ var Poi = class extends EventDispatcher2 {
1066
1061
  img.style.border = `${this.options.icon_border.width}px solid ${this.options.icon_border.color}`;
1067
1062
  }
1068
1063
  img.onload = () => {
1069
- this._changePosition();
1070
1064
  this.resetSize();
1071
1065
  };
1072
1066
  this.img = img;
@@ -1094,8 +1088,7 @@ var Poi = class extends EventDispatcher2 {
1094
1088
  if (this.showTextStatus === visible) {
1095
1089
  return;
1096
1090
  }
1097
- console.log("visible", visible);
1098
- this.textDiv.style.display = visible ? "block" : "none";
1091
+ this.textDiv.style.visibility = visible ? "visible" : "hidden";
1099
1092
  this.showTextStatus = visible;
1100
1093
  }
1101
1094
  }
@@ -1105,21 +1098,29 @@ var Poi = class extends EventDispatcher2 {
1105
1098
  }
1106
1099
  this.changeOverlayVisible(visible);
1107
1100
  }
1108
- getBox() {
1101
+ getBox(boxScale = this.context.config.poi.boxScale) {
1109
1102
  const { width, height } = this.size;
1103
+ const w = width * boxScale;
1104
+ const h = height * boxScale;
1110
1105
  const { x, y } = this.overlay.clientPos;
1111
1106
  return {
1112
- left: x - width / 2,
1113
- right: x + width / 2,
1114
- top: this.options.icon ? y - height : y - height / 2,
1115
- bottom: this.options.icon ? y : y + height / 2
1107
+ left: x - w / 2,
1108
+ right: x + w / 2,
1109
+ top: this.options.icon ? y - h : y - h / 2,
1110
+ bottom: this.options.icon ? y : y + h / 2
1116
1111
  };
1117
1112
  }
1113
+ getOriginBox() {
1114
+ return this.getBox(1);
1115
+ }
1118
1116
  isContain(x, y) {
1119
1117
  if (!this.overlay.visible) {
1120
1118
  return false;
1121
1119
  }
1122
- const box = this.getBox();
1120
+ if (!this.visible) {
1121
+ return false;
1122
+ }
1123
+ const box = this.getOriginBox();
1123
1124
  return x >= box.left && x <= box.right && y >= box.top && y <= box.bottom;
1124
1125
  }
1125
1126
  dispose() {
@@ -2155,29 +2156,24 @@ var Selection = class extends EventDispatcher4 {
2155
2156
  }
2156
2157
  }
2157
2158
  });
2158
- if (!e.ctrlKey) {
2159
+ if (!(isMac ? e.metaKey : e.ctrlKey)) {
2159
2160
  this._list.clear();
2160
2161
  }
2161
2162
  graphics.forEach((item) => this._list.add(item));
2162
2163
  this.selectEnd();
2163
2164
  this.downPoint = null;
2164
2165
  });
2166
+ __publicField(this, "onPointerOut", (e) => {
2167
+ this.disableBoxSelection();
2168
+ });
2165
2169
  __publicField(this, "onKeyDown", (e) => {
2166
2170
  if (isControl(e.key)) {
2167
- this.isMultipleSelect = true;
2168
- this.boxSelection.setEnable(true);
2169
- this.prevPanStatus = this.context.control.enablePan;
2170
- this.prevRotateStatus = this.context.control.enableRotate;
2171
- this.context.control.enablePan = false;
2172
- this.context.control.enableRotate = false;
2171
+ this.enableBoxSelection();
2173
2172
  }
2174
2173
  });
2175
2174
  __publicField(this, "onKeyUp", (e) => {
2176
2175
  if (isControl(e.key)) {
2177
- this.isMultipleSelect = false;
2178
- this.boxSelection.setEnable(false);
2179
- this.context.control.enablePan = !!this.prevPanStatus;
2180
- this.context.control.enableRotate = !!this.prevRotateStatus;
2176
+ this.disableBoxSelection();
2181
2177
  }
2182
2178
  });
2183
2179
  __publicField(this, "onBoxSelected", ({ list }) => {
@@ -2194,19 +2190,42 @@ var Selection = class extends EventDispatcher4 {
2194
2190
  get list() {
2195
2191
  return this._list;
2196
2192
  }
2193
+ enableBoxSelection() {
2194
+ if (this.isMultipleSelect) {
2195
+ return;
2196
+ }
2197
+ this.isMultipleSelect = true;
2198
+ this.boxSelection.setEnable(true);
2199
+ this.prevPanStatus = this.context.control.enablePan;
2200
+ this.prevRotateStatus = this.context.control.enableRotate;
2201
+ this.context.control.enablePan = false;
2202
+ this.context.control.enableRotate = false;
2203
+ }
2204
+ disableBoxSelection() {
2205
+ if (this.isMultipleSelect) {
2206
+ this.isMultipleSelect = false;
2207
+ this.boxSelection.setEnable(false);
2208
+ this.context.control.enablePan = !!this.prevPanStatus;
2209
+ this.context.control.enableRotate = !!this.prevRotateStatus;
2210
+ }
2211
+ }
2197
2212
  selectEnd() {
2198
2213
  this.dispatchEvent({ type: "select", graphics: [...this._list], isMultipleSelect: this.isMultipleSelect });
2199
2214
  }
2200
2215
  registryEvent() {
2201
- this.context.container.addEventListener("pointerdown", this.onPointerDown);
2202
- this.context.container.addEventListener("pointerup", this.onPointerUp);
2216
+ this.context.container.addEventListener("pointerdown", this.onPointerDown, true);
2217
+ this.context.container.addEventListener("pointerup", this.onPointerUp, true);
2218
+ this.context.container.addEventListener("pointerout", this.onPointerOut);
2219
+ this.context.container.addEventListener("pointercancel", this.onPointerOut);
2203
2220
  window.addEventListener("keydown", this.onKeyDown);
2204
2221
  window.addEventListener("keyup", this.onKeyUp);
2205
2222
  this.boxSelection.addEventListener("selected", this.onBoxSelected);
2206
2223
  }
2207
2224
  unRegistryEvent() {
2208
- this.context.container.removeEventListener("pointerdown", this.onPointerDown);
2209
- this.context.container.removeEventListener("pointerup", this.onPointerUp);
2225
+ this.context.container.removeEventListener("pointerdown", this.onPointerDown, true);
2226
+ this.context.container.removeEventListener("pointerup", this.onPointerUp, true);
2227
+ this.context.container.removeEventListener("pointerout", this.onPointerOut);
2228
+ this.context.container.removeEventListener("pointercancel", this.onPointerOut);
2210
2229
  window.removeEventListener("keydown", this.onKeyDown);
2211
2230
  window.removeEventListener("keyup", this.onKeyUp);
2212
2231
  this.boxSelection.removeEventListener("selected", this.onBoxSelected);
@@ -2236,7 +2255,7 @@ var HoverHelper = class extends EventDispatcher5 {
2236
2255
  var _a;
2237
2256
  return (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.graphicMap.get(item.options.id);
2238
2257
  }).filter((graphic) => graphic && graphic.options.geometry.type === "point");
2239
- if (!graphics.length && !poiGraphics && this.curGraphics.size) {
2258
+ if (!graphics.length && !poiGraphics.length && this.curGraphics.size) {
2240
2259
  this.curGraphics.clear();
2241
2260
  this.handleHoverGraphicsChange();
2242
2261
  return;
@@ -2257,6 +2276,8 @@ var HoverHelper = class extends EventDispatcher5 {
2257
2276
  }
2258
2277
  const timer = this.timer.setTimeout(() => {
2259
2278
  this.curGraphics.add(graphic);
2279
+ this.graphicTimerMap.delete(graphic);
2280
+ this.timer.clearTimeout(timer);
2260
2281
  this.handleHoverGraphicsChange();
2261
2282
  }, time);
2262
2283
  this.graphicTimerMap.set(graphic, timer);
@@ -2747,14 +2768,7 @@ var Context = class extends EventDispatcher6 {
2747
2768
  duration + 500
2748
2769
  );
2749
2770
  }
2750
- /**
2751
- * 放大相机到物体占全屏
2752
- * @param object
2753
- * @param padding
2754
- * @param duration
2755
- * @returns
2756
- */
2757
- fitCameraToObject(object, padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2771
+ getFitCameraToObjectZoom(object, padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2758
2772
  const [top, right, bottom, left] = padding;
2759
2773
  const { clientSize: { width, height } } = this;
2760
2774
  const polar = this.control.getPolarAngle();
@@ -2775,7 +2789,23 @@ var Context = class extends EventDispatcher6 {
2775
2789
  const yScale = (height - top - bottom) / size.y;
2776
2790
  const scale = Math.min(xScale, yScale);
2777
2791
  const center2 = new Vector312((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
2778
- return this.setZoom(scale * this.camera.zoom, center2, duration);
2792
+ return { zoom: scale * this.camera.zoom, center: center2 };
2793
+ }
2794
+ /**
2795
+ * 放大相机到物体占全屏
2796
+ * @param object
2797
+ * @param padding
2798
+ * @param duration
2799
+ * @returns
2800
+ */
2801
+ fitCameraToObject(object, padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2802
+ const { zoom, center: center2 } = this.getFitCameraToObjectZoom(object, padding, duration, force2DView);
2803
+ return this.setZoom(zoom, center2, duration);
2804
+ }
2805
+ getFitCameraToGroundZoom(padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2806
+ if (this.currentFloor && this.currentFloor.hasElement) {
2807
+ return this.getFitCameraToObjectZoom(this.currentFloor.groundUpper, padding, duration, force2DView).zoom;
2808
+ }
2779
2809
  }
2780
2810
  fitCameraToGround(padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2781
2811
  if (this.currentFloor && this.currentFloor.hasElement) {
@@ -2974,8 +3004,8 @@ var BMap = class extends EventDispatcher7 {
2974
3004
  this.context.control.maxZoom = Infinity;
2975
3005
  this.context.camera.zoom = 1;
2976
3006
  this.context.setAzimuthalAngle(0, 0);
2977
- this.context.fitCameraToGround(void 0, 0);
2978
- this.basicZoom = this.context.camera.zoom;
3007
+ const basicZoom = this.context.getFitCameraToGroundZoom(void 0, 0);
3008
+ this.basicZoom = basicZoom || 0;
2979
3009
  this.context.control.minZoom = this.basicZoom;
2980
3010
  this.context.control.maxZoom = this.basicZoom * 25;
2981
3011
  this.context.camera.zoom = zoom;
@@ -3152,9 +3182,9 @@ var BMap = class extends EventDispatcher7 {
3152
3182
  position: graphic.getPosition().setZ(0.1)
3153
3183
  }));
3154
3184
  if (model) {
3155
- const dir = getLongestSideDir(graphic.options.geometry.cds[0]);
3156
- const angleY = dir.angleTo(new Vector313(0, 1, 0));
3157
- model.rotateZ(angleY);
3185
+ const { facilityAngle = 0, facilityXScale = 1, facilityYScale = 1 } = graphic.options.userData;
3186
+ model.rotateZ((180 - facilityAngle) / 180 * Math.PI);
3187
+ model.scale.set(facilityXScale, facilityYScale, 1);
3158
3188
  }
3159
3189
  }
3160
3190
  }