@aibee/crc-bmap 0.0.12 → 0.0.14

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
@@ -178,7 +178,7 @@ function initDirectionalLight(color = 16777215, intensity = 1) {
178
178
  directionalLight.castShadow = true;
179
179
  directionalLight.shadow.radius = 8;
180
180
  directionalLight.shadow.bias = -1e-3;
181
- directionalLight.shadow.mapSize.set(64, 64);
181
+ directionalLight.shadow.mapSize.set(256, 256);
182
182
  directionalLight.shadow.camera.left = -200;
183
183
  directionalLight.shadow.camera.right = 200;
184
184
  directionalLight.shadow.camera.top = 200;
@@ -373,10 +373,10 @@ function setRectPosition(rect, x, y, w, h) {
373
373
  import {
374
374
  EventDispatcher as EventDispatcher5,
375
375
  Box2,
376
- Vector3 as Vector37,
376
+ Vector3 as Vector38,
377
377
  Vector2 as Vector23,
378
378
  Raycaster as Raycaster3,
379
- Box3 as Box34,
379
+ Box3 as Box35,
380
380
  Color as Color4,
381
381
  AmbientLight as AmbientLight2
382
382
  } from "three";
@@ -538,8 +538,8 @@ var Graphic = class extends Object3D {
538
538
  }
539
539
  const intersects = raycaster.intersectObject(this.mesh);
540
540
  if (intersects[0]) {
541
- const position = intersects[0].point;
542
- return position;
541
+ const { point: position, distance } = intersects[0];
542
+ return { position, distance };
543
543
  }
544
544
  return false;
545
545
  }
@@ -587,8 +587,12 @@ var Shadow = class extends Object3D2 {
587
587
  changeLightColor(color) {
588
588
  this.directionalLight.color = new Color3(color);
589
589
  }
590
+ setPosition(position) {
591
+ this.position.copy(position);
592
+ this.directionalLight.position.set(-position.x / 2, -position.y / 2, 100);
593
+ }
590
594
  // 创建平面白色
591
- initPlane(width = 1e4, height = 1e4) {
595
+ initPlane(width = 1e3, height = 1e3) {
592
596
  const geometry = new PlaneGeometry(width, height);
593
597
  const material = new ShadowMaterial({
594
598
  transparent: true,
@@ -654,6 +658,9 @@ var Overlay = class extends EventDispatcher {
654
658
  setVisible(visible, display = "block") {
655
659
  this.div.style.display = visible ? display : "none";
656
660
  }
661
+ setOpacity(opacity) {
662
+ this.div.style.opacity = `${opacity}`;
663
+ }
657
664
  getPosition() {
658
665
  if (this.element) {
659
666
  if (typeof this.element.getPosition === "function") {
@@ -684,13 +691,14 @@ var Overlay = class extends EventDispatcher {
684
691
  var defaultOptions2 = {
685
692
  text: "",
686
693
  level: 1,
687
- collision_enable: true
694
+ collision_enable: true,
695
+ opacity: 1
688
696
  };
689
697
  var Poi = class extends Object3D4 {
690
698
  constructor(context, options) {
691
699
  super();
692
700
  this.context = context;
693
- __publicField(this, "span");
701
+ __publicField(this, "textDiv");
694
702
  __publicField(this, "img");
695
703
  __publicField(this, "overlay");
696
704
  __publicField(this, "options");
@@ -716,7 +724,11 @@ var Poi = class extends Object3D4 {
716
724
  }
717
725
  });
718
726
  this.addEventListener("change-text", ({ value }) => {
719
- this.span.textContent = value;
727
+ this.overlay.div.removeChild(this.textDiv);
728
+ this.overlay.div.appendChild(this.initText());
729
+ });
730
+ this.addEventListener("change-opacity", ({ value }) => {
731
+ this.overlay.setOpacity(value);
720
732
  });
721
733
  }
722
734
  initDiv() {
@@ -737,11 +749,23 @@ var Poi = class extends Object3D4 {
737
749
  return this.position;
738
750
  }
739
751
  initText() {
740
- const span = document.createElement("span");
741
- span.style.whiteSpace = "nowrap";
742
- span.textContent = this.options.text;
743
- this.span = span;
744
- return span;
752
+ const textDiv = document.createElement("div");
753
+ textDiv.appendChild(this.createTextFragment());
754
+ textDiv.style.background = "rgba(255, 255, 255, .7)";
755
+ textDiv.style.padding = "2px";
756
+ textDiv.style.borderRadius = "4px";
757
+ this.textDiv = textDiv;
758
+ return textDiv;
759
+ }
760
+ createTextFragment() {
761
+ const f = document.createDocumentFragment();
762
+ this.options.text.split("\r\n").forEach((item) => {
763
+ const div = document.createElement("div");
764
+ div.style.whiteSpace = "nowrap";
765
+ div.textContent = item;
766
+ f.appendChild(div);
767
+ });
768
+ return f;
745
769
  }
746
770
  initIcon() {
747
771
  var _a, _b;
@@ -770,14 +794,14 @@ var Poi = class extends Object3D4 {
770
794
  }
771
795
  dispose() {
772
796
  this.unRegistryEvent();
773
- this.overlay.dispose();
774
- this.span = null;
797
+ this.textDiv = null;
775
798
  this.img = void 0;
799
+ this.overlay.dispose();
776
800
  }
777
801
  };
778
802
 
779
803
  // src/elements/floor.ts
780
- import { Object3D as Object3D7 } from "three";
804
+ import { Box3 as Box34, Object3D as Object3D7, Vector3 as Vector35 } from "three";
781
805
 
782
806
  // src/layer/graphic-layer.ts
783
807
  import { Box3 as Box33, Vector3 as Vector34 } from "three";
@@ -814,23 +838,29 @@ var GraphicLayer = class extends Layer {
814
838
  * @param raycaster
815
839
  */
816
840
  getGraphicByRaycaster(raycaster) {
817
- let position = null;
818
- const graphics = this.children.filter((item) => {
841
+ const initData = { distance: 1e4, graphic: null, position: null };
842
+ const data = this.children.reduce((res, item) => {
819
843
  if (item instanceof Graphic) {
820
844
  const pos = item.raycast(raycaster);
821
845
  if (pos) {
822
- if (position) {
823
- if (pos.z > position.z) {
824
- position = pos;
825
- }
826
- } else {
827
- position = pos;
846
+ const { distance } = pos;
847
+ if (distance < res.distance) {
848
+ return {
849
+ distance: res.distance,
850
+ position: res.position,
851
+ graphic: item
852
+ };
828
853
  }
829
854
  }
830
- return !!pos;
855
+ return res;
856
+ } else {
857
+ return res;
831
858
  }
832
- });
833
- return { graphics, position };
859
+ }, initData);
860
+ if (data === initData) {
861
+ return { graphics: [], position: null };
862
+ }
863
+ return { graphics: [data.graphic], position: data.position };
834
864
  }
835
865
  };
836
866
 
@@ -1037,24 +1067,37 @@ var Floor = class extends Object3D7 {
1037
1067
  this.context = context;
1038
1068
  __publicField(this, "graphicLayer");
1039
1069
  __publicField(this, "poiLayer");
1040
- __publicField(this, "ground");
1070
+ __publicField(this, "grounds", /* @__PURE__ */ new Set());
1041
1071
  __publicField(this, "shadow", new Shadow());
1042
1072
  __publicField(this, "heatmap");
1073
+ __publicField(this, "groundUpper", new Object3D7());
1043
1074
  this.graphicLayer = new GraphicLayer(this.context);
1044
1075
  this.poiLayer = new PoiLayer(this.context);
1045
- this.add(this.graphicLayer);
1046
- this.add(this.poiLayer);
1047
- this.add(this.shadow);
1076
+ this.groundUpper.add(this.graphicLayer);
1077
+ this.groundUpper.add(this.poiLayer);
1078
+ this.add(this.groundUpper);
1079
+ }
1080
+ addGrounds(grounds) {
1081
+ grounds.forEach((ground) => {
1082
+ if (!this.grounds.has(ground)) {
1083
+ this.grounds.add(ground);
1084
+ this.groundUpper.add(ground);
1085
+ }
1086
+ });
1087
+ }
1088
+ get hasElement() {
1089
+ return !!(this.grounds.size || this.graphicLayer.children.length);
1090
+ }
1091
+ getCenter() {
1092
+ return new Box34().setFromObject(this.groundUpper).getCenter(new Vector35());
1048
1093
  }
1049
- addGround(ground) {
1050
- this.ground = ground;
1051
- this.add(ground);
1052
- const center2 = ground.getCenter();
1053
- const size = ground.getSize();
1054
- this.shadow.position.x = center2.x;
1055
- this.shadow.position.y = center2.y;
1094
+ addShadow() {
1095
+ const box = new Box34().setFromObject(this.groundUpper);
1096
+ const center2 = box.getCenter(new Vector35());
1097
+ const size = box.getSize(new Vector35());
1098
+ this.shadow.setPosition(center2);
1056
1099
  this.shadow.changeLightCamera(size);
1057
- this.shadow.setTarget(ground);
1100
+ this.add(this.shadow);
1058
1101
  }
1059
1102
  addGraphic(graphicOptions) {
1060
1103
  return this.graphicLayer.createGraphic(graphicOptions);
@@ -1063,15 +1106,13 @@ var Floor = class extends Object3D7 {
1063
1106
  return this.poiLayer.createPoi(poiOptions);
1064
1107
  }
1065
1108
  addHeatmap(data) {
1066
- var _a, _b;
1067
1109
  if (!this.heatmap) {
1068
1110
  this.heatmap = new HeatmapElement(this.context);
1069
1111
  this.add(this.heatmap);
1070
1112
  }
1071
1113
  this.heatmap.loadData(data);
1072
- if (this.ground) {
1073
- this.heatmap.position.setZ(((_a = this.ground) == null ? void 0 : _a.options.airHeight) + ((_b = this.ground) == null ? void 0 : _b.options.height));
1074
- }
1114
+ const box = new Box34().setFromObject(this.graphicLayer);
1115
+ this.heatmap.position.setZ(box.max.z);
1075
1116
  return this.heatmap;
1076
1117
  }
1077
1118
  removeHeatMap() {
@@ -1088,18 +1129,19 @@ var Floor = class extends Object3D7 {
1088
1129
  this.shadow.visible = visible;
1089
1130
  }
1090
1131
  dispose() {
1091
- var _a, _b;
1132
+ var _a;
1092
1133
  this.shadow.dispose();
1093
1134
  this.graphicLayer.dispose();
1094
1135
  this.poiLayer.dispose();
1095
- (_a = this.ground) == null ? void 0 : _a.dispose();
1096
- (_b = this.heatmap) == null ? void 0 : _b.dispose();
1136
+ this.grounds.forEach((ground) => ground.dispose());
1137
+ (_a = this.heatmap) == null ? void 0 : _a.dispose();
1138
+ this.groundUpper.clear();
1097
1139
  this.clear();
1098
1140
  }
1099
1141
  };
1100
1142
 
1101
1143
  // src/elements/base-svg.ts
1102
- import { EventDispatcher as EventDispatcher2, Vector3 as Vector35 } from "three";
1144
+ import { EventDispatcher as EventDispatcher2, Vector3 as Vector36 } from "three";
1103
1145
  var BaseSvg = class extends EventDispatcher2 {
1104
1146
  constructor(context) {
1105
1147
  super();
@@ -1124,7 +1166,7 @@ var BaseSvg = class extends EventDispatcher2 {
1124
1166
  const { clientWidth, clientHeight } = renderer.domElement;
1125
1167
  const nx = x / clientWidth * 2 - 1;
1126
1168
  const ny = 1 - y / clientHeight * 2;
1127
- const v = new Vector35(nx, ny, 0);
1169
+ const v = new Vector36(nx, ny, 0);
1128
1170
  return v.unproject(camera);
1129
1171
  }
1130
1172
  getSvgCoordinate(vector) {
@@ -1658,7 +1700,7 @@ var Context = class extends EventDispatcher5 {
1658
1700
  camera.top = h / 2;
1659
1701
  camera.bottom = -h / 2;
1660
1702
  camera.updateProjectionMatrix();
1661
- renderer.setSize(window.innerWidth, window.innerHeight);
1703
+ renderer.setSize(w, h);
1662
1704
  });
1663
1705
  __publicField(this, "onClick", (e) => {
1664
1706
  const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
@@ -1718,7 +1760,7 @@ var Context = class extends EventDispatcher5 {
1718
1760
  /**
1719
1761
  * 获取两个点之间的像素数
1720
1762
  */
1721
- getRatio(point1 = new Vector37(0, 0, 0), point22 = new Vector37(100, 0, 0)) {
1763
+ getRatio(point1 = new Vector38(0, 0, 0), point22 = new Vector38(100, 0, 0)) {
1722
1764
  const { clientWidth, clientHeight } = this.container;
1723
1765
  const device1 = vector3ToDevice(point1, this.camera, clientWidth, clientHeight);
1724
1766
  const device2 = vector3ToDevice(point22, this.camera, clientWidth, clientHeight);
@@ -1732,14 +1774,13 @@ var Context = class extends EventDispatcher5 {
1732
1774
  });
1733
1775
  }
1734
1776
  switchFloor(floor) {
1735
- var _a;
1736
1777
  if (this.currentFloor) {
1737
1778
  this.scene.remove(this.currentFloor);
1738
1779
  this.currentFloor.dispose();
1739
1780
  }
1740
1781
  this.currentFloor = floor;
1741
1782
  this.scene.add(floor);
1742
- const position = (_a = floor.graphicLayer) == null ? void 0 : _a.getCenter();
1783
+ const position = floor.getCenter();
1743
1784
  if (position) {
1744
1785
  this.lights.position.x = position.x;
1745
1786
  this.lights.position.y = position.y;
@@ -1815,7 +1856,7 @@ var Context = class extends EventDispatcher5 {
1815
1856
  );
1816
1857
  }
1817
1858
  getCameraLookAt() {
1818
- return new Vector37().subVectors(this.control.target, this.camera.position);
1859
+ return new Vector38().subVectors(this.control.target, this.camera.position);
1819
1860
  }
1820
1861
  /**
1821
1862
  * 按照一个中心点设置相机的放大缩小
@@ -1863,7 +1904,7 @@ var Context = class extends EventDispatcher5 {
1863
1904
  fitCameraToObject(object, padding = [20, 20, 20, 20], duration = 500) {
1864
1905
  const [top, right, bottom, left] = padding;
1865
1906
  const { clientWidth, clientHeight } = this.container;
1866
- const boundingBox = new Box34().setFromObject(object);
1907
+ const boundingBox = new Box35().setFromObject(object);
1867
1908
  const { max, min } = boundingBox;
1868
1909
  const max2d = vector3ToDevice(max, this.camera, clientWidth, clientHeight);
1869
1910
  const min2d = vector3ToDevice(min, this.camera, clientWidth, clientHeight);
@@ -1875,12 +1916,12 @@ var Context = class extends EventDispatcher5 {
1875
1916
  const xScale = (clientWidth - right - left) / size.x;
1876
1917
  const yScale = (clientHeight - top - bottom) / size.y;
1877
1918
  const scale = Math.min(xScale, yScale);
1878
- const center2 = new Vector37((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
1919
+ const center2 = new Vector38((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
1879
1920
  return this.setZoom(scale * this.camera.zoom, center2, duration);
1880
1921
  }
1881
1922
  fitCameraToGround(padding = [20, 20, 20, 20], duration = 500) {
1882
- if (this.currentFloor) {
1883
- return this.fitCameraToObject(this.currentFloor.graphicLayer, padding, duration);
1923
+ if (this.currentFloor && this.currentFloor.hasElement) {
1924
+ return this.fitCameraToObject(this.currentFloor.groundUpper, padding, duration);
1884
1925
  } else {
1885
1926
  return Promise.resolve(false);
1886
1927
  }
@@ -2075,38 +2116,37 @@ var BMap = class extends EventDispatcher6 {
2075
2116
  if (!data.length) {
2076
2117
  return { curFloor, graphics: [] };
2077
2118
  }
2078
- const list = [...data];
2079
- let groundIndex = data.findIndex((item) => item.info.group === "ground");
2080
- if (groundIndex !== -1) {
2081
- const ground = data[groundIndex];
2082
- const groundGraphic = new Graphic(this.context, ground.info);
2083
- curFloor.addGround(groundGraphic);
2084
- list.splice(groundIndex, 1);
2085
- }
2119
+ const grounds = data.filter((item) => item.info.group === "ground");
2120
+ const groundGraphics = grounds.map((ground) => new Graphic(this.context, ground.info));
2121
+ curFloor.addGrounds(groundGraphics);
2122
+ const graphicData = data.filter((item) => item.info.group !== "ground");
2086
2123
  const legacyToGraphicMap = /* @__PURE__ */ new Map();
2087
- const graphics = list.map((item) => {
2124
+ const graphics = graphicData.map((item) => {
2088
2125
  const graphic = curFloor.addGraphic(item.info);
2089
2126
  graphic.userData.data = item;
2090
2127
  legacyToGraphicMap.set(item.legacy_id, graphic);
2091
2128
  return graphic;
2092
2129
  });
2130
+ curFloor.addShadow();
2093
2131
  curFloor.userData.legacyToGraphicMap = legacyToGraphicMap;
2094
2132
  return { curFloor, graphics };
2095
2133
  }
2096
2134
  switchFloor(floor) {
2097
- const curFloorData = this.floorDataMap.get(floor);
2098
- if (curFloorData) {
2099
- const createdFloor = this.createFloor(curFloorData);
2100
- if (createdFloor) {
2101
- this.context.switchFloor(createdFloor.curFloor);
2102
- this.context.fitCameraToGround(void 0, 0);
2103
- this.basicZoom = this.context.camera.zoom;
2135
+ return __async(this, null, function* () {
2136
+ const curFloorData = this.floorDataMap.get(floor);
2137
+ if (curFloorData) {
2138
+ const createdFloor = this.createFloor(curFloorData);
2139
+ if (createdFloor) {
2140
+ this.context.switchFloor(createdFloor.curFloor);
2141
+ yield this.context.fitCameraToGround(void 0, 0);
2142
+ this.basicZoom = this.context.camera.zoom;
2143
+ } else {
2144
+ console.warn("[switchFloor error] [" + floor + "] \u697C\u5C42\u6CA1\u6709\u6570\u636E");
2145
+ }
2104
2146
  } else {
2105
- console.warn("[switchFloor error] [" + floor + "] \u697C\u5C42\u6CA1\u6709\u6570\u636E");
2147
+ console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42");
2106
2148
  }
2107
- } else {
2108
- console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42");
2109
- }
2149
+ });
2110
2150
  }
2111
2151
  addHeatmap(data) {
2112
2152
  var _a;
@@ -2127,8 +2167,11 @@ var BMap = class extends EventDispatcher6 {
2127
2167
  createGraphicPoi(graphic, options) {
2128
2168
  if (this.context.currentFloor) {
2129
2169
  const poi = this.context.currentFloor.addPoi(options);
2130
- poi.position.copy(graphic.getCenter());
2170
+ const position = graphic.getCenter();
2171
+ position.z += graphic.options.height / 2;
2172
+ poi.position.copy(position);
2131
2173
  poi.position.z = poi.position.z + graphic.options.height / 2;
2174
+ return poi;
2132
2175
  }
2133
2176
  return null;
2134
2177
  }