@aibee/crc-bmap 0.0.15 → 0.0.17

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
@@ -442,7 +442,6 @@ var Graphic = class extends Object3D {
442
442
  if (this.options.geometry.type === "point") {
443
443
  const [x, y] = this.options.geometry.cds;
444
444
  this.position.set(x, y, this.options.height + this.options.airHeight);
445
- console.log(this.options);
446
445
  return this;
447
446
  }
448
447
  this.init();
@@ -839,6 +838,7 @@ var Layer = class extends Object3D5 {
839
838
  var GraphicLayer = class extends Layer {
840
839
  constructor(context) {
841
840
  super(context);
841
+ __publicField(this, "graphicMap", /* @__PURE__ */ new Map());
842
842
  }
843
843
  getCenter() {
844
844
  const box = new Box33().setFromObject(this);
@@ -847,6 +847,7 @@ var GraphicLayer = class extends Layer {
847
847
  createGraphic(options) {
848
848
  const graphic = new Graphic(this.context, options);
849
849
  this.add(graphic);
850
+ this.graphicMap.set(options.id, graphic);
850
851
  return graphic;
851
852
  }
852
853
  /**
@@ -2046,6 +2047,8 @@ var BMap = class extends EventDispatcher6 {
2046
2047
  __publicField(this, "svgPolygon");
2047
2048
  __publicField(this, "basicZoom", 1);
2048
2049
  __publicField(this, "floorDataMap", /* @__PURE__ */ new Map());
2050
+ __publicField(this, "buildingGroundMap", /* @__PURE__ */ new Map());
2051
+ __publicField(this, "currentBuildGround", null);
2049
2052
  __publicField(this, "onKeydown", (e) => {
2050
2053
  if (this.polarKeys.includes(e.code)) {
2051
2054
  this.context.control.maxPolarAngle = this.config.control.maxPolar;
@@ -2084,8 +2087,16 @@ var BMap = class extends EventDispatcher6 {
2084
2087
  return data;
2085
2088
  });
2086
2089
  }
2090
+ getBuildingKey({ brand, project, phase, building }) {
2091
+ const key = `${brand}-${project}-${phase}-${building}`;
2092
+ return key;
2093
+ }
2087
2094
  loadBuildingGround(_0) {
2088
2095
  return __async(this, arguments, function* ({ brand, project, phase, building }) {
2096
+ const key = this.getBuildingKey({ brand, project, phase, building });
2097
+ if (this.buildingGroundMap.get(key)) {
2098
+ return this.buildingGroundMap.get(key) || null;
2099
+ }
2089
2100
  const { apiDomain, apiPath: { floorRange }, apiInfo } = this.config;
2090
2101
  const url = `${apiDomain}${floorRange}?brand=${brand}&project=${project}&phase=${phase}&building=${building}`;
2091
2102
  const data = yield fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
@@ -2095,12 +2106,18 @@ var BMap = class extends EventDispatcher6 {
2095
2106
  }
2096
2107
  return data2;
2097
2108
  });
2109
+ this.buildingGroundMap.set(key, data);
2098
2110
  return data;
2099
2111
  });
2100
2112
  }
2113
+ getFloorKey({ brand, project, phase, building, floor, ts }) {
2114
+ const floorKey = `${brand}-${project}-${phase}-${building}-${floor}-${ts}`;
2115
+ return floorKey;
2116
+ }
2101
2117
  load(_0) {
2102
2118
  return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts }) {
2103
- if (this.floorDataMap.get(floor)) {
2119
+ const floorKey = this.getFloorKey({ brand, project, phase, building, floor, ts });
2120
+ if (this.floorDataMap.get(floorKey)) {
2104
2121
  return;
2105
2122
  }
2106
2123
  const [data, buildGround] = yield Promise.all([
@@ -2128,7 +2145,7 @@ var BMap = class extends EventDispatcher6 {
2128
2145
  if (!this.config.useFloorCache) {
2129
2146
  this.floorDataMap.clear();
2130
2147
  }
2131
- this.floorDataMap.set(floor, data);
2148
+ this.floorDataMap.set(floorKey, data);
2132
2149
  return data;
2133
2150
  });
2134
2151
  }
@@ -2152,13 +2169,18 @@ var BMap = class extends EventDispatcher6 {
2152
2169
  curFloor.userData.legacyToGraphicMap = legacyToGraphicMap;
2153
2170
  return { curFloor, graphics };
2154
2171
  }
2155
- switchFloor(floor) {
2156
- return __async(this, null, function* () {
2157
- const curFloorData = this.floorDataMap.get(floor);
2172
+ switchFloor(_0) {
2173
+ return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts }) {
2174
+ const floorKey = this.getFloorKey({ brand, project, phase, building, floor, ts });
2175
+ const curFloorData = this.floorDataMap.get(floorKey);
2158
2176
  if (curFloorData) {
2177
+ const buildingKey = this.getBuildingKey({ brand, project, phase, building });
2178
+ this.currentBuildGround = this.buildingGroundMap.get(buildingKey) || null;
2159
2179
  const createdFloor = this.createFloor(curFloorData);
2160
2180
  if (createdFloor) {
2161
2181
  this.context.switchFloor(createdFloor.curFloor);
2182
+ this.context.control.minZoom = 0;
2183
+ this.context.control.maxZoom = Infinity;
2162
2184
  yield this.context.fitCameraToGround(void 0, 0);
2163
2185
  this.basicZoom = this.context.camera.zoom;
2164
2186
  this.context.control.minZoom = this.basicZoom;
@@ -2349,6 +2371,42 @@ var BMap = class extends EventDispatcher6 {
2349
2371
  this.context.control.enableRotate = true;
2350
2372
  }
2351
2373
  }
2374
+ /**
2375
+ * 根据nodeId 获取graphic
2376
+ */
2377
+ getGraphicByNodeId(nodeId) {
2378
+ if (this.context.currentFloor) {
2379
+ return this.context.currentFloor.graphicLayer.graphicMap.get(nodeId) || null;
2380
+ }
2381
+ return null;
2382
+ }
2383
+ deleteGraphic(graphic) {
2384
+ if (this.context.currentFloor) {
2385
+ this.context.currentFloor.graphicLayer.remove(graphic);
2386
+ graphic.dispose();
2387
+ this.context.currentFloor.graphicLayer.graphicMap.delete(graphic.options.id);
2388
+ }
2389
+ }
2390
+ createGraphicByOptions(options) {
2391
+ var _a;
2392
+ if (this.currentBuildGround) {
2393
+ const center2 = getCenter(this.currentBuildGround.info.geometry.cds[0]);
2394
+ if (options.geometry.type === "polygon") {
2395
+ options.geometry.cds.map((cds) => {
2396
+ if (Array.isArray(cds)) {
2397
+ cds.forEach((coord) => {
2398
+ coord[0] -= center2[0];
2399
+ coord[1] -= center2[1];
2400
+ });
2401
+ }
2402
+ });
2403
+ } else {
2404
+ const [x, y] = options.geometry.cds;
2405
+ options.geometry.cds = [x - center2[0], y - center2[1]];
2406
+ }
2407
+ }
2408
+ return (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.createGraphic(options);
2409
+ }
2352
2410
  dispose() {
2353
2411
  this.context.dispose();
2354
2412
  clearTextTexture();