@aibee/crc-bmap 0.0.73 → 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() {
@@ -1308,13 +1309,7 @@ var PoiLayer = class extends Layer {
1308
1309
  */
1309
1310
  collisionDetection() {
1310
1311
  const range = [];
1311
- const pois = this.pois.filter((item) => {
1312
- if (item.visible && item.withinDisplayRange) {
1313
- return true;
1314
- } else {
1315
- item.parentSetVisible(false);
1316
- }
1317
- });
1312
+ const pois = this.pois.filter((item) => item.visible && item.withinDisplayRange);
1318
1313
  pois.forEach((item, index) => {
1319
1314
  const { left, right, top, bottom } = item.getBox();
1320
1315
  if (index === 0) {
@@ -2161,29 +2156,24 @@ var Selection = class extends EventDispatcher4 {
2161
2156
  }
2162
2157
  }
2163
2158
  });
2164
- if (!e.ctrlKey) {
2159
+ if (!(isMac ? e.metaKey : e.ctrlKey)) {
2165
2160
  this._list.clear();
2166
2161
  }
2167
2162
  graphics.forEach((item) => this._list.add(item));
2168
2163
  this.selectEnd();
2169
2164
  this.downPoint = null;
2170
2165
  });
2166
+ __publicField(this, "onPointerOut", (e) => {
2167
+ this.disableBoxSelection();
2168
+ });
2171
2169
  __publicField(this, "onKeyDown", (e) => {
2172
2170
  if (isControl(e.key)) {
2173
- this.isMultipleSelect = true;
2174
- this.boxSelection.setEnable(true);
2175
- this.prevPanStatus = this.context.control.enablePan;
2176
- this.prevRotateStatus = this.context.control.enableRotate;
2177
- this.context.control.enablePan = false;
2178
- this.context.control.enableRotate = false;
2171
+ this.enableBoxSelection();
2179
2172
  }
2180
2173
  });
2181
2174
  __publicField(this, "onKeyUp", (e) => {
2182
2175
  if (isControl(e.key)) {
2183
- this.isMultipleSelect = false;
2184
- this.boxSelection.setEnable(false);
2185
- this.context.control.enablePan = !!this.prevPanStatus;
2186
- this.context.control.enableRotate = !!this.prevRotateStatus;
2176
+ this.disableBoxSelection();
2187
2177
  }
2188
2178
  });
2189
2179
  __publicField(this, "onBoxSelected", ({ list }) => {
@@ -2200,19 +2190,42 @@ var Selection = class extends EventDispatcher4 {
2200
2190
  get list() {
2201
2191
  return this._list;
2202
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
+ }
2203
2212
  selectEnd() {
2204
2213
  this.dispatchEvent({ type: "select", graphics: [...this._list], isMultipleSelect: this.isMultipleSelect });
2205
2214
  }
2206
2215
  registryEvent() {
2207
- this.context.container.addEventListener("pointerdown", this.onPointerDown);
2208
- 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);
2209
2220
  window.addEventListener("keydown", this.onKeyDown);
2210
2221
  window.addEventListener("keyup", this.onKeyUp);
2211
2222
  this.boxSelection.addEventListener("selected", this.onBoxSelected);
2212
2223
  }
2213
2224
  unRegistryEvent() {
2214
- this.context.container.removeEventListener("pointerdown", this.onPointerDown);
2215
- 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);
2216
2229
  window.removeEventListener("keydown", this.onKeyDown);
2217
2230
  window.removeEventListener("keyup", this.onKeyUp);
2218
2231
  this.boxSelection.removeEventListener("selected", this.onBoxSelected);
@@ -2242,7 +2255,7 @@ var HoverHelper = class extends EventDispatcher5 {
2242
2255
  var _a;
2243
2256
  return (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.graphicMap.get(item.options.id);
2244
2257
  }).filter((graphic) => graphic && graphic.options.geometry.type === "point");
2245
- if (!graphics.length && !poiGraphics && this.curGraphics.size) {
2258
+ if (!graphics.length && !poiGraphics.length && this.curGraphics.size) {
2246
2259
  this.curGraphics.clear();
2247
2260
  this.handleHoverGraphicsChange();
2248
2261
  return;
@@ -2263,6 +2276,8 @@ var HoverHelper = class extends EventDispatcher5 {
2263
2276
  }
2264
2277
  const timer = this.timer.setTimeout(() => {
2265
2278
  this.curGraphics.add(graphic);
2279
+ this.graphicTimerMap.delete(graphic);
2280
+ this.timer.clearTimeout(timer);
2266
2281
  this.handleHoverGraphicsChange();
2267
2282
  }, time);
2268
2283
  this.graphicTimerMap.set(graphic, timer);
@@ -2753,14 +2768,7 @@ var Context = class extends EventDispatcher6 {
2753
2768
  duration + 500
2754
2769
  );
2755
2770
  }
2756
- /**
2757
- * 放大相机到物体占全屏
2758
- * @param object
2759
- * @param padding
2760
- * @param duration
2761
- * @returns
2762
- */
2763
- fitCameraToObject(object, padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2771
+ getFitCameraToObjectZoom(object, padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2764
2772
  const [top, right, bottom, left] = padding;
2765
2773
  const { clientSize: { width, height } } = this;
2766
2774
  const polar = this.control.getPolarAngle();
@@ -2781,7 +2789,23 @@ var Context = class extends EventDispatcher6 {
2781
2789
  const yScale = (height - top - bottom) / size.y;
2782
2790
  const scale = Math.min(xScale, yScale);
2783
2791
  const center2 = new Vector312((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
2784
- 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
+ }
2785
2809
  }
2786
2810
  fitCameraToGround(padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
2787
2811
  if (this.currentFloor && this.currentFloor.hasElement) {
@@ -2980,8 +3004,8 @@ var BMap = class extends EventDispatcher7 {
2980
3004
  this.context.control.maxZoom = Infinity;
2981
3005
  this.context.camera.zoom = 1;
2982
3006
  this.context.setAzimuthalAngle(0, 0);
2983
- this.context.fitCameraToGround(void 0, 0);
2984
- this.basicZoom = this.context.camera.zoom;
3007
+ const basicZoom = this.context.getFitCameraToGroundZoom(void 0, 0);
3008
+ this.basicZoom = basicZoom || 0;
2985
3009
  this.context.control.minZoom = this.basicZoom;
2986
3010
  this.context.control.maxZoom = this.basicZoom * 25;
2987
3011
  this.context.camera.zoom = zoom;
@@ -3158,9 +3182,9 @@ var BMap = class extends EventDispatcher7 {
3158
3182
  position: graphic.getPosition().setZ(0.1)
3159
3183
  }));
3160
3184
  if (model) {
3161
- const dir = getLongestSideDir(graphic.options.geometry.cds[0]);
3162
- const angleY = dir.angleTo(new Vector313(0, 1, 0));
3163
- 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);
3164
3188
  }
3165
3189
  }
3166
3190
  }
@@ -3212,11 +3236,13 @@ var BMap = class extends EventDispatcher7 {
3212
3236
  * @param duration
3213
3237
  */
3214
3238
  translateElementToCenterX(ele, duration = 500) {
3215
- const { y, z } = this.context.camera.position;
3216
- const position = ele.getPosition();
3217
- position.setY(y);
3218
- position.setZ(z);
3219
- return this.context.setCameraPosition(position, duration);
3239
+ return __async(this, null, function* () {
3240
+ const { y, z } = this.context.control.target;
3241
+ const position = ele.getPosition();
3242
+ position.setY(y);
3243
+ position.setZ(z);
3244
+ yield this.context.setCameraPosition(position, duration);
3245
+ });
3220
3246
  }
3221
3247
  /**
3222
3248
  * 获取物体的屏幕坐标