@aibee/crc-bmap 0.0.13 → 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
@@ -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
  }
@@ -658,6 +658,9 @@ var Overlay = class extends EventDispatcher {
658
658
  setVisible(visible, display = "block") {
659
659
  this.div.style.display = visible ? display : "none";
660
660
  }
661
+ setOpacity(opacity) {
662
+ this.div.style.opacity = `${opacity}`;
663
+ }
661
664
  getPosition() {
662
665
  if (this.element) {
663
666
  if (typeof this.element.getPosition === "function") {
@@ -688,13 +691,14 @@ var Overlay = class extends EventDispatcher {
688
691
  var defaultOptions2 = {
689
692
  text: "",
690
693
  level: 1,
691
- collision_enable: true
694
+ collision_enable: true,
695
+ opacity: 1
692
696
  };
693
697
  var Poi = class extends Object3D4 {
694
698
  constructor(context, options) {
695
699
  super();
696
700
  this.context = context;
697
- __publicField(this, "span");
701
+ __publicField(this, "textDiv");
698
702
  __publicField(this, "img");
699
703
  __publicField(this, "overlay");
700
704
  __publicField(this, "options");
@@ -720,7 +724,11 @@ var Poi = class extends Object3D4 {
720
724
  }
721
725
  });
722
726
  this.addEventListener("change-text", ({ value }) => {
723
- 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);
724
732
  });
725
733
  }
726
734
  initDiv() {
@@ -741,11 +749,23 @@ var Poi = class extends Object3D4 {
741
749
  return this.position;
742
750
  }
743
751
  initText() {
744
- const span = document.createElement("span");
745
- span.style.whiteSpace = "nowrap";
746
- span.textContent = this.options.text;
747
- this.span = span;
748
- 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;
749
769
  }
750
770
  initIcon() {
751
771
  var _a, _b;
@@ -774,9 +794,9 @@ var Poi = class extends Object3D4 {
774
794
  }
775
795
  dispose() {
776
796
  this.unRegistryEvent();
777
- this.overlay.dispose();
778
- this.span = null;
797
+ this.textDiv = null;
779
798
  this.img = void 0;
799
+ this.overlay.dispose();
780
800
  }
781
801
  };
782
802
 
@@ -818,23 +838,29 @@ var GraphicLayer = class extends Layer {
818
838
  * @param raycaster
819
839
  */
820
840
  getGraphicByRaycaster(raycaster) {
821
- let position = null;
822
- const graphics = this.children.filter((item) => {
841
+ const initData = { distance: 1e4, graphic: null, position: null };
842
+ const data = this.children.reduce((res, item) => {
823
843
  if (item instanceof Graphic) {
824
844
  const pos = item.raycast(raycaster);
825
845
  if (pos) {
826
- if (position) {
827
- if (pos.z > position.z) {
828
- position = pos;
829
- }
830
- } else {
831
- 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
+ };
832
853
  }
833
854
  }
834
- return !!pos;
855
+ return res;
856
+ } else {
857
+ return res;
835
858
  }
836
- });
837
- return { graphics, position };
859
+ }, initData);
860
+ if (data === initData) {
861
+ return { graphics: [], position: null };
862
+ }
863
+ return { graphics: [data.graphic], position: data.position };
838
864
  }
839
865
  };
840
866
 
@@ -1059,6 +1085,12 @@ var Floor = class extends Object3D7 {
1059
1085
  }
1060
1086
  });
1061
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());
1093
+ }
1062
1094
  addShadow() {
1063
1095
  const box = new Box34().setFromObject(this.groundUpper);
1064
1096
  const center2 = box.getCenter(new Vector35());
@@ -1668,7 +1700,7 @@ var Context = class extends EventDispatcher5 {
1668
1700
  camera.top = h / 2;
1669
1701
  camera.bottom = -h / 2;
1670
1702
  camera.updateProjectionMatrix();
1671
- renderer.setSize(window.innerWidth, window.innerHeight);
1703
+ renderer.setSize(w, h);
1672
1704
  });
1673
1705
  __publicField(this, "onClick", (e) => {
1674
1706
  const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
@@ -1742,14 +1774,13 @@ var Context = class extends EventDispatcher5 {
1742
1774
  });
1743
1775
  }
1744
1776
  switchFloor(floor) {
1745
- var _a;
1746
1777
  if (this.currentFloor) {
1747
1778
  this.scene.remove(this.currentFloor);
1748
1779
  this.currentFloor.dispose();
1749
1780
  }
1750
1781
  this.currentFloor = floor;
1751
1782
  this.scene.add(floor);
1752
- const position = (_a = floor.graphicLayer) == null ? void 0 : _a.getCenter();
1783
+ const position = floor.getCenter();
1753
1784
  if (position) {
1754
1785
  this.lights.position.x = position.x;
1755
1786
  this.lights.position.y = position.y;
@@ -1889,7 +1920,7 @@ var Context = class extends EventDispatcher5 {
1889
1920
  return this.setZoom(scale * this.camera.zoom, center2, duration);
1890
1921
  }
1891
1922
  fitCameraToGround(padding = [20, 20, 20, 20], duration = 500) {
1892
- if (this.currentFloor) {
1923
+ if (this.currentFloor && this.currentFloor.hasElement) {
1893
1924
  return this.fitCameraToObject(this.currentFloor.groundUpper, padding, duration);
1894
1925
  } else {
1895
1926
  return Promise.resolve(false);
@@ -2101,19 +2132,21 @@ var BMap = class extends EventDispatcher6 {
2101
2132
  return { curFloor, graphics };
2102
2133
  }
2103
2134
  switchFloor(floor) {
2104
- const curFloorData = this.floorDataMap.get(floor);
2105
- if (curFloorData) {
2106
- const createdFloor = this.createFloor(curFloorData);
2107
- if (createdFloor) {
2108
- this.context.switchFloor(createdFloor.curFloor);
2109
- this.context.fitCameraToGround(void 0, 0);
2110
- 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
+ }
2111
2146
  } else {
2112
- 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");
2113
2148
  }
2114
- } else {
2115
- console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42");
2116
- }
2149
+ });
2117
2150
  }
2118
2151
  addHeatmap(data) {
2119
2152
  var _a;
@@ -2134,8 +2167,11 @@ var BMap = class extends EventDispatcher6 {
2134
2167
  createGraphicPoi(graphic, options) {
2135
2168
  if (this.context.currentFloor) {
2136
2169
  const poi = this.context.currentFloor.addPoi(options);
2137
- poi.position.copy(graphic.getCenter());
2170
+ const position = graphic.getCenter();
2171
+ position.z += graphic.options.height / 2;
2172
+ poi.position.copy(position);
2138
2173
  poi.position.z = poi.position.z + graphic.options.height / 2;
2174
+ return poi;
2139
2175
  }
2140
2176
  return null;
2141
2177
  }