@aibee/crc-bmap 0.0.92 → 0.0.94

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
@@ -1,60 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __pow = Math.pow;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __publicField = (obj, key, value) => {
22
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
- return value;
24
- };
25
- var __async = (__this, __arguments, generator) => {
26
- return new Promise((resolve, reject) => {
27
- var fulfilled = (value) => {
28
- try {
29
- step(generator.next(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var rejected = (value) => {
35
- try {
36
- step(generator.throw(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
42
- step((generator = generator.apply(__this, __arguments)).next());
43
- });
44
- };
45
-
46
1
  // src/bmap.ts
47
- import { EventDispatcher as EventDispatcher7 } from "three";
2
+ import { EventDispatcher as EventDispatcher7, Vector3 as Vector314 } from "three";
48
3
 
49
4
  // src/utils/timer.ts
50
5
  var Timer = class {
51
- constructor() {
52
- __publicField(this, "tasks", {
53
- requestAnimation: /* @__PURE__ */ new Set(),
54
- timeout: /* @__PURE__ */ new Set(),
55
- interval: /* @__PURE__ */ new Set()
56
- });
57
- }
6
+ tasks = {
7
+ requestAnimation: /* @__PURE__ */ new Set(),
8
+ timeout: /* @__PURE__ */ new Set(),
9
+ interval: /* @__PURE__ */ new Set()
10
+ };
58
11
  requestAnimationFrame(fn) {
59
12
  const timer = window.requestAnimationFrame(() => {
60
13
  this.tasks.requestAnimation.delete(timer);
@@ -187,7 +140,6 @@ function initDirectionalLight(color = 16777215, intensity = 1) {
187
140
 
188
141
  // src/utils/dispose.ts
189
142
  function dispose(o, recursive) {
190
- var _a;
191
143
  if (recursive && o.children && o.children.length) {
192
144
  o.children.forEach((child) => {
193
145
  dispose(child, recursive);
@@ -208,7 +160,7 @@ function dispose(o, recursive) {
208
160
  }
209
161
  }
210
162
  if (o.isLight) {
211
- (_a = o.dispose) == null ? void 0 : _a.call(o);
163
+ o.dispose?.();
212
164
  }
213
165
  }
214
166
 
@@ -476,6 +428,76 @@ function isControl(key) {
476
428
  return key === "Control";
477
429
  }
478
430
 
431
+ // src/utils/events.ts
432
+ var oncePrefix = "__once__";
433
+ var Events = class {
434
+ events = /* @__PURE__ */ new Map();
435
+ on(type, callback) {
436
+ if (typeof callback !== "function")
437
+ return void 0;
438
+ const events = this.events.get(type);
439
+ if (events) {
440
+ return events.add(callback);
441
+ }
442
+ return this.events.set(type, /* @__PURE__ */ new Set([callback]));
443
+ }
444
+ once(type, callback) {
445
+ if (typeof callback !== "function")
446
+ return void 0;
447
+ const event = `${oncePrefix}${type}`;
448
+ const events = this.events.get(event);
449
+ if (events) {
450
+ return events.add(callback);
451
+ }
452
+ return this.events.set(event, /* @__PURE__ */ new Set([callback]));
453
+ }
454
+ off(type, callback) {
455
+ const events = this.events.get(type);
456
+ const onceEvents = this.events.get(`${oncePrefix}${type}`);
457
+ if (!events && !onceEvents) {
458
+ return;
459
+ }
460
+ if (callback === void 0) {
461
+ events?.clear();
462
+ onceEvents?.clear();
463
+ }
464
+ if (events?.has(callback)) {
465
+ events.delete(callback);
466
+ }
467
+ if (onceEvents?.has(callback)) {
468
+ onceEvents.delete(callback);
469
+ }
470
+ }
471
+ offAll() {
472
+ this.events.clear();
473
+ }
474
+ emit(type, ...args) {
475
+ const events = this.events.get(type);
476
+ const onceEvents = this.events.get(`${oncePrefix}${type}`);
477
+ if (!events && !onceEvents) {
478
+ return;
479
+ }
480
+ events?.forEach((fn) => {
481
+ if (typeof fn === "function") {
482
+ fn(...args);
483
+ }
484
+ });
485
+ onceEvents?.forEach((fn) => {
486
+ if (typeof fn === "function") {
487
+ fn(...args);
488
+ }
489
+ });
490
+ onceEvents?.clear();
491
+ }
492
+ };
493
+
494
+ // src/utils/event-name.ts
495
+ var EventName = /* @__PURE__ */ ((EventName2) => {
496
+ EventName2["SWITCH_FLOOR_BEFORE"] = "switch_floor_before";
497
+ EventName2["SWITCH_FLOOR_AFTER"] = "switch_floor_after";
498
+ return EventName2;
499
+ })(EventName || {});
500
+
479
501
  // src/context.ts
480
502
  import {
481
503
  EventDispatcher as EventDispatcher6,
@@ -548,15 +570,8 @@ var Graphic = class extends Object3D {
548
570
  constructor(context, options) {
549
571
  super();
550
572
  this.context = context;
551
- __publicField(this, "geometry");
552
- __publicField(this, "material");
553
- __publicField(this, "mesh");
554
- __publicField(this, "line");
555
- __publicField(this, "lineMaterial");
556
- __publicField(this, "lineGeometry");
557
- __publicField(this, "options");
558
573
  this.options = proxyOptions(
559
- __spreadValues(__spreadValues({}, defaultOptions), options),
574
+ { ...defaultOptions, ...options },
560
575
  this
561
576
  );
562
577
  if (this.options.geometry.type === "point") {
@@ -599,7 +614,6 @@ var Graphic = class extends Object3D {
599
614
  this.visible = value;
600
615
  });
601
616
  this.addEventListener("change-stroke", ({ value }) => {
602
- var _a;
603
617
  if (value) {
604
618
  if (this.line) {
605
619
  return;
@@ -609,7 +623,7 @@ var Graphic = class extends Object3D {
609
623
  this.createBorder();
610
624
  } else if (this.line) {
611
625
  this.remove(this.line);
612
- (_a = this.lineGeometry) == null ? void 0 : _a.dispose();
626
+ this.lineGeometry?.dispose();
613
627
  }
614
628
  });
615
629
  this.addEventListener("change-renderType", () => {
@@ -621,6 +635,13 @@ var Graphic = class extends Object3D {
621
635
  this.initMesh();
622
636
  });
623
637
  }
638
+ geometry;
639
+ material;
640
+ mesh;
641
+ line;
642
+ lineMaterial;
643
+ lineGeometry;
644
+ options;
624
645
  getCenter() {
625
646
  if (this.options.geometry.type === "point") {
626
647
  return this.position.clone();
@@ -821,9 +842,8 @@ var Graphic = class extends Object3D {
821
842
  return false;
822
843
  }
823
844
  dispose() {
824
- var _a;
825
845
  this.geometry.dispose();
826
- (_a = this.line) == null ? void 0 : _a.geometry.dispose();
846
+ this.line?.geometry.dispose();
827
847
  this.clear();
828
848
  }
829
849
  };
@@ -838,11 +858,11 @@ import {
838
858
  DoubleSide as DoubleSide2
839
859
  } from "three";
840
860
  var Shadow = class extends Object3D2 {
861
+ directionalLight;
862
+ plane;
863
+ basicOpacity = 0.07;
841
864
  constructor() {
842
865
  super();
843
- __publicField(this, "directionalLight");
844
- __publicField(this, "plane");
845
- __publicField(this, "basicOpacity", 0.07);
846
866
  this.directionalLight = this.initLight();
847
867
  this.initPlane();
848
868
  }
@@ -914,22 +934,7 @@ var Overlay = class extends EventDispatcher {
914
934
  constructor(context, options = {}) {
915
935
  super();
916
936
  this.context = context;
917
- __publicField(this, "div");
918
- __publicField(this, "element");
919
- __publicField(this, "position", new Vector34());
920
- __publicField(this, "clientPos", { x: 0, y: 0 });
921
- __publicField(this, "visible", true);
922
- __publicField(this, "options");
923
- __publicField(this, "placement", "top");
924
- __publicField(this, "observer", null);
925
- __publicField(this, "onUpdate", () => {
926
- if (this.options.autoChangePlacement) {
927
- this.usePlacement();
928
- } else {
929
- this.updatePosition();
930
- }
931
- });
932
- this.options = __spreadValues(__spreadValues({}, defaultOptions2), options);
937
+ this.options = { ...defaultOptions2, ...options };
933
938
  this.registryEvent();
934
939
  this.div = this.initDiv();
935
940
  if (this.options.appendToBody) {
@@ -938,10 +943,20 @@ var Overlay = class extends EventDispatcher {
938
943
  this.context.container.appendChild(this.div);
939
944
  }
940
945
  }
946
+ div;
947
+ element;
948
+ position = new Vector34();
949
+ clientPos = { x: 0, y: 0 };
950
+ visible = true;
951
+ options;
952
+ placement = "top";
953
+ observer = null;
941
954
  initObserver() {
942
955
  const observer = new MutationObserver(
943
956
  debounce(() => {
944
- this.usePlacement();
957
+ if (this.div) {
958
+ this.usePlacement();
959
+ }
945
960
  }, 100)
946
961
  );
947
962
  observer.observe(this.div, {
@@ -1166,6 +1181,13 @@ var Overlay = class extends EventDispatcher {
1166
1181
  }
1167
1182
  this._updatePosition(x, y);
1168
1183
  }
1184
+ onUpdate = () => {
1185
+ if (this.options.autoChangePlacement) {
1186
+ this.usePlacement();
1187
+ } else {
1188
+ this.updatePosition();
1189
+ }
1190
+ };
1169
1191
  registryEvent() {
1170
1192
  this.context.addEventListener("update", this.onUpdate);
1171
1193
  }
@@ -1173,11 +1195,10 @@ var Overlay = class extends EventDispatcher {
1173
1195
  this.context.removeEventListener("update", this.onUpdate);
1174
1196
  }
1175
1197
  dispose() {
1176
- var _a, _b;
1177
1198
  this.unRegistryEvent();
1178
1199
  this.unBindElement();
1179
- (_a = this.observer) == null ? void 0 : _a.disconnect();
1180
- (_b = this.div) == null ? void 0 : _b.remove();
1200
+ this.observer?.disconnect();
1201
+ this.div?.remove();
1181
1202
  this.div = null;
1182
1203
  }
1183
1204
  };
@@ -1200,24 +1221,10 @@ var defaultOptions3 = {
1200
1221
  };
1201
1222
  var Poi = class extends EventDispatcher2 {
1202
1223
  constructor(context, options) {
1203
- var _a, _b, _c;
1204
1224
  super();
1205
1225
  this.context = context;
1206
- __publicField(this, "div");
1207
- __publicField(this, "textDiv");
1208
- __publicField(this, "img");
1209
- __publicField(this, "overlay");
1210
- __publicField(this, "options");
1211
- __publicField(this, "visible", true);
1212
- __publicField(this, "size", { width: 0, height: 0 });
1213
- __publicField(this, "position", new Vector35());
1214
- __publicField(this, "userData", {});
1215
- __publicField(this, "showTextStatus", true);
1216
- __publicField(this, "_changePosition", () => {
1217
- this.overlay.updatePosition(true);
1218
- });
1219
- this.options = proxyOptions(__spreadValues(__spreadValues({}, defaultOptions3), options), this);
1220
- this.position.set(((_a = options.position) == null ? void 0 : _a.x) || 0, ((_b = options.position) == null ? void 0 : _b.y) || 0, ((_c = options.position) == null ? void 0 : _c.z) || 0);
1226
+ this.options = proxyOptions({ ...defaultOptions3, ...options }, this);
1227
+ this.position.set(options.position?.x || 0, options.position?.y || 0, options.position?.z || 0);
1221
1228
  this.overlay = new Overlay(this.context, { autoUpdate: false });
1222
1229
  this.overlay.addEventListener("update-position", ({ x, y, height }) => {
1223
1230
  this.overlay.div.style.transform = `translate3d(calc(${x}px - 50%), calc(${-height + y}px - ${this.options.icon ? "100%" : "50%"}), 0)`;
@@ -1250,8 +1257,8 @@ var Poi = class extends EventDispatcher2 {
1250
1257
  });
1251
1258
  this.addEventListener("change-icon_size", ({ value }) => {
1252
1259
  if (this.img) {
1253
- this.img.style.width = `${(value == null ? void 0 : value[0]) || 32}px`;
1254
- this.img.style.height = `${(value == null ? void 0 : value[1]) || 32}px`;
1260
+ this.img.style.width = `${value?.[0] || 32}px`;
1261
+ this.img.style.height = `${value?.[1] || 32}px`;
1255
1262
  this.resetSize();
1256
1263
  }
1257
1264
  });
@@ -1269,29 +1276,37 @@ var Poi = class extends EventDispatcher2 {
1269
1276
  this.div.style.background = value;
1270
1277
  });
1271
1278
  }
1279
+ div;
1280
+ textDiv;
1281
+ img;
1282
+ overlay;
1283
+ options;
1284
+ visible = true;
1285
+ size = { width: 0, height: 0 };
1286
+ position = new Vector35();
1287
+ userData = {};
1288
+ showTextStatus = true;
1272
1289
  get withinDisplayRange() {
1273
1290
  return this.overlay.withinDisplayRange;
1274
1291
  }
1275
- resetSize() {
1276
- return __async(this, null, function* () {
1277
- yield sleepOnePromise();
1278
- if (this.options.box_only_icon) {
1279
- if (!this.img) {
1280
- return;
1281
- }
1282
- const { width, height } = this.img.getBoundingClientRect();
1283
- this.size = {
1284
- width: width + 2,
1285
- height: height + 2
1286
- };
1287
- } else {
1288
- const { width, height } = this.div.getBoundingClientRect();
1289
- this.size = {
1290
- width: width + 2,
1291
- height: height + 2
1292
- };
1292
+ async resetSize() {
1293
+ await sleepOnePromise();
1294
+ if (this.options.box_only_icon) {
1295
+ if (!this.img) {
1296
+ return;
1293
1297
  }
1294
- });
1298
+ const { width, height } = this.img.getBoundingClientRect();
1299
+ this.size = {
1300
+ width: width + 2,
1301
+ height: height + 2
1302
+ };
1303
+ } else {
1304
+ const { width, height } = this.div.getBoundingClientRect();
1305
+ this.size = {
1306
+ width: width + 2,
1307
+ height: height + 2
1308
+ };
1309
+ }
1295
1310
  }
1296
1311
  renderHelperBox() {
1297
1312
  }
@@ -1371,11 +1386,10 @@ var Poi = class extends EventDispatcher2 {
1371
1386
  return f;
1372
1387
  }
1373
1388
  initIcon() {
1374
- var _a, _b;
1375
1389
  const img = document.createElement("img");
1376
1390
  img.setAttribute("src", this.options.icon);
1377
- img.style.width = `${((_a = this.options.icon_size) == null ? void 0 : _a[0]) || 32}px`;
1378
- img.style.height = `${((_b = this.options.icon_size) == null ? void 0 : _b[1]) || 32}px`;
1391
+ img.style.width = `${this.options.icon_size?.[0] || 32}px`;
1392
+ img.style.height = `${this.options.icon_size?.[1] || 32}px`;
1379
1393
  img.style.opacity = `${this.options.icon_opacity}px`;
1380
1394
  img.style.borderRadius = "50%";
1381
1395
  if (this.options.icon_border.width) {
@@ -1387,6 +1401,9 @@ var Poi = class extends EventDispatcher2 {
1387
1401
  this.img = img;
1388
1402
  return img;
1389
1403
  }
1404
+ _changePosition = () => {
1405
+ this.overlay.updatePosition(true);
1406
+ };
1390
1407
  registryEvent() {
1391
1408
  }
1392
1409
  unRegistryEvent() {
@@ -1474,9 +1491,9 @@ var Layer = class extends Object3D5 {
1474
1491
 
1475
1492
  // src/layer/graphic-layer.ts
1476
1493
  var GraphicLayer = class extends Layer {
1494
+ graphicMap = /* @__PURE__ */ new Map();
1477
1495
  constructor(context) {
1478
1496
  super(context);
1479
- __publicField(this, "graphicMap", /* @__PURE__ */ new Map());
1480
1497
  }
1481
1498
  getCenter() {
1482
1499
  const box = new Box33().setFromObject(this);
@@ -1535,16 +1552,11 @@ var GraphicLayer = class extends Layer {
1535
1552
  // src/layer/poi-layer.ts
1536
1553
  import { debounce as debounce2 } from "lodash";
1537
1554
  var PoiLayer = class extends Layer {
1555
+ pois = [];
1556
+ debounceCollisionDetection;
1557
+ timer = new Timer();
1538
1558
  constructor(context) {
1539
1559
  super(context);
1540
- __publicField(this, "pois", []);
1541
- __publicField(this, "debounceCollisionDetection");
1542
- __publicField(this, "timer", new Timer());
1543
- __publicField(this, "onUpdate", () => {
1544
- this.timer.requestAnimationFrame(() => {
1545
- this.collisionDetection();
1546
- });
1547
- });
1548
1560
  this.registryEvent();
1549
1561
  this.debounceCollisionDetection = debounce2(this.collisionDetection, 10);
1550
1562
  }
@@ -1625,6 +1637,11 @@ var PoiLayer = class extends Layer {
1625
1637
  });
1626
1638
  return pois;
1627
1639
  }
1640
+ onUpdate = () => {
1641
+ this.timer.requestAnimationFrame(() => {
1642
+ this.collisionDetection();
1643
+ });
1644
+ };
1628
1645
  /**
1629
1646
  * 碰撞检测
1630
1647
  */
@@ -1681,11 +1698,11 @@ var HeatmapElement = class extends Object3D6 {
1681
1698
  constructor(context) {
1682
1699
  super();
1683
1700
  this.context = context;
1684
- __publicField(this, "heatmap");
1685
- __publicField(this, "div");
1686
- __publicField(this, "plane");
1687
1701
  this.div = document.createElement("div");
1688
1702
  }
1703
+ heatmap;
1704
+ div;
1705
+ plane;
1689
1706
  clearHeatmap() {
1690
1707
  if (this.div.firstChild) {
1691
1708
  this.div.removeChild(this.div.firstChild);
@@ -1695,11 +1712,12 @@ var HeatmapElement = class extends Object3D6 {
1695
1712
  loadData(data) {
1696
1713
  this.clearHeatmap();
1697
1714
  const { width, height, leftTop, center: center2 } = this.getBox(data);
1698
- this.heatmap = create(__spreadValues({
1715
+ this.heatmap = create({
1699
1716
  width,
1700
1717
  height,
1701
- container: this.div
1702
- }, this.context.config.heatMap));
1718
+ container: this.div,
1719
+ ...this.context.config.heatMap
1720
+ });
1703
1721
  this.heatmap.setData(this.transformData(data, leftTop));
1704
1722
  this.initPlane(width, height);
1705
1723
  this.position.set(center2[0], center2[1], this.position.z);
@@ -1767,26 +1785,23 @@ var Model = class extends Object3D7 {
1767
1785
  super();
1768
1786
  this.context = context;
1769
1787
  this.options = options;
1770
- __publicField(this, "poi", null);
1771
- __publicField(this, "model", null);
1772
1788
  this.position.copy(options.position || new Vector37(0, 0, 0));
1773
1789
  this.loadModel();
1774
1790
  }
1775
- loadModel() {
1776
- return __async(this, null, function* () {
1777
- const object = yield loadModel(this.options.modelUrl);
1778
- object.scene.rotation.set(Math.PI / 2, Math.PI / 2, 0);
1779
- this.add(object.scene);
1780
- this.model = object;
1781
- this.initPoi();
1782
- });
1791
+ poi = null;
1792
+ model = null;
1793
+ async loadModel() {
1794
+ const object = await loadModel(this.options.modelUrl);
1795
+ object.scene.rotation.set(Math.PI / 2, Math.PI / 2, 0);
1796
+ this.add(object.scene);
1797
+ this.model = object;
1798
+ this.initPoi();
1783
1799
  }
1784
1800
  initPoi() {
1785
- var _a;
1786
1801
  if (!this.options.icon) {
1787
1802
  return;
1788
1803
  }
1789
- const poi = (_a = this.context.currentFloor) == null ? void 0 : _a.addPoi({
1804
+ const poi = this.context.currentFloor?.addPoi({
1790
1805
  icon: this.options.icon,
1791
1806
  icon_size: this.options.icon_size,
1792
1807
  built_in: true,
@@ -1798,11 +1813,10 @@ var Model = class extends Object3D7 {
1798
1813
  }
1799
1814
  }
1800
1815
  dispose() {
1801
- var _a;
1802
1816
  dispose(this);
1803
1817
  this.model = null;
1804
1818
  if (this.poi) {
1805
- (_a = this.context.currentFloor) == null ? void 0 : _a.poiLayer.removePoi(this.poi);
1819
+ this.context.currentFloor?.poiLayer.removePoi(this.poi);
1806
1820
  this.poi = null;
1807
1821
  }
1808
1822
  }
@@ -1813,15 +1827,6 @@ var Floor = class extends Object3D8 {
1813
1827
  constructor(context) {
1814
1828
  super();
1815
1829
  this.context = context;
1816
- __publicField(this, "graphicLayer");
1817
- __publicField(this, "poiLayer");
1818
- __publicField(this, "grounds", /* @__PURE__ */ new Set());
1819
- __publicField(this, "shadow", new Shadow());
1820
- __publicField(this, "heatmap");
1821
- __publicField(this, "groundUpper", new Object3D8());
1822
- __publicField(this, "models", new Object3D8());
1823
- __publicField(this, "modelMap", /* @__PURE__ */ new Map());
1824
- __publicField(this, "groundMaxHeight", 0);
1825
1830
  this.graphicLayer = new GraphicLayer(this.context);
1826
1831
  this.poiLayer = new PoiLayer(this.context);
1827
1832
  this.groundUpper.add(this.graphicLayer);
@@ -1829,6 +1834,15 @@ var Floor = class extends Object3D8 {
1829
1834
  this.add(this.groundUpper);
1830
1835
  this.add(this.models);
1831
1836
  }
1837
+ graphicLayer;
1838
+ poiLayer;
1839
+ grounds = /* @__PURE__ */ new Set();
1840
+ shadow = new Shadow();
1841
+ heatmap;
1842
+ groundUpper = new Object3D8();
1843
+ models = new Object3D8();
1844
+ modelMap = /* @__PURE__ */ new Map();
1845
+ groundMaxHeight = 0;
1832
1846
  getPosition() {
1833
1847
  const box = new Box35().setFromObject(this.groundUpper);
1834
1848
  return box.getCenter(new Vector38());
@@ -1902,12 +1916,11 @@ var Floor = class extends Object3D8 {
1902
1916
  this.shadow.visible = visible;
1903
1917
  }
1904
1918
  dispose() {
1905
- var _a;
1906
1919
  this.shadow.dispose();
1907
1920
  this.graphicLayer.dispose();
1908
1921
  this.poiLayer.dispose();
1909
1922
  this.grounds.forEach((ground) => ground.dispose());
1910
- (_a = this.heatmap) == null ? void 0 : _a.dispose();
1923
+ this.heatmap?.dispose();
1911
1924
  this.groundUpper.clear();
1912
1925
  this.models.children.forEach((model) => model.dispose());
1913
1926
  this.models.clear();
@@ -1922,19 +1935,19 @@ var BaseSvg = class extends EventDispatcher3 {
1922
1935
  constructor(context) {
1923
1936
  super();
1924
1937
  this.context = context;
1925
- __publicField(this, "points", []);
1926
- __publicField(this, "svg");
1927
- __publicField(this, "enable", true);
1928
- __publicField(this, "_onResize", ({ width, height }) => {
1929
- if (this.svg) {
1930
- this.svg.setAttribute("width", `${width}`);
1931
- this.svg.setAttribute("height", `${height}`);
1932
- }
1933
- });
1934
1938
  this.svg = createSvg(`${context.container.clientWidth}`, `${context.container.clientHeight}`);
1935
1939
  context.container.appendChild(this.svg);
1936
1940
  this._registryEvent();
1937
1941
  }
1942
+ points = [];
1943
+ svg;
1944
+ enable = true;
1945
+ _onResize = ({ width, height }) => {
1946
+ if (this.svg) {
1947
+ this.svg.setAttribute("width", `${width}`);
1948
+ this.svg.setAttribute("height", `${height}`);
1949
+ }
1950
+ };
1938
1951
  _registryEvent() {
1939
1952
  this.context.addEventListener("resize", this._onResize);
1940
1953
  }
@@ -1975,48 +1988,6 @@ var SvgLine = class extends BaseSvg {
1975
1988
  constructor(context) {
1976
1989
  super(context);
1977
1990
  this.context = context;
1978
- __publicField(this, "circles");
1979
- __publicField(this, "line");
1980
- __publicField(this, "onUpdate", () => {
1981
- if (this.points[0]) {
1982
- const point1 = this.getSvgCoordinate(this.points[0]);
1983
- setCirclePosition(this.circles[0], point1.x, point1.y);
1984
- setLineStartEnd(this.line, point1);
1985
- }
1986
- if (this.points[1]) {
1987
- const point22 = this.getSvgCoordinate(this.points[1]);
1988
- setCirclePosition(this.circles[1], point22.x, point22.y);
1989
- setLineStartEnd(this.line, void 0, point22);
1990
- }
1991
- });
1992
- __publicField(this, "onPointermove", (e) => {
1993
- if (this.points.length !== 1) {
1994
- return;
1995
- }
1996
- this.line.style.display = "block";
1997
- setLineStartEnd(this.line, void 0, { x: e.offsetX, y: e.offsetY });
1998
- });
1999
- __publicField(this, "onPointerleave", () => {
2000
- if (this.points[1]) {
2001
- return;
2002
- }
2003
- this.line.style.display = "none";
2004
- });
2005
- __publicField(this, "onPointerdown", (e) => {
2006
- if (this.points[1]) {
2007
- return;
2008
- }
2009
- const point3 = this.getIntersectByPointerEvent(e);
2010
- if (point3) {
2011
- const { offsetX: x, offsetY: y } = e;
2012
- const circle = this.circles[this.points.length];
2013
- setCirclePosition(circle, x, y);
2014
- if (!this.points.length) {
2015
- setLineStartEnd(this.line, { x, y }, { x, y });
2016
- }
2017
- this.addPoint(point3);
2018
- }
2019
- });
2020
1991
  const { config: { svg: { circle, line } } } = context;
2021
1992
  this.circles = [createCircle(circle.radius, circle.fill), createCircle(circle.radius, circle.fill)];
2022
1993
  this.line = createLine(line.stroke);
@@ -2025,6 +1996,8 @@ var SvgLine = class extends BaseSvg {
2025
1996
  this.svg.appendChild(this.line);
2026
1997
  this.registryEvent();
2027
1998
  }
1999
+ circles;
2000
+ line;
2028
2001
  setEnable(enable) {
2029
2002
  super.setEnable(enable);
2030
2003
  if (enable) {
@@ -2047,6 +2020,46 @@ var SvgLine = class extends BaseSvg {
2047
2020
  this.context.container.removeEventListener("pointerdown", this.onPointerdown);
2048
2021
  this.context.removeEventListener("update", this.onUpdate);
2049
2022
  }
2023
+ onUpdate = () => {
2024
+ if (this.points[0]) {
2025
+ const point1 = this.getSvgCoordinate(this.points[0]);
2026
+ setCirclePosition(this.circles[0], point1.x, point1.y);
2027
+ setLineStartEnd(this.line, point1);
2028
+ }
2029
+ if (this.points[1]) {
2030
+ const point22 = this.getSvgCoordinate(this.points[1]);
2031
+ setCirclePosition(this.circles[1], point22.x, point22.y);
2032
+ setLineStartEnd(this.line, void 0, point22);
2033
+ }
2034
+ };
2035
+ onPointermove = (e) => {
2036
+ if (this.points.length !== 1) {
2037
+ return;
2038
+ }
2039
+ this.line.style.display = "block";
2040
+ setLineStartEnd(this.line, void 0, { x: e.offsetX, y: e.offsetY });
2041
+ };
2042
+ onPointerleave = () => {
2043
+ if (this.points[1]) {
2044
+ return;
2045
+ }
2046
+ this.line.style.display = "none";
2047
+ };
2048
+ onPointerdown = (e) => {
2049
+ if (this.points[1]) {
2050
+ return;
2051
+ }
2052
+ const point3 = this.getIntersectByPointerEvent(e);
2053
+ if (point3) {
2054
+ const { offsetX: x, offsetY: y } = e;
2055
+ const circle = this.circles[this.points.length];
2056
+ setCirclePosition(circle, x, y);
2057
+ if (!this.points.length) {
2058
+ setLineStartEnd(this.line, { x, y }, { x, y });
2059
+ }
2060
+ this.addPoint(point3);
2061
+ }
2062
+ };
2050
2063
  addPoint(vector) {
2051
2064
  this.points.push(vector);
2052
2065
  if (this.points.length >= 2) {
@@ -2059,7 +2072,7 @@ var SvgLine = class extends BaseSvg {
2059
2072
  */
2060
2073
  calculatedDistance() {
2061
2074
  const [{ x: x1, y: y1 }, { x: x2, y: y2 }] = this.points;
2062
- return Math.sqrt(__pow(x2 - x1, 2) + __pow(y2 - y1, 2));
2075
+ return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
2063
2076
  }
2064
2077
  dispose() {
2065
2078
  super.dispose();
@@ -2071,69 +2084,11 @@ var SvgLine = class extends BaseSvg {
2071
2084
 
2072
2085
  // src/elements/svg-polygon.ts
2073
2086
  var SvgPolygon = class extends BaseSvg {
2087
+ circles = [];
2088
+ lines = [];
2089
+ isClose = false;
2074
2090
  constructor(context) {
2075
2091
  super(context);
2076
- __publicField(this, "circles", []);
2077
- __publicField(this, "lines", []);
2078
- __publicField(this, "isClose", false);
2079
- __publicField(this, "onUpdate", () => {
2080
- if (this.points.length) {
2081
- this.points.forEach((point3, index) => {
2082
- const devicePoint = this.getSvgCoordinate(point3);
2083
- if (this.circles[index]) {
2084
- setCirclePosition(this.circles[index], devicePoint.x, devicePoint.y);
2085
- }
2086
- if (index !== 0) {
2087
- setLineStartEnd(this.lines[index - 1], void 0, devicePoint);
2088
- }
2089
- if (this.lines[index]) {
2090
- setLineStartEnd(this.lines[index], devicePoint);
2091
- }
2092
- });
2093
- }
2094
- });
2095
- __publicField(this, "onPointermove", (e) => {
2096
- if (!this.lastLine || this.isClose) {
2097
- return;
2098
- }
2099
- this.lastLine.style.display = "block";
2100
- setLineStartEnd(this.lastLine, void 0, { x: e.offsetX, y: e.offsetY });
2101
- });
2102
- __publicField(this, "onPointerleave", () => {
2103
- if (this.isClose) {
2104
- return;
2105
- }
2106
- this.lastLine.style.display = "none";
2107
- });
2108
- __publicField(this, "onPointerdown", (e) => {
2109
- if (this.isClose) {
2110
- return;
2111
- }
2112
- const point3 = this.getIntersectByPointerEvent(e);
2113
- if (point3) {
2114
- const { offsetX: x, offsetY: y } = e;
2115
- if (this.checkAdsorb(x, y)) {
2116
- this.isClose = true;
2117
- this.addPoint(this.points[0]);
2118
- } else {
2119
- this.addPoint(point3);
2120
- }
2121
- const { circle: { fill, radius }, line: { stroke } } = this.context.config.svg;
2122
- if (!this.isClose) {
2123
- const circle = createCircle(radius, fill);
2124
- setCirclePosition(circle, x, y);
2125
- this.addCircle(circle);
2126
- }
2127
- if (this.lines.length) {
2128
- setLineStartEnd(this.lastLine, void 0, { x, y });
2129
- }
2130
- if (!this.isClose) {
2131
- const line = createLine(stroke);
2132
- setLineStartEnd(line, { x, y }, { x, y });
2133
- this.addLine(line);
2134
- }
2135
- }
2136
- });
2137
2092
  this.registryEvent();
2138
2093
  }
2139
2094
  setEnable(enable) {
@@ -2169,6 +2124,64 @@ var SvgPolygon = class extends BaseSvg {
2169
2124
  this.context.container.removeEventListener("pointerdown", this.onPointerdown);
2170
2125
  this.context.removeEventListener("update", this.onUpdate);
2171
2126
  }
2127
+ onUpdate = () => {
2128
+ if (this.points.length) {
2129
+ this.points.forEach((point3, index) => {
2130
+ const devicePoint = this.getSvgCoordinate(point3);
2131
+ if (this.circles[index]) {
2132
+ setCirclePosition(this.circles[index], devicePoint.x, devicePoint.y);
2133
+ }
2134
+ if (index !== 0) {
2135
+ setLineStartEnd(this.lines[index - 1], void 0, devicePoint);
2136
+ }
2137
+ if (this.lines[index]) {
2138
+ setLineStartEnd(this.lines[index], devicePoint);
2139
+ }
2140
+ });
2141
+ }
2142
+ };
2143
+ onPointermove = (e) => {
2144
+ if (!this.lastLine || this.isClose) {
2145
+ return;
2146
+ }
2147
+ this.lastLine.style.display = "block";
2148
+ setLineStartEnd(this.lastLine, void 0, { x: e.offsetX, y: e.offsetY });
2149
+ };
2150
+ onPointerleave = () => {
2151
+ if (this.isClose) {
2152
+ return;
2153
+ }
2154
+ this.lastLine.style.display = "none";
2155
+ };
2156
+ onPointerdown = (e) => {
2157
+ if (this.isClose) {
2158
+ return;
2159
+ }
2160
+ const point3 = this.getIntersectByPointerEvent(e);
2161
+ if (point3) {
2162
+ const { offsetX: x, offsetY: y } = e;
2163
+ if (this.checkAdsorb(x, y)) {
2164
+ this.isClose = true;
2165
+ this.addPoint(this.points[0]);
2166
+ } else {
2167
+ this.addPoint(point3);
2168
+ }
2169
+ const { circle: { fill, radius }, line: { stroke } } = this.context.config.svg;
2170
+ if (!this.isClose) {
2171
+ const circle = createCircle(radius, fill);
2172
+ setCirclePosition(circle, x, y);
2173
+ this.addCircle(circle);
2174
+ }
2175
+ if (this.lines.length) {
2176
+ setLineStartEnd(this.lastLine, void 0, { x, y });
2177
+ }
2178
+ if (!this.isClose) {
2179
+ const line = createLine(stroke);
2180
+ setLineStartEnd(line, { x, y }, { x, y });
2181
+ this.addLine(line);
2182
+ }
2183
+ }
2184
+ };
2172
2185
  /**
2173
2186
  * 检测是否可以吸附
2174
2187
  * 坐标点最少3个 传入的坐标点和第一个坐标的像素相差不超过5个像素
@@ -2180,7 +2193,7 @@ var SvgPolygon = class extends BaseSvg {
2180
2193
  const circle = this.circles[0];
2181
2194
  const cx = +circle.getAttribute("cx");
2182
2195
  const cy = +circle.getAttribute("cy");
2183
- return Math.sqrt(__pow(x - cx, 2) + __pow(y - cy, 2)) <= 5;
2196
+ return Math.sqrt((x - cx) ** 2 + (y - cy) ** 2) <= 5;
2184
2197
  }
2185
2198
  addPoint(vector) {
2186
2199
  this.points.push(vector);
@@ -2214,60 +2227,6 @@ var SelectBox = class extends BaseSvg {
2214
2227
  constructor(context) {
2215
2228
  super(context);
2216
2229
  this.context = context;
2217
- __publicField(this, "rect");
2218
- __publicField(this, "cornerRect", []);
2219
- // 四个角上的方块
2220
- __publicField(this, "centerRect", []);
2221
- // 四个线中间的方块
2222
- __publicField(this, "graphic");
2223
- __publicField(this, "onUpdate", () => {
2224
- if (!this.graphic) {
2225
- setRectPosition(this.rect, 0, 0, 0, 0);
2226
- for (let i = 0; i < this.cornerRect.length; i++) {
2227
- setRectPosition(this.cornerRect[i], 0, 0, 0, 0);
2228
- setRectPosition(this.centerRect[i], 0, 0, 0, 0);
2229
- }
2230
- } else {
2231
- const box = new Box36().setFromObject(this.graphic);
2232
- const { camera, container: { clientWidth: w, clientHeight: h } } = this.context;
2233
- const { min, max } = box;
2234
- const leftBottom = vector3ToDevice(min, camera, w, h);
2235
- const rightTop = vector3ToDevice(max, camera, w, h);
2236
- setRectPosition(this.rect, leftBottom.x, rightTop.y, Math.abs(rightTop.x - leftBottom.x), Math.abs(rightTop.y - leftBottom.y));
2237
- const { x: left, y: bottom } = leftBottom;
2238
- const { x: right, y: top } = rightTop;
2239
- const halfWidth = 5;
2240
- const corners = [
2241
- { x: left - halfWidth, y: top - halfWidth },
2242
- // 左上角
2243
- { x: right - halfWidth, y: top - halfWidth },
2244
- // 右上角
2245
- { x: left - halfWidth, y: bottom - halfWidth },
2246
- // 左下角
2247
- { x: right - halfWidth, y: bottom - halfWidth }
2248
- // 右下角
2249
- ];
2250
- for (let i = 0; i < corners.length; i++) {
2251
- setRectPosition(this.cornerRect[i], corners[i].x, corners[i].y, halfWidth * 2, halfWidth * 2);
2252
- }
2253
- const centerHalfWidth = 4;
2254
- const centerX = (left + right) / 2;
2255
- const centerY = (bottom + top) / 2;
2256
- const centers = [
2257
- { x: centerX - centerHalfWidth, y: top - centerHalfWidth },
2258
- // 上
2259
- { x: left - centerHalfWidth, y: centerY - centerHalfWidth },
2260
- // 左
2261
- { x: right - centerHalfWidth, y: centerY - centerHalfWidth },
2262
- // 右
2263
- { x: centerX - centerHalfWidth, y: bottom - centerHalfWidth }
2264
- // 下
2265
- ];
2266
- for (let i = 0; i < centers.length; i++) {
2267
- setRectPosition(this.centerRect[i], centers[i].x, centers[i].y, centerHalfWidth * 2, centerHalfWidth * 2);
2268
- }
2269
- }
2270
- });
2271
2230
  const { config: { svg: { line } } } = context;
2272
2231
  this.rect = createRect(line.stroke, "transparent");
2273
2232
  this.svg.appendChild(this.rect);
@@ -2279,6 +2238,12 @@ var SelectBox = class extends BaseSvg {
2279
2238
  }
2280
2239
  this.registryEvent();
2281
2240
  }
2241
+ rect;
2242
+ cornerRect = [];
2243
+ // 四个角上的方块
2244
+ centerRect = [];
2245
+ // 四个线中间的方块
2246
+ graphic;
2282
2247
  setEnable(enable) {
2283
2248
  super.setEnable(enable);
2284
2249
  if (enable) {
@@ -2293,6 +2258,54 @@ var SelectBox = class extends BaseSvg {
2293
2258
  unRegistryEvent() {
2294
2259
  this.context.removeEventListener("update", this.onUpdate);
2295
2260
  }
2261
+ onUpdate = () => {
2262
+ if (!this.graphic) {
2263
+ setRectPosition(this.rect, 0, 0, 0, 0);
2264
+ for (let i = 0; i < this.cornerRect.length; i++) {
2265
+ setRectPosition(this.cornerRect[i], 0, 0, 0, 0);
2266
+ setRectPosition(this.centerRect[i], 0, 0, 0, 0);
2267
+ }
2268
+ } else {
2269
+ const box = new Box36().setFromObject(this.graphic);
2270
+ const { camera, container: { clientWidth: w, clientHeight: h } } = this.context;
2271
+ const { min, max } = box;
2272
+ const leftBottom = vector3ToDevice(min, camera, w, h);
2273
+ const rightTop = vector3ToDevice(max, camera, w, h);
2274
+ setRectPosition(this.rect, leftBottom.x, rightTop.y, Math.abs(rightTop.x - leftBottom.x), Math.abs(rightTop.y - leftBottom.y));
2275
+ const { x: left, y: bottom } = leftBottom;
2276
+ const { x: right, y: top } = rightTop;
2277
+ const halfWidth = 5;
2278
+ const corners = [
2279
+ { x: left - halfWidth, y: top - halfWidth },
2280
+ // 左上角
2281
+ { x: right - halfWidth, y: top - halfWidth },
2282
+ // 右上角
2283
+ { x: left - halfWidth, y: bottom - halfWidth },
2284
+ // 左下角
2285
+ { x: right - halfWidth, y: bottom - halfWidth }
2286
+ // 右下角
2287
+ ];
2288
+ for (let i = 0; i < corners.length; i++) {
2289
+ setRectPosition(this.cornerRect[i], corners[i].x, corners[i].y, halfWidth * 2, halfWidth * 2);
2290
+ }
2291
+ const centerHalfWidth = 4;
2292
+ const centerX = (left + right) / 2;
2293
+ const centerY = (bottom + top) / 2;
2294
+ const centers = [
2295
+ { x: centerX - centerHalfWidth, y: top - centerHalfWidth },
2296
+ // 上
2297
+ { x: left - centerHalfWidth, y: centerY - centerHalfWidth },
2298
+ // 左
2299
+ { x: right - centerHalfWidth, y: centerY - centerHalfWidth },
2300
+ // 右
2301
+ { x: centerX - centerHalfWidth, y: bottom - centerHalfWidth }
2302
+ // 下
2303
+ ];
2304
+ for (let i = 0; i < centers.length; i++) {
2305
+ setRectPosition(this.centerRect[i], centers[i].x, centers[i].y, centerHalfWidth * 2, centerHalfWidth * 2);
2306
+ }
2307
+ }
2308
+ };
2296
2309
  selectGraphic(graphic) {
2297
2310
  this.graphic = graphic;
2298
2311
  }
@@ -2308,57 +2321,12 @@ var SelectBox = class extends BaseSvg {
2308
2321
  // src/operations/selection/box-selection.ts
2309
2322
  import { Frustum } from "three";
2310
2323
  var BoxSelection = class extends BaseSvg {
2324
+ startPoint;
2325
+ endPoint;
2326
+ rect;
2327
+ frustum = new Frustum();
2311
2328
  constructor(context) {
2312
2329
  super(context);
2313
- __publicField(this, "startPoint");
2314
- __publicField(this, "endPoint");
2315
- __publicField(this, "rect");
2316
- __publicField(this, "frustum", new Frustum());
2317
- __publicField(this, "onPointerDown", (e) => {
2318
- if (!this.enable) {
2319
- return;
2320
- }
2321
- const point3 = this.getIntersectByPointerEvent(e);
2322
- if (point3) {
2323
- this.startPoint = point3;
2324
- }
2325
- this.endPoint = void 0;
2326
- });
2327
- __publicField(this, "onPointerMove", (e) => {
2328
- if (!this.enable || !this.startPoint) {
2329
- return;
2330
- }
2331
- const point3 = this.getIntersectByPointerEvent(e);
2332
- if (point3) {
2333
- this.endPoint = point3;
2334
- }
2335
- });
2336
- __publicField(this, "onPointerUp", (e) => {
2337
- if (!this.enable) {
2338
- return;
2339
- }
2340
- const point3 = this.getIntersectByPointerEvent(e);
2341
- if (point3) {
2342
- this.endPoint = point3;
2343
- }
2344
- this.doSelect();
2345
- this.startPoint = void 0;
2346
- });
2347
- __publicField(this, "onUpdate", () => {
2348
- if (this.startPoint) {
2349
- const startPoint = this.getSvgCoordinate(this.startPoint);
2350
- let endPoint = __spreadValues({}, startPoint);
2351
- if (this.endPoint) {
2352
- endPoint = this.getSvgCoordinate(this.endPoint);
2353
- }
2354
- const leftTop = { x: Math.min(startPoint.x, endPoint.x), y: Math.min(startPoint.y, endPoint.y) };
2355
- const width = Math.abs(endPoint.x - startPoint.x);
2356
- const height = Math.abs(endPoint.y - startPoint.y);
2357
- setRectPosition(this.rect, leftTop.x, leftTop.y, width, height);
2358
- } else {
2359
- setRectPosition(this.rect, 0, 0, 0, 0);
2360
- }
2361
- });
2362
2330
  const { config: { selectBox: { fill, stroke } } } = context;
2363
2331
  this.rect = createRect(stroke, fill);
2364
2332
  this.svg.appendChild(this.rect);
@@ -2374,6 +2342,51 @@ var BoxSelection = class extends BaseSvg {
2374
2342
  this.unRegistryEvent();
2375
2343
  }
2376
2344
  }
2345
+ onPointerDown = (e) => {
2346
+ if (!this.enable) {
2347
+ return;
2348
+ }
2349
+ const point3 = this.getIntersectByPointerEvent(e);
2350
+ if (point3) {
2351
+ this.startPoint = point3;
2352
+ }
2353
+ this.endPoint = void 0;
2354
+ };
2355
+ onPointerMove = (e) => {
2356
+ if (!this.enable || !this.startPoint) {
2357
+ return;
2358
+ }
2359
+ const point3 = this.getIntersectByPointerEvent(e);
2360
+ if (point3) {
2361
+ this.endPoint = point3;
2362
+ }
2363
+ };
2364
+ onPointerUp = (e) => {
2365
+ if (!this.enable) {
2366
+ return;
2367
+ }
2368
+ const point3 = this.getIntersectByPointerEvent(e);
2369
+ if (point3) {
2370
+ this.endPoint = point3;
2371
+ }
2372
+ this.doSelect();
2373
+ this.startPoint = void 0;
2374
+ };
2375
+ onUpdate = () => {
2376
+ if (this.startPoint) {
2377
+ const startPoint = this.getSvgCoordinate(this.startPoint);
2378
+ let endPoint = { ...startPoint };
2379
+ if (this.endPoint) {
2380
+ endPoint = this.getSvgCoordinate(this.endPoint);
2381
+ }
2382
+ const leftTop = { x: Math.min(startPoint.x, endPoint.x), y: Math.min(startPoint.y, endPoint.y) };
2383
+ const width = Math.abs(endPoint.x - startPoint.x);
2384
+ const height = Math.abs(endPoint.y - startPoint.y);
2385
+ setRectPosition(this.rect, leftTop.x, leftTop.y, width, height);
2386
+ } else {
2387
+ setRectPosition(this.rect, 0, 0, 0, 0);
2388
+ }
2389
+ };
2377
2390
  registryEvent() {
2378
2391
  this.context.container.addEventListener("pointerdown", this.onPointerDown);
2379
2392
  this.context.container.addEventListener("pointermove", this.onPointerMove);
@@ -2402,11 +2415,10 @@ var BoxSelection = class extends BaseSvg {
2402
2415
  }
2403
2416
  }
2404
2417
  searchMapInFrustum(leftTop, rightBottom) {
2405
- var _a;
2406
2418
  const { context } = this;
2407
- return ((_a = context.currentFloor) == null ? void 0 : _a.graphicLayer.children.filter((item) => {
2419
+ return context.currentFloor?.graphicLayer.children.filter((item) => {
2408
2420
  return item instanceof Graphic && this.searchChildInFrustum(item, leftTop, rightBottom);
2409
- })) || [];
2421
+ }) || [];
2410
2422
  }
2411
2423
  searchChildInFrustum(object, leftTop, rightBottom) {
2412
2424
  const { context: { camera, container: { clientWidth: w, clientHeight: h } } } = this;
@@ -2448,68 +2460,16 @@ var Selection = class extends EventDispatcher4 {
2448
2460
  constructor(context) {
2449
2461
  super();
2450
2462
  this.context = context;
2451
- __publicField(this, "_list", /* @__PURE__ */ new Set());
2452
- __publicField(this, "boxSelection");
2453
- __publicField(this, "prevPanStatus");
2454
- __publicField(this, "prevRotateStatus");
2455
- __publicField(this, "downPoint", null);
2456
- __publicField(this, "isMultipleSelect", false);
2457
- __publicField(this, "onPointerDown", (e) => {
2458
- this.downPoint = { x: e.offsetX, y: e.offsetY };
2459
- });
2460
- __publicField(this, "onPointerUp", (e) => {
2461
- if (!this.downPoint) {
2462
- return;
2463
- }
2464
- const { offsetX, offsetY } = e;
2465
- const { x, y } = this.downPoint;
2466
- if (Math.sqrt(__pow(x - offsetX, 2) + __pow(y - offsetY, 2)) > 3) {
2467
- return;
2468
- }
2469
- const { graphics } = this.context.getGraphicsByDeviceXy(offsetX, offsetY);
2470
- const graphicIdSet = new Set(graphics.map((item) => item.options.id));
2471
- const pois = this.context.getPoisByDeviceXy(offsetX, offsetY);
2472
- pois.forEach((item) => {
2473
- var _a;
2474
- if (!graphicIdSet.has(item.options.id)) {
2475
- const graphic = ((_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.graphicMap.get(item.options.id)) || null;
2476
- if (graphic && graphic.options.geometry.type === "point") {
2477
- graphics.push(graphic);
2478
- graphicIdSet.add(item.options.id);
2479
- }
2480
- }
2481
- });
2482
- if (!(isMac ? e.metaKey : e.ctrlKey)) {
2483
- this._list.clear();
2484
- }
2485
- graphics.forEach((item) => this._list.add(item));
2486
- this.selectEnd();
2487
- this.downPoint = null;
2488
- });
2489
- __publicField(this, "onPointerOut", (e) => {
2490
- this.disableBoxSelection();
2491
- });
2492
- __publicField(this, "onKeyDown", (e) => {
2493
- if (isControl(e.key)) {
2494
- this.enableBoxSelection();
2495
- }
2496
- });
2497
- __publicField(this, "onKeyUp", (e) => {
2498
- if (isControl(e.key)) {
2499
- this.disableBoxSelection();
2500
- }
2501
- });
2502
- __publicField(this, "onBoxSelected", ({ list }) => {
2503
- this._list.clear();
2504
- list.forEach((item) => {
2505
- this._list.add(item);
2506
- });
2507
- this.selectEnd();
2508
- });
2509
2463
  this.boxSelection = new BoxSelection(context);
2510
2464
  this.boxSelection.setEnable(false);
2511
2465
  this.registryEvent();
2512
2466
  }
2467
+ _list = /* @__PURE__ */ new Set();
2468
+ boxSelection;
2469
+ prevPanStatus;
2470
+ prevRotateStatus;
2471
+ downPoint = null;
2472
+ isMultipleSelect = false;
2513
2473
  get list() {
2514
2474
  return this._list;
2515
2475
  }
@@ -2532,6 +2492,57 @@ var Selection = class extends EventDispatcher4 {
2532
2492
  this.context.control.enableRotate = !!this.prevRotateStatus;
2533
2493
  }
2534
2494
  }
2495
+ onPointerDown = (e) => {
2496
+ this.downPoint = { x: e.offsetX, y: e.offsetY };
2497
+ };
2498
+ onPointerUp = (e) => {
2499
+ if (!this.downPoint) {
2500
+ return;
2501
+ }
2502
+ const { offsetX, offsetY } = e;
2503
+ const { x, y } = this.downPoint;
2504
+ if (Math.sqrt((x - offsetX) ** 2 + (y - offsetY) ** 2) > 3) {
2505
+ return;
2506
+ }
2507
+ const { graphics } = this.context.getGraphicsByDeviceXy(offsetX, offsetY);
2508
+ const graphicIdSet = new Set(graphics.map((item) => item.options.id));
2509
+ const pois = this.context.getPoisByDeviceXy(offsetX, offsetY);
2510
+ pois.forEach((item) => {
2511
+ if (!graphicIdSet.has(item.options.id)) {
2512
+ const graphic = this.context.currentFloor?.graphicLayer.graphicMap.get(item.options.id) || null;
2513
+ if (graphic && graphic.options.geometry.type === "point") {
2514
+ graphics.push(graphic);
2515
+ graphicIdSet.add(item.options.id);
2516
+ }
2517
+ }
2518
+ });
2519
+ if (!(isMac ? e.metaKey : e.ctrlKey)) {
2520
+ this._list.clear();
2521
+ }
2522
+ graphics.forEach((item) => this._list.add(item));
2523
+ this.selectEnd();
2524
+ this.downPoint = null;
2525
+ };
2526
+ onPointerOut = (e) => {
2527
+ this.disableBoxSelection();
2528
+ };
2529
+ onKeyDown = (e) => {
2530
+ if (isControl(e.key)) {
2531
+ this.enableBoxSelection();
2532
+ }
2533
+ };
2534
+ onKeyUp = (e) => {
2535
+ if (isControl(e.key)) {
2536
+ this.disableBoxSelection();
2537
+ }
2538
+ };
2539
+ onBoxSelected = ({ list }) => {
2540
+ this._list.clear();
2541
+ list.forEach((item) => {
2542
+ this._list.add(item);
2543
+ });
2544
+ this.selectEnd();
2545
+ };
2535
2546
  selectEnd() {
2536
2547
  this.dispatchEvent({ type: "select", graphics: [...this._list], isMultipleSelect: this.isMultipleSelect });
2537
2548
  }
@@ -2570,75 +2581,72 @@ var HoverHelper = class extends EventDispatcher5 {
2570
2581
  constructor(context) {
2571
2582
  super();
2572
2583
  this.context = context;
2573
- __publicField(this, "curGraphics", /* @__PURE__ */ new Set());
2574
- __publicField(this, "timer", new Timer());
2575
- __publicField(this, "graphicTimerMap", /* @__PURE__ */ new Map());
2576
- __publicField(this, "onPointerMove", ({ graphics, pois, e }) => {
2577
- const poiGraphics = pois.map((item) => {
2578
- var _a;
2579
- return (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.graphicMap.get(item.options.id);
2580
- }).filter((graphic) => graphic && graphic.options.geometry.type === "point");
2581
- if (!graphics.length && !poiGraphics.length && this.curGraphics.size) {
2582
- this.curGraphics.clear();
2583
- this.handleHoverGraphicsChange();
2584
+ this.registryEvent();
2585
+ }
2586
+ curGraphics = /* @__PURE__ */ new Set();
2587
+ timer = new Timer();
2588
+ graphicTimerMap = /* @__PURE__ */ new Map();
2589
+ onPointerMove = ({ graphics, pois, e }) => {
2590
+ const poiGraphics = pois.map((item) => this.context.currentFloor?.graphicLayer.graphicMap.get(item.options.id)).filter((graphic) => graphic && graphic.options.geometry.type === "point");
2591
+ if (!graphics.length && !poiGraphics.length && this.curGraphics.size) {
2592
+ this.curGraphics.clear();
2593
+ this.handleHoverGraphicsChange();
2594
+ return;
2595
+ }
2596
+ const { time } = this.context.config.hover;
2597
+ const allGraphics = /* @__PURE__ */ new Set();
2598
+ if (poiGraphics.length) {
2599
+ let resGraphic;
2600
+ let distance = 1e4;
2601
+ poiGraphics.forEach((graphic) => {
2602
+ const poi = pois.find((poi2) => poi2.options.id === graphic.options.id);
2603
+ const { x, y } = poi.clientPos;
2604
+ let curDistance = Math.sqrt((x - e.offsetX) ** 2 + (y - e.offsetY) ** 2);
2605
+ if (curDistance < distance) {
2606
+ distance = curDistance;
2607
+ resGraphic = graphic;
2608
+ }
2609
+ });
2610
+ allGraphics.add(resGraphic);
2611
+ }
2612
+ if (!allGraphics.size) {
2613
+ graphics.forEach((graphic) => allGraphics.add(graphic));
2614
+ }
2615
+ allGraphics.forEach((graphic) => {
2616
+ if (this.graphicTimerMap.get(graphic)) {
2584
2617
  return;
2585
2618
  }
2586
- const { time } = this.context.config.hover;
2587
- const allGraphics = /* @__PURE__ */ new Set();
2588
- if (poiGraphics.length) {
2589
- let resGraphic;
2590
- let distance = 1e4;
2591
- poiGraphics.forEach((graphic) => {
2592
- const poi = pois.find((poi2) => poi2.options.id === graphic.options.id);
2593
- const { x, y } = poi.clientPos;
2594
- let curDistance = Math.sqrt(__pow(x - e.offsetX, 2) + __pow(y - e.offsetY, 2));
2595
- if (curDistance < distance) {
2596
- distance = curDistance;
2597
- resGraphic = graphic;
2598
- }
2599
- });
2600
- allGraphics.add(resGraphic);
2601
- }
2602
- if (!allGraphics.size) {
2603
- graphics.forEach((graphic) => allGraphics.add(graphic));
2619
+ if (this.curGraphics.has(graphic)) {
2620
+ return;
2604
2621
  }
2605
- allGraphics.forEach((graphic) => {
2606
- if (this.graphicTimerMap.get(graphic)) {
2607
- return;
2608
- }
2609
- if (this.curGraphics.has(graphic)) {
2610
- return;
2611
- }
2612
- const timer = this.timer.setTimeout(() => {
2613
- this.curGraphics.add(graphic);
2614
- this.graphicTimerMap.delete(graphic);
2615
- this.timer.clearTimeout(timer);
2616
- this.handleHoverGraphicsChange();
2617
- }, time);
2618
- this.graphicTimerMap.set(graphic, timer);
2619
- });
2620
- this.graphicTimerMap.forEach((timer, graphic) => {
2621
- if (!allGraphics.has(graphic)) {
2622
- this.timer.clearTimeout(timer);
2623
- this.graphicTimerMap.delete(graphic);
2624
- }
2625
- });
2626
- const size = this.curGraphics.size;
2627
- this.curGraphics.forEach((graphic) => {
2628
- if (!allGraphics.has(graphic)) {
2629
- this.curGraphics.delete(graphic);
2630
- }
2631
- });
2632
- if (size !== this.curGraphics.size) {
2622
+ const timer = this.timer.setTimeout(() => {
2623
+ this.curGraphics.add(graphic);
2624
+ this.graphicTimerMap.delete(graphic);
2625
+ this.timer.clearTimeout(timer);
2633
2626
  this.handleHoverGraphicsChange();
2627
+ }, time);
2628
+ this.graphicTimerMap.set(graphic, timer);
2629
+ });
2630
+ this.graphicTimerMap.forEach((timer, graphic) => {
2631
+ if (!allGraphics.has(graphic)) {
2632
+ this.timer.clearTimeout(timer);
2633
+ this.graphicTimerMap.delete(graphic);
2634
2634
  }
2635
2635
  });
2636
- __publicField(this, "onPointerLevel", () => {
2637
- this.curGraphics.clear();
2638
- this.handleHoverGraphicsChange();
2636
+ const size = this.curGraphics.size;
2637
+ this.curGraphics.forEach((graphic) => {
2638
+ if (!allGraphics.has(graphic)) {
2639
+ this.curGraphics.delete(graphic);
2640
+ }
2639
2641
  });
2640
- this.registryEvent();
2641
- }
2642
+ if (size !== this.curGraphics.size) {
2643
+ this.handleHoverGraphicsChange();
2644
+ }
2645
+ };
2646
+ onPointerLevel = () => {
2647
+ this.curGraphics.clear();
2648
+ this.handleHoverGraphicsChange();
2649
+ };
2642
2650
  handleHoverGraphicsChange(graphics = this.curGraphics) {
2643
2651
  this.dispatchEvent({ type: "hover-change", graphics: Array.from(graphics) });
2644
2652
  }
@@ -2673,11 +2681,11 @@ function vectorToString(vector) {
2673
2681
  var MaterialFactory = class {
2674
2682
  constructor(context) {
2675
2683
  this.context = context;
2676
- __publicField(this, "lineMaterialMap", /* @__PURE__ */ new Map());
2677
- __publicField(this, "meshStandardMaterialMap", /* @__PURE__ */ new Map());
2678
- __publicField(this, "meshBasicMaterialMap", /* @__PURE__ */ new Map());
2679
- __publicField(this, "shaderMaterialMap", /* @__PURE__ */ new Map());
2680
2684
  }
2685
+ lineMaterialMap = /* @__PURE__ */ new Map();
2686
+ meshStandardMaterialMap = /* @__PURE__ */ new Map();
2687
+ meshBasicMaterialMap = /* @__PURE__ */ new Map();
2688
+ shaderMaterialMap = /* @__PURE__ */ new Map();
2681
2689
  generateLineMaterialKey({ color, opacity }) {
2682
2690
  return `${color}-${opacity}`;
2683
2691
  }
@@ -2836,17 +2844,15 @@ import { Box3 as Box37, Vector3 as Vector312 } from "three";
2836
2844
  var CameraBound = class {
2837
2845
  constructor(context) {
2838
2846
  this.context = context;
2839
- __publicField(this, "prevCamera", {
2840
- position: new Vector312(),
2841
- zoom: 1,
2842
- target: new Vector312()
2843
- });
2844
- __publicField(this, "enable", true);
2845
- __publicField(this, "onCameraChange", () => {
2846
- });
2847
2847
  this.registryEvent();
2848
2848
  this.changePrevCamera();
2849
2849
  }
2850
+ prevCamera = {
2851
+ position: new Vector312(),
2852
+ zoom: 1,
2853
+ target: new Vector312()
2854
+ };
2855
+ enable = true;
2850
2856
  setEnable(enable) {
2851
2857
  this.enable = enable;
2852
2858
  if (enable) {
@@ -2903,6 +2909,8 @@ var CameraBound = class {
2903
2909
  const [pt, pr, pb, pl] = this.context.config.cameraBound.padding;
2904
2910
  return left <= pl && width - right <= pr && top <= pt && height - bottom <= pb;
2905
2911
  }
2912
+ onCameraChange = () => {
2913
+ };
2906
2914
  dispose() {
2907
2915
  this.unRegistryEvent();
2908
2916
  }
@@ -2914,74 +2922,6 @@ var Context = class extends EventDispatcher6 {
2914
2922
  super();
2915
2923
  this.container = container;
2916
2924
  this.config = config;
2917
- __publicField(this, "scene", initScene());
2918
- __publicField(this, "renderer", initRenderer());
2919
- __publicField(this, "camera");
2920
- __publicField(this, "control");
2921
- __publicField(this, "lights", initLight());
2922
- // 管理任务,防止内存泄漏
2923
- __publicField(this, "timer", new Timer());
2924
- __publicField(this, "tweenGroup", new TweenGroup());
2925
- __publicField(this, "currentFloor");
2926
- __publicField(this, "selection");
2927
- __publicField(this, "hoverHelper");
2928
- __publicField(this, "basicRatio");
2929
- // zoom=1的时候,100M对应的像素个数
2930
- __publicField(this, "materialFactory");
2931
- __publicField(this, "cameraBound");
2932
- __publicField(this, "clientSize", {
2933
- width: 0,
2934
- height: 0,
2935
- x: 0,
2936
- y: 0
2937
- });
2938
- __publicField(this, "onWindowResize", () => {
2939
- const { container, camera, renderer } = this;
2940
- let { clientWidth: w, clientHeight: h } = container;
2941
- w = Math.max(1, w);
2942
- h = Math.max(1, h);
2943
- camera.left = -w / 2;
2944
- camera.right = w / 2;
2945
- camera.top = h / 2;
2946
- camera.bottom = -h / 2;
2947
- camera.updateProjectionMatrix();
2948
- renderer.setSize(w, h);
2949
- this.resizeClientSize();
2950
- this.dispatchEvent({ type: "resize", width: w, height: h });
2951
- });
2952
- __publicField(this, "onClick", (e) => {
2953
- const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
2954
- if (graphics.length) {
2955
- this.dispatchEvent({
2956
- type: "graphic-click",
2957
- graphics,
2958
- position
2959
- });
2960
- }
2961
- const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
2962
- if (pois.length) {
2963
- this.dispatchEvent({ type: "poi-click", pois });
2964
- }
2965
- });
2966
- __publicField(this, "onPointerover", (e) => {
2967
- const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
2968
- const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
2969
- this.dispatchEvent({ type: "pointer-over", e, graphics, pois, position });
2970
- });
2971
- __publicField(this, "onPointermove", (e) => {
2972
- const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
2973
- const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
2974
- this.dispatchEvent({ type: "pointer-move", e, graphics, pois, position });
2975
- });
2976
- __publicField(this, "onPointerleave", () => {
2977
- this.dispatchEvent({ type: "pointer-level" });
2978
- });
2979
- __publicField(this, "onSelectionSelect", ({ graphics, isMultipleSelect }) => {
2980
- this.dispatchEvent({ type: "select-graphic", graphics, isMultipleSelect });
2981
- });
2982
- __publicField(this, "onHoverChange", ({ graphics }) => {
2983
- this.dispatchEvent({ type: "hover", graphics });
2984
- });
2985
2925
  this.container.style.position = "relative";
2986
2926
  this.container.style.overflow = "hidden";
2987
2927
  this.init();
@@ -2991,6 +2931,27 @@ var Context = class extends EventDispatcher6 {
2991
2931
  this.resizeClientSize();
2992
2932
  this.registryEvent();
2993
2933
  }
2934
+ scene = initScene();
2935
+ renderer = initRenderer();
2936
+ camera;
2937
+ control;
2938
+ lights = initLight();
2939
+ // 管理任务,防止内存泄漏
2940
+ timer = new Timer();
2941
+ tweenGroup = new TweenGroup();
2942
+ currentFloor;
2943
+ selection;
2944
+ hoverHelper;
2945
+ basicRatio;
2946
+ // zoom=1的时候,100M对应的像素个数
2947
+ materialFactory;
2948
+ cameraBound;
2949
+ clientSize = {
2950
+ width: 0,
2951
+ height: 0,
2952
+ x: 0,
2953
+ y: 0
2954
+ };
2994
2955
  resizeClientSize() {
2995
2956
  const { x, y, width, height } = this.container.getBoundingClientRect();
2996
2957
  this.clientSize = {
@@ -3010,9 +2971,8 @@ var Context = class extends EventDispatcher6 {
3010
2971
  this.scene.add(this.lights);
3011
2972
  this.basicRatio = this.getRatio();
3012
2973
  this.control.addEventListener("change", () => {
3013
- var _a;
3014
2974
  const polarAngle = this.control.getPolarAngle();
3015
- (_a = this.currentFloor) == null ? void 0 : _a.setShadowOpacity(polarAngle / this.config.control.maxPolar);
2975
+ this.currentFloor?.setShadowOpacity(polarAngle / this.config.control.maxPolar);
3016
2976
  this.dispatchEvent({ type: "change-ratio", px: (this.basicRatio || 0) * this.camera.zoom });
3017
2977
  this.dispatchEvent({ type: "control-change" });
3018
2978
  });
@@ -3025,7 +2985,7 @@ var Context = class extends EventDispatcher6 {
3025
2985
  const { clientWidth, clientHeight } = this.container;
3026
2986
  const device1 = vector3ToDevice(point1, this.camera, clientWidth, clientHeight);
3027
2987
  const device2 = vector3ToDevice(point22, this.camera, clientWidth, clientHeight);
3028
- return Math.ceil(Math.sqrt(__pow(device2.x - device1.x, 2) + __pow(device2.y - device1.y, 2)));
2988
+ return Math.ceil(Math.sqrt((device2.x - device1.x) ** 2 + (device2.y - device1.y) ** 2));
3029
2989
  }
3030
2990
  changeAmbientLightColor(color) {
3031
2991
  this.lights.children.forEach((item) => {
@@ -3047,6 +3007,34 @@ var Context = class extends EventDispatcher6 {
3047
3007
  this.lights.position.y = position.y;
3048
3008
  }
3049
3009
  }
3010
+ onWindowResize = () => {
3011
+ const { container, camera, renderer } = this;
3012
+ let { clientWidth: w, clientHeight: h } = container;
3013
+ w = Math.max(1, w);
3014
+ h = Math.max(1, h);
3015
+ camera.left = -w / 2;
3016
+ camera.right = w / 2;
3017
+ camera.top = h / 2;
3018
+ camera.bottom = -h / 2;
3019
+ camera.updateProjectionMatrix();
3020
+ renderer.setSize(w, h);
3021
+ this.resizeClientSize();
3022
+ this.dispatchEvent({ type: "resize", width: w, height: h });
3023
+ };
3024
+ onClick = (e) => {
3025
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
3026
+ if (graphics.length) {
3027
+ this.dispatchEvent({
3028
+ type: "graphic-click",
3029
+ graphics,
3030
+ position
3031
+ });
3032
+ }
3033
+ const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
3034
+ if (pois.length) {
3035
+ this.dispatchEvent({ type: "poi-click", pois });
3036
+ }
3037
+ };
3050
3038
  /**
3051
3039
  * 获取屏幕坐标对应的graphic
3052
3040
  * @param x
@@ -3054,13 +3042,12 @@ var Context = class extends EventDispatcher6 {
3054
3042
  * @returns
3055
3043
  */
3056
3044
  getGraphicsByDeviceXy(x, y) {
3057
- var _a;
3058
3045
  const point3 = new Vector23();
3059
3046
  point3.x = x / this.clientSize.width * 2 - 1;
3060
3047
  point3.y = y / this.clientSize.height * -2 + 1;
3061
3048
  const raycaster = new Raycaster3();
3062
3049
  raycaster.setFromCamera(point3, this.camera);
3063
- const res = (_a = this.currentFloor) == null ? void 0 : _a.graphicLayer.getGraphicByRaycaster(raycaster);
3050
+ const res = this.currentFloor?.graphicLayer.getGraphicByRaycaster(raycaster);
3064
3051
  return res || { graphics: [], position: null };
3065
3052
  }
3066
3053
  /**
@@ -3070,10 +3057,28 @@ var Context = class extends EventDispatcher6 {
3070
3057
  * @returns
3071
3058
  */
3072
3059
  getPoisByDeviceXy(x, y) {
3073
- var _a;
3074
- const pois = (_a = this.currentFloor) == null ? void 0 : _a.poiLayer.getPoiByDeviceXy(x, y);
3060
+ const pois = this.currentFloor?.poiLayer.getPoiByDeviceXy(x, y);
3075
3061
  return pois || [];
3076
3062
  }
3063
+ onPointerover = (e) => {
3064
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
3065
+ const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
3066
+ this.dispatchEvent({ type: "pointer-over", e, graphics, pois, position });
3067
+ };
3068
+ onPointermove = (e) => {
3069
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
3070
+ const pois = this.getPoisByDeviceXy(e.offsetX, e.offsetY);
3071
+ this.dispatchEvent({ type: "pointer-move", e, graphics, pois, position });
3072
+ };
3073
+ onPointerleave = () => {
3074
+ this.dispatchEvent({ type: "pointer-level" });
3075
+ };
3076
+ onSelectionSelect = ({ graphics, isMultipleSelect }) => {
3077
+ this.dispatchEvent({ type: "select-graphic", graphics, isMultipleSelect });
3078
+ };
3079
+ onHoverChange = ({ graphics }) => {
3080
+ this.dispatchEvent({ type: "hover", graphics });
3081
+ };
3077
3082
  registryEvent() {
3078
3083
  window.addEventListener("resize", this.onWindowResize);
3079
3084
  this.container.addEventListener("click", this.onClick);
@@ -3216,10 +3221,10 @@ var Context = class extends EventDispatcher6 {
3216
3221
  const boundingBox = new Box38().setFromObject(object);
3217
3222
  this.setPolarAngle(polar, 0);
3218
3223
  const { max, min } = boundingBox;
3219
- const leftTop = new Vector313(min.x, max.y, min.z);
3220
- const rightTop = new Vector313(max.x, max.y, min.z);
3221
- const rightBottom = new Vector313(max.x, min.y, max.z);
3222
- const leftBottom = new Vector313(min.x, min.y, max.z);
3224
+ const leftTop = new Vector313(min.x, max.y, max.z);
3225
+ const rightTop = new Vector313(max.x, max.y, max.z);
3226
+ const rightBottom = new Vector313(max.x, min.y, min.z);
3227
+ const leftBottom = new Vector313(min.x, min.y, min.z);
3223
3228
  const leftTop2d = vector3ToDevice(leftTop, this.camera, width, height);
3224
3229
  const rightTop2d = vector3ToDevice(rightTop, this.camera, width, height);
3225
3230
  const leftBottom2d = vector3ToDevice(leftBottom, this.camera, width, height);
@@ -3234,7 +3239,7 @@ var Context = class extends EventDispatcher6 {
3234
3239
  const xScale = (width - right - left) / size.x;
3235
3240
  const yScale = (height - top - bottom) / size.y;
3236
3241
  const scale = Math.min(xScale, yScale);
3237
- const center2 = new Vector313((max.x + min.x) / 2, (max.y + min.y) / 2, 0);
3242
+ const center2 = new Vector313((max.x + min.x) / 2, (max.y + min.y) / 2, (max.z + min.z) / 2);
3238
3243
  return { zoom: scale * this.camera.zoom, center: center2 };
3239
3244
  }
3240
3245
  /**
@@ -3321,7 +3326,8 @@ var defaultConfig = {
3321
3326
  apiInfo: {},
3322
3327
  apiPath: {
3323
3328
  floorGraphic: "/api/inception-map/floor/get",
3324
- floorRange: "/api/inception-map/range/get"
3329
+ floorRange: "/api/inception-map/range/get",
3330
+ equipmentList: "/api/inception-map/equipment/get"
3325
3331
  },
3326
3332
  resizeObserver: false,
3327
3333
  initTransToMark: false,
@@ -3388,6 +3394,118 @@ function getConfig(config) {
3388
3394
 
3389
3395
  // src/bmap.ts
3390
3396
  import { debounce as debounce3 } from "lodash";
3397
+
3398
+ // src/plugins/base.ts
3399
+ var Plugin = class {
3400
+ bmap;
3401
+ constructor(bmap) {
3402
+ this.bmap = bmap;
3403
+ }
3404
+ dispose() {
3405
+ }
3406
+ };
3407
+
3408
+ // src/plugins/equipment/equipment.ts
3409
+ var Equipment = class extends Plugin {
3410
+ equipmentList = [];
3411
+ equipmentMap = /* @__PURE__ */ new Map();
3412
+ constructor(bmap) {
3413
+ super(bmap);
3414
+ this.fetchEquipment();
3415
+ this.bmap.event.on("switch_floor_after" /* SWITCH_FLOOR_AFTER */, this.onSwitchFloor);
3416
+ }
3417
+ async fetchEquipment() {
3418
+ const {
3419
+ apiDomain,
3420
+ apiPath: { equipmentList },
3421
+ apiInfo
3422
+ } = this.bmap.config;
3423
+ const url = `${apiDomain}${equipmentList}`;
3424
+ await fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
3425
+ this.equipmentList = res;
3426
+ this.equipmentMap = new Map(
3427
+ res.map((item) => [item.equipment_id, item])
3428
+ );
3429
+ });
3430
+ if (this.bmap.context.currentFloor) {
3431
+ this.changeGraphicToEquipment(
3432
+ this.bmap.context.currentFloor.graphicLayer.children
3433
+ );
3434
+ }
3435
+ }
3436
+ onSwitchFloor = (floor) => {
3437
+ if (!this.equipmentList.length) {
3438
+ return;
3439
+ }
3440
+ this.changeGraphicToEquipment(floor.graphics);
3441
+ };
3442
+ getGraphicEquipment(graphic) {
3443
+ return graphic.userData.data.info.userData.equipment;
3444
+ }
3445
+ changeGraphicToEquipment(graphics) {
3446
+ console.log(graphics);
3447
+ graphics.filter((graphic) => {
3448
+ const equipment = this.getGraphicEquipment(graphic);
3449
+ return equipment && this.equipmentMap.has(equipment);
3450
+ }).forEach((graphic) => {
3451
+ const equipment = this.equipmentMap.get(
3452
+ this.getGraphicEquipment(graphic)
3453
+ );
3454
+ const poi = this.bmap.createGraphicPoi(graphic, {
3455
+ icon: equipment?.equipment_icon,
3456
+ built_in: true,
3457
+ icon_size: [14, 14]
3458
+ });
3459
+ });
3460
+ }
3461
+ dispose() {
3462
+ this.bmap.event.off("switch_floor_after" /* SWITCH_FLOOR_AFTER */, this.onSwitchFloor);
3463
+ }
3464
+ };
3465
+
3466
+ // src/plugins/navigation/path.worker.ts
3467
+ var workerCode = `
3468
+ self.onmessage = (e) => {
3469
+ console.log(e.data)
3470
+ loadRoad("");
3471
+ getPath("", "")
3472
+ }
3473
+
3474
+ function loadRoad(project) {
3475
+ // \u8BF7\u6C42\u5168\u90E8\u697C\u5C42\u7684\u8DEF\u7F51
3476
+ console.log(project)
3477
+ self.postMessage("project")
3478
+ }
3479
+
3480
+ function getPath(start, end) {
3481
+ // \u89C4\u5212\u8DEF\u7EBF
3482
+ console.log(start, end)
3483
+ self.postMessage("getPath")
3484
+ }
3485
+ `;
3486
+ var path_worker_default = workerCode;
3487
+
3488
+ // src/plugins/navigation/navigation.ts
3489
+ var Navigation = class extends Plugin {
3490
+ worker_url = window.URL.createObjectURL(new Blob([path_worker_default], { type: "text/javascript" }));
3491
+ worker = new Worker(this.worker_url);
3492
+ constructor(bmap) {
3493
+ super(bmap);
3494
+ console.log(this.worker);
3495
+ this.worker.postMessage("initial");
3496
+ this.worker.onmessage = (e) => {
3497
+ console.log("onmessage", e.data);
3498
+ };
3499
+ }
3500
+ fetchRoad() {
3501
+ }
3502
+ dispose() {
3503
+ this.worker.terminate();
3504
+ window.URL.revokeObjectURL(this.worker_url);
3505
+ }
3506
+ };
3507
+
3508
+ // src/bmap.ts
3391
3509
  var MapTypePolar = /* @__PURE__ */ ((MapTypePolar2) => {
3392
3510
  MapTypePolar2[MapTypePolar2["D2"] = 0] = "D2";
3393
3511
  MapTypePolar2[MapTypePolar2["D3"] = 1.1] = "D3";
@@ -3397,178 +3515,196 @@ var BMap = class extends EventDispatcher7 {
3397
3515
  constructor(container, config = {}) {
3398
3516
  super();
3399
3517
  this.container = container;
3400
- __publicField(this, "config");
3401
- __publicField(this, "context");
3402
- __publicField(this, "polarKeys", []);
3403
- __publicField(this, "azimuthalKeys", []);
3404
- __publicField(this, "svgLine");
3405
- __publicField(this, "svgPolygon");
3406
- __publicField(this, "basicZoom", 1);
3407
- __publicField(this, "prevCameraZoom", 1);
3408
- __publicField(this, "type", "2d");
3409
- __publicField(this, "floorDataMap", /* @__PURE__ */ new Map());
3410
- __publicField(this, "buildingGroundMap", /* @__PURE__ */ new Map());
3411
- __publicField(this, "currentBuildGround", null);
3412
- __publicField(this, "observe", null);
3413
- __publicField(this, "onControlChange", () => {
3414
- const { camera: { zoom } } = this.context;
3415
- if (zoom !== this.prevCameraZoom) {
3416
- this.dispatchEvent({
3417
- type: "zoom-change",
3418
- basicZoom: this.basicZoom,
3419
- cameraZoom: this.context.camera.zoom
3420
- });
3421
- this.prevCameraZoom = zoom;
3422
- }
3423
- });
3424
- __publicField(this, "onKeydown", (e) => {
3425
- if (this.polarKeys.includes(e.code)) {
3426
- this.context.control.maxPolarAngle = this.config.control.maxPolar;
3427
- this.context.control.minPolarAngle = 0;
3428
- }
3429
- if (this.azimuthalKeys.includes(e.code)) {
3430
- this.context.control.maxAzimuthAngle = Infinity;
3431
- this.context.control.minAzimuthAngle = Infinity;
3432
- }
3433
- });
3434
- __publicField(this, "onKeyUp", (e) => {
3435
- if (this.polarKeys.includes(e.code)) {
3436
- const polar = this.context.control.getPolarAngle();
3437
- this.context.control.maxPolarAngle = polar;
3438
- this.context.control.minPolarAngle = polar;
3439
- }
3440
- if (this.azimuthalKeys.includes(e.code)) {
3441
- const azimuthal = this.context.control.getAzimuthalAngle();
3442
- this.context.control.maxAzimuthAngle = azimuthal;
3443
- this.context.control.minAzimuthAngle = azimuthal;
3444
- }
3445
- });
3446
- __publicField(this, "resize", () => {
3447
- this.context.cameraBound.setEnable(false);
3448
- this.context.onWindowResize();
3449
- const azimuthal = this.context.control.getAzimuthalAngle();
3450
- const zoom = this.context.camera.zoom;
3451
- this.context.control.minZoom = 0;
3452
- this.context.control.maxZoom = Infinity;
3453
- this.context.camera.zoom = 1;
3454
- this.context.setAzimuthalAngle(0, 0);
3455
- const basicZoom = this.context.getFitCameraToGroundZoom(void 0, 0);
3456
- this.basicZoom = basicZoom || 0;
3457
- this.context.control.minZoom = this.basicZoom;
3458
- this.context.control.maxZoom = this.basicZoom * 25;
3459
- this.context.camera.zoom = zoom;
3460
- this.context.control.addEventListener("change", this.onControlChange);
3461
- this.context.setAzimuthalAngle(azimuthal, 0);
3462
- this.context.cameraBound.setEnable(true);
3463
- });
3464
3518
  this.config = getConfig(config);
3465
3519
  this.context = new Context(container, this.config);
3466
3520
  this.registryEvent();
3467
3521
  this.context.render();
3468
3522
  }
3469
- loadGraphics(_0) {
3470
- return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts, resource_type_list }) {
3471
- const { apiDomain, apiPath: { floorGraphic }, apiInfo } = this.config;
3472
- const url = `${apiDomain}${floorGraphic}?brand=${brand}&project=${project}&phase=${phase}&building=${building}&floor=${floor}&ts=${ts}&resource_type_list=${resource_type_list}`;
3473
- const data = yield fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
3474
- (res || []).map((item) => item.info = JSON.parse(item.info));
3475
- return res || [];
3476
- });
3477
- return data;
3523
+ config;
3524
+ context;
3525
+ polarKeys = [];
3526
+ azimuthalKeys = [];
3527
+ svgLine;
3528
+ svgPolygon;
3529
+ basicZoom = 1;
3530
+ prevCameraZoom = 1;
3531
+ type = "2d";
3532
+ floorDataMap = /* @__PURE__ */ new Map();
3533
+ buildingGroundMap = /* @__PURE__ */ new Map();
3534
+ currentBuildGround = null;
3535
+ observe = null;
3536
+ event = new Events();
3537
+ timer = new Timer();
3538
+ plugins = [];
3539
+ async loadGraphics({
3540
+ brand,
3541
+ project,
3542
+ phase,
3543
+ building,
3544
+ floor,
3545
+ ts,
3546
+ resource_type_list
3547
+ }) {
3548
+ const {
3549
+ apiDomain,
3550
+ apiPath: { floorGraphic },
3551
+ apiInfo
3552
+ } = this.config;
3553
+ const url = `${apiDomain}${floorGraphic}?brand=${brand}&project=${project}&phase=${phase}&building=${building}&floor=${floor}&ts=${ts}&resource_type_list=${resource_type_list}`;
3554
+ const data = await fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
3555
+ (res || []).map((item) => item.info = JSON.parse(item.info));
3556
+ return res || [];
3478
3557
  });
3558
+ return data;
3479
3559
  }
3480
- getBuildingKey({ brand, project, phase, building }) {
3560
+ getBuildingKey({
3561
+ brand,
3562
+ project,
3563
+ phase,
3564
+ building
3565
+ }) {
3481
3566
  const key = `${brand}-${project}-${phase}-${building}`;
3482
3567
  return key;
3483
3568
  }
3484
- loadBuildingGround(_0) {
3485
- return __async(this, arguments, function* ({ brand, project, phase, building }) {
3486
- const key = this.getBuildingKey({ brand, project, phase, building });
3487
- if (this.buildingGroundMap.get(key)) {
3488
- return this.buildingGroundMap.get(key) || null;
3569
+ async loadBuildingGround({
3570
+ brand,
3571
+ project,
3572
+ phase,
3573
+ building
3574
+ }) {
3575
+ const key = this.getBuildingKey({ brand, project, phase, building });
3576
+ if (this.buildingGroundMap.get(key)) {
3577
+ return this.buildingGroundMap.get(key) || null;
3578
+ }
3579
+ const {
3580
+ apiDomain,
3581
+ apiPath: { floorRange },
3582
+ apiInfo
3583
+ } = this.config;
3584
+ const url = `${apiDomain}${floorRange}?brand=${brand}&project=${project}&phase=${phase}&building=${building}`;
3585
+ const data = await fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
3586
+ const data2 = (res || [])[0];
3587
+ if (data2) {
3588
+ data2.info = JSON.parse(data2.info);
3489
3589
  }
3490
- const { apiDomain, apiPath: { floorRange }, apiInfo } = this.config;
3491
- const url = `${apiDomain}${floorRange}?brand=${brand}&project=${project}&phase=${phase}&building=${building}`;
3492
- const data = yield fetch(url, apiInfo).then((res) => res.json()).then((res) => res.data).then((res) => {
3493
- const data2 = (res || [])[0];
3494
- if (data2) {
3495
- data2.info = JSON.parse(data2.info);
3496
- }
3497
- return data2;
3498
- });
3499
- this.buildingGroundMap.set(key, data);
3500
- return data;
3590
+ return data2;
3501
3591
  });
3502
- }
3503
- getFloorKey({ brand, project, phase, building, floor, ts, resource_type_list }) {
3592
+ this.buildingGroundMap.set(key, data);
3593
+ return data;
3594
+ }
3595
+ getFloorKey({
3596
+ brand,
3597
+ project,
3598
+ phase,
3599
+ building,
3600
+ floor,
3601
+ ts,
3602
+ resource_type_list
3603
+ }) {
3504
3604
  const floorKey = `${brand}-${project}-${phase}-${building}-${floor}-${ts}-${resource_type_list}`;
3505
3605
  return floorKey;
3506
3606
  }
3507
- load(_0) {
3508
- return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts, resource_type_list }) {
3509
- const floorKey = this.getFloorKey({ brand, project, phase, building, floor, ts, resource_type_list });
3510
- if (this.floorDataMap.get(floorKey)) {
3511
- return;
3512
- }
3513
- const [data, buildGround] = yield Promise.all([
3514
- this.loadGraphics({ brand, project, phase, building, floor, ts, resource_type_list }),
3515
- this.loadBuildingGround({ brand, project, phase, building })
3516
- ]);
3517
- if (buildGround) {
3518
- const center2 = getCenter(buildGround.info.geometry.cds[0]);
3519
- data.forEach((item) => {
3520
- item.info.geometry.coords = JSON.parse(JSON.stringify(item.info.geometry.cds));
3521
- if (item.info.geometry.type === "polygon") {
3522
- item.info.geometry.coords.map((cds) => {
3523
- if (Array.isArray(cds)) {
3524
- cds.forEach((coord) => {
3525
- coord[0] -= center2[0];
3526
- coord[1] -= center2[1];
3527
- });
3528
- }
3607
+ async load({
3608
+ brand,
3609
+ project,
3610
+ phase,
3611
+ building,
3612
+ floor,
3613
+ ts,
3614
+ resource_type_list
3615
+ }) {
3616
+ const floorKey = this.getFloorKey({
3617
+ brand,
3618
+ project,
3619
+ phase,
3620
+ building,
3621
+ floor,
3622
+ ts,
3623
+ resource_type_list
3624
+ });
3625
+ if (this.floorDataMap.get(floorKey)) {
3626
+ return;
3627
+ }
3628
+ const [data, buildGround] = await Promise.all([
3629
+ this.loadGraphics({
3630
+ brand,
3631
+ project,
3632
+ phase,
3633
+ building,
3634
+ floor,
3635
+ ts,
3636
+ resource_type_list
3637
+ }),
3638
+ this.loadBuildingGround({ brand, project, phase, building })
3639
+ ]);
3640
+ const center2 = buildGround ? getCenter(
3641
+ buildGround.info.geometry.cds[0]
3642
+ ) : [0, 0];
3643
+ data.forEach((item) => {
3644
+ item.info.geometry.coords = JSON.parse(
3645
+ JSON.stringify(item.info.geometry.cds)
3646
+ );
3647
+ if (item.info.geometry.type === "polygon") {
3648
+ item.info.geometry.coords.map((cds) => {
3649
+ if (Array.isArray(cds)) {
3650
+ cds.forEach((coord) => {
3651
+ coord[0] -= center2[0];
3652
+ coord[1] -= center2[1];
3529
3653
  });
3530
- } else {
3531
- const [x, y] = item.info.geometry.cds;
3532
- item.info.geometry.coords = [x - center2[0], y - center2[1]];
3533
3654
  }
3534
- item.info.transformToBuildingGround = true;
3535
3655
  });
3656
+ } else {
3657
+ const [x, y] = item.info.geometry.cds;
3658
+ item.info.geometry.coords = [x - center2[0], y - center2[1]];
3536
3659
  }
3537
- const { ground, markGraphic, graphic } = this.config;
3538
- for (let i = 0; i < data.length; i++) {
3539
- const item = data[i];
3540
- item.info.deltaHeight = 1e-5 * (i + 1);
3541
- if (item.info.group === "ground") {
3542
- item.info.fillColor = ground.color;
3543
- item.info.fillOpacity = ground.opacity;
3544
- item.info.height = ground.height;
3545
- item.info.stroke = ground.stroke;
3546
- item.info.strokeColor = ground.strokeColor;
3547
- item.info.strokeOpacity = ground.strokeOpacity;
3548
- } else if (item.info.userData.mark) {
3660
+ item.info.transformToBuildingGround = !!buildGround;
3661
+ });
3662
+ const { ground, markGraphic, graphic } = this.config;
3663
+ for (let i = 0; i < data.length; i++) {
3664
+ const item = data[i];
3665
+ item.info.deltaHeight = 1e-5 * (i + 1);
3666
+ if (item.info.group === "ground") {
3667
+ item.info.fillColor = ground.color;
3668
+ item.info.fillOpacity = ground.opacity;
3669
+ item.info.height = ground.height;
3670
+ item.info.stroke = ground.stroke;
3671
+ item.info.strokeColor = ground.strokeColor;
3672
+ item.info.strokeOpacity = ground.strokeOpacity;
3673
+ } else if (item.info.userData.mark) {
3674
+ item.info.height = markGraphic.height;
3675
+ item.info.fillColor = markGraphic.color;
3676
+ item.info.fillOpacity = markGraphic.opacity;
3677
+ item.info.stroke = markGraphic.stroke;
3678
+ item.info.strokeColor = markGraphic.strokeColor;
3679
+ item.info.strokeOpacity = markGraphic.strokeOpacity;
3680
+ } else {
3681
+ item.info.fillOpacity = graphic.fillOpacity;
3682
+ if (this.config.initTransToMark) {
3549
3683
  item.info.height = markGraphic.height;
3550
3684
  item.info.fillColor = markGraphic.color;
3551
- item.info.fillOpacity = markGraphic.opacity;
3552
3685
  item.info.stroke = markGraphic.stroke;
3553
3686
  item.info.strokeColor = markGraphic.strokeColor;
3554
3687
  item.info.strokeOpacity = markGraphic.strokeOpacity;
3555
- } else {
3556
- item.info.fillOpacity = graphic.fillOpacity;
3557
- if (this.config.initTransToMark) {
3558
- item.info.height = markGraphic.height;
3559
- item.info.fillColor = markGraphic.color;
3560
- item.info.stroke = markGraphic.stroke;
3561
- item.info.strokeColor = markGraphic.strokeColor;
3562
- item.info.strokeOpacity = markGraphic.strokeOpacity;
3563
- }
3564
3688
  }
3565
3689
  }
3566
- if (!this.config.useFloorCache) {
3567
- this.floorDataMap.clear();
3568
- }
3569
- this.floorDataMap.set(floorKey, data);
3570
- return data;
3571
- });
3690
+ }
3691
+ if (!this.config.useFloorCache) {
3692
+ this.floorDataMap.clear();
3693
+ }
3694
+ this.floorDataMap.set(floorKey, data);
3695
+ return data;
3696
+ }
3697
+ loadEquipment() {
3698
+ const equipment = new Equipment(this);
3699
+ this.plugins.push(equipment);
3700
+ }
3701
+ use(plugin) {
3702
+ plugin.bmap = this;
3703
+ this.plugins.push(plugin);
3704
+ }
3705
+ loadNavigation() {
3706
+ const navigation = new Navigation(this);
3707
+ this.plugins.push(navigation);
3572
3708
  }
3573
3709
  createFloor(data) {
3574
3710
  const curFloor = new Floor(this.context);
@@ -3590,15 +3726,37 @@ var BMap = class extends EventDispatcher7 {
3590
3726
  curFloor.userData.legacyToGraphicMap = legacyToGraphicMap;
3591
3727
  return { curFloor, graphics };
3592
3728
  }
3593
- switchFloor({ brand, project, phase, building, floor, ts, resource_type_list }) {
3594
- const floorKey = this.getFloorKey({ brand, project, phase, building, floor, ts, resource_type_list });
3729
+ switchFloor({
3730
+ brand,
3731
+ project,
3732
+ phase,
3733
+ building,
3734
+ floor,
3735
+ ts,
3736
+ resource_type_list
3737
+ }) {
3738
+ const floorKey = this.getFloorKey({
3739
+ brand,
3740
+ project,
3741
+ phase,
3742
+ building,
3743
+ floor,
3744
+ ts,
3745
+ resource_type_list
3746
+ });
3595
3747
  const curFloorData = this.floorDataMap.get(floorKey);
3596
3748
  this.context.control.removeEventListener("change", this.onControlChange);
3597
3749
  if (curFloorData) {
3598
- const buildingKey = this.getBuildingKey({ brand, project, phase, building });
3750
+ const buildingKey = this.getBuildingKey({
3751
+ brand,
3752
+ project,
3753
+ phase,
3754
+ building
3755
+ });
3599
3756
  this.currentBuildGround = this.buildingGroundMap.get(buildingKey) || null;
3600
3757
  const createdFloor = this.createFloor(curFloorData);
3601
3758
  if (createdFloor) {
3759
+ this.event.emit("switch_floor_before" /* SWITCH_FLOOR_BEFORE */, createdFloor);
3602
3760
  this.context.cameraBound.setEnable(false);
3603
3761
  this.context.switchFloor(createdFloor.curFloor);
3604
3762
  this.context.control.minZoom = 0;
@@ -3615,43 +3773,62 @@ var BMap = class extends EventDispatcher7 {
3615
3773
  }
3616
3774
  this.onControlChange();
3617
3775
  this.context.cameraBound.setEnable(true);
3776
+ this.event.emit("switch_floor_after" /* SWITCH_FLOOR_AFTER */, createdFloor);
3618
3777
  } else {
3619
3778
  console.warn("[switchFloor error] [" + floor + "] \u697C\u5C42\u6CA1\u6709\u6570\u636E");
3620
3779
  }
3621
3780
  } else {
3622
- console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42");
3781
+ console.warn(
3782
+ "[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42"
3783
+ );
3623
3784
  }
3624
3785
  }
3786
+ onControlChange = () => {
3787
+ const {
3788
+ camera: { zoom }
3789
+ } = this.context;
3790
+ if (zoom !== this.prevCameraZoom) {
3791
+ this.dispatchEvent({
3792
+ type: "zoom-change",
3793
+ basicZoom: this.basicZoom,
3794
+ cameraZoom: this.context.camera.zoom
3795
+ });
3796
+ this.prevCameraZoom = zoom;
3797
+ }
3798
+ };
3625
3799
  // 扶梯
3626
3800
  addModel(graphic, options) {
3627
- var _a;
3628
3801
  if (graphic.options.geometry.type === "polygon") {
3629
- const model = (_a = this.context.currentFloor) == null ? void 0 : _a.addModel(__spreadProps(__spreadValues({}, options), {
3802
+ const model = this.context.currentFloor?.addModel({
3803
+ ...options,
3630
3804
  position: graphic.getPosition().setZ(0.1),
3631
3805
  id: graphic.options.id
3632
- }));
3806
+ });
3633
3807
  if (model) {
3634
- const { facilityAngle = 0, facilityXScale = 1, facilityYScale = 1 } = graphic.options.userData;
3808
+ const {
3809
+ facilityAngle = 0,
3810
+ facilityXScale = 1,
3811
+ facilityYScale = 1
3812
+ } = graphic.options.userData;
3635
3813
  model.rotateZ((180 - facilityAngle) / 180 * Math.PI);
3636
3814
  model.scale.set(facilityXScale, facilityYScale, 1);
3637
3815
  }
3638
3816
  }
3639
3817
  }
3640
3818
  addHeatmap(data) {
3641
- var _a;
3642
- return (_a = this.context.currentFloor) == null ? void 0 : _a.addHeatmap(data);
3819
+ return this.context.currentFloor?.addHeatmap(data);
3643
3820
  }
3644
3821
  getLegacyToGraphicMap() {
3645
- var _a;
3646
- return ((_a = this.context.currentFloor) == null ? void 0 : _a.userData.legacyToGraphicMap) || /* @__PURE__ */ new Map();
3822
+ return this.context.currentFloor?.userData.legacyToGraphicMap || /* @__PURE__ */ new Map();
3647
3823
  }
3648
3824
  /**
3649
3825
  * 获取当前楼层全部的graphic
3650
- * @returns
3826
+ * @returns
3651
3827
  */
3652
3828
  getFloorAllGraphics() {
3653
- var _a;
3654
- return ((_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.children.filter((item) => item instanceof Graphic)) || [];
3829
+ return this.context.currentFloor?.graphicLayer.children.filter(
3830
+ (item) => item instanceof Graphic
3831
+ ) || [];
3655
3832
  }
3656
3833
  createGraphicPoi(graphic, options) {
3657
3834
  if (this.context.currentFloor) {
@@ -3659,16 +3836,16 @@ var BMap = class extends EventDispatcher7 {
3659
3836
  options.id = graphic.options.id;
3660
3837
  }
3661
3838
  const position = graphic.getCenter();
3662
- const poi = this.context.currentFloor.addPoi(__spreadProps(__spreadValues({}, options), {
3663
- position: __spreadProps(__spreadValues({}, position), { z: position.z + graphic.options.height / 2 })
3664
- }));
3839
+ const poi = this.context.currentFloor.addPoi({
3840
+ ...options,
3841
+ position: { ...position, z: position.z + graphic.options.height / 2 }
3842
+ });
3665
3843
  return poi;
3666
3844
  }
3667
3845
  return null;
3668
3846
  }
3669
3847
  removeHeatMap() {
3670
- var _a;
3671
- (_a = this.context.currentFloor) == null ? void 0 : _a.removeHeatMap();
3848
+ this.context.currentFloor?.removeHeatMap();
3672
3849
  }
3673
3850
  /**
3674
3851
  * 移动相机位置让选中的元素居中显示
@@ -3684,14 +3861,26 @@ var BMap = class extends EventDispatcher7 {
3684
3861
  * @param ele { Graphic | Poi }
3685
3862
  * @param duration
3686
3863
  */
3687
- translateElementToCenterX(ele, duration = 500) {
3688
- return __async(this, null, function* () {
3689
- const { y, z } = this.context.control.target;
3864
+ async translateElementToCenterX(ele, duration = 500) {
3865
+ return timeoutPromise(new Promise((resolve) => {
3866
+ const target = this.context.control.target.clone();
3690
3867
  const position = ele.getPosition();
3691
- position.setY(y);
3692
- position.setZ(z);
3693
- yield this.context.setCameraPosition(position, duration);
3694
- });
3868
+ this.timer.requestAnimationFrame(() => {
3869
+ const {
3870
+ clientSize: { width, height },
3871
+ camera
3872
+ } = this.context;
3873
+ console.log("width", width, height);
3874
+ const device = vector3ToDevice(position, camera, width, height);
3875
+ const offsetX = device.x - width / 2;
3876
+ const v3 = new Vector314();
3877
+ v3.setFromMatrixColumn(this.context.camera.matrix, 0);
3878
+ v3.normalize();
3879
+ v3.multiplyScalar(offsetX / this.context.camera.zoom);
3880
+ target.add(v3);
3881
+ this.context.setCameraPosition(target, duration).then(resolve);
3882
+ });
3883
+ }), duration + 500);
3695
3884
  }
3696
3885
  /**
3697
3886
  * 获取物体的屏幕坐标
@@ -3719,13 +3908,18 @@ var BMap = class extends EventDispatcher7 {
3719
3908
  return this.context.setPolarAngle(1.1 /* D3 */, duration);
3720
3909
  }
3721
3910
  }
3722
- resetView(duration = 300) {
3723
- return __async(this, null, function* () {
3724
- const time = duration / 3;
3725
- yield this.context.setAzimuthalAngle(this.config.control.defaultAzimuthal, time);
3726
- yield this.changeMapType(this.type, time);
3727
- yield this.context.fitCameraToGround(this.config.defaultPadding, time, false);
3728
- });
3911
+ async resetView(duration = 300) {
3912
+ const time = duration / 3;
3913
+ await this.context.setAzimuthalAngle(
3914
+ this.config.control.defaultAzimuthal,
3915
+ time
3916
+ );
3917
+ await this.changeMapType(this.type, time);
3918
+ await this.context.fitCameraToGround(
3919
+ this.config.defaultPadding,
3920
+ time,
3921
+ false
3922
+ );
3729
3923
  }
3730
3924
  /**
3731
3925
  * 缩小地图
@@ -3755,6 +3949,28 @@ var BMap = class extends EventDispatcher7 {
3755
3949
  duration
3756
3950
  );
3757
3951
  }
3952
+ onKeydown = (e) => {
3953
+ if (this.polarKeys.includes(e.code)) {
3954
+ this.context.control.maxPolarAngle = this.config.control.maxPolar;
3955
+ this.context.control.minPolarAngle = 0;
3956
+ }
3957
+ if (this.azimuthalKeys.includes(e.code)) {
3958
+ this.context.control.maxAzimuthAngle = Infinity;
3959
+ this.context.control.minAzimuthAngle = Infinity;
3960
+ }
3961
+ };
3962
+ onKeyUp = (e) => {
3963
+ if (this.polarKeys.includes(e.code)) {
3964
+ const polar = this.context.control.getPolarAngle();
3965
+ this.context.control.maxPolarAngle = polar;
3966
+ this.context.control.minPolarAngle = polar;
3967
+ }
3968
+ if (this.azimuthalKeys.includes(e.code)) {
3969
+ const azimuthal = this.context.control.getAzimuthalAngle();
3970
+ this.context.control.maxAzimuthAngle = azimuthal;
3971
+ this.context.control.minAzimuthAngle = azimuthal;
3972
+ }
3973
+ };
3758
3974
  registryEvent() {
3759
3975
  window.addEventListener("keydown", this.onKeydown);
3760
3976
  window.addEventListener("keyup", this.onKeyUp);
@@ -3765,10 +3981,9 @@ var BMap = class extends EventDispatcher7 {
3765
3981
  }
3766
3982
  }
3767
3983
  unRegistryEvent() {
3768
- var _a;
3769
3984
  window.removeEventListener("keydown", this.onKeydown);
3770
3985
  window.removeEventListener("keyup", this.onKeyUp);
3771
- (_a = this.observe) == null ? void 0 : _a.disconnect();
3986
+ this.observe?.disconnect();
3772
3987
  this.observe = null;
3773
3988
  }
3774
3989
  /**
@@ -3789,23 +4004,21 @@ var BMap = class extends EventDispatcher7 {
3789
4004
  }
3790
4005
  /**
3791
4006
  * 测量距离
3792
- * @returns
4007
+ * @returns
3793
4008
  */
3794
- measureDistance() {
3795
- return __async(this, null, function* () {
3796
- this.cancelDistance();
3797
- return new Promise((resolve, reject) => {
3798
- this.changeMapType("2d", 0);
3799
- this.context.control.enableRotate = false;
3800
- this.svgLine = new SvgLine(this.context);
3801
- const dispose2 = this.svgLine.dispose.bind(this.svgLine);
3802
- this.svgLine.dispose = function() {
3803
- dispose2();
3804
- reject("cancel");
3805
- };
3806
- this.svgLine.addEventListener("distance", ({ distance }) => {
3807
- resolve(distance);
3808
- });
4009
+ async measureDistance() {
4010
+ this.cancelDistance();
4011
+ return new Promise((resolve, reject) => {
4012
+ this.changeMapType("2d", 0);
4013
+ this.context.control.enableRotate = false;
4014
+ this.svgLine = new SvgLine(this.context);
4015
+ const dispose2 = this.svgLine.dispose.bind(this.svgLine);
4016
+ this.svgLine.dispose = function() {
4017
+ dispose2();
4018
+ reject("cancel");
4019
+ };
4020
+ this.svgLine.addEventListener("distance", ({ distance }) => {
4021
+ resolve(distance);
3809
4022
  });
3810
4023
  });
3811
4024
  }
@@ -3852,20 +4065,21 @@ var BMap = class extends EventDispatcher7 {
3852
4065
  * 根据nodeId 获取graphic
3853
4066
  */
3854
4067
  getGraphicByNodeId(nodeId) {
3855
- var _a;
3856
- return ((_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.getGraphicByNodeId(nodeId)) || null;
4068
+ return this.context.currentFloor?.graphicLayer.getGraphicByNodeId(nodeId) || null;
3857
4069
  }
3858
4070
  deleteGraphic(graphic) {
3859
- var _a;
3860
- (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.removeGraphic(graphic);
4071
+ this.context.currentFloor?.graphicLayer.removeGraphic(graphic);
3861
4072
  }
3862
4073
  createGraphicByOptions(options) {
3863
- var _a;
3864
4074
  if (!options.transformToBuildingGround) {
3865
4075
  if (this.currentBuildGround) {
3866
- const center2 = getCenter(this.currentBuildGround.info.geometry.cds[0]);
4076
+ const center2 = getCenter(
4077
+ this.currentBuildGround.info.geometry.cds[0]
4078
+ );
3867
4079
  if (options.geometry.type === "polygon") {
3868
- options.geometry.coords = JSON.parse(JSON.stringify(options.geometry.cds));
4080
+ options.geometry.coords = JSON.parse(
4081
+ JSON.stringify(options.geometry.cds)
4082
+ );
3869
4083
  options.geometry.coords.map((cds) => {
3870
4084
  if (Array.isArray(cds)) {
3871
4085
  cds.forEach((coord) => {
@@ -3880,19 +4094,18 @@ var BMap = class extends EventDispatcher7 {
3880
4094
  }
3881
4095
  }
3882
4096
  }
3883
- return (_a = this.context.currentFloor) == null ? void 0 : _a.graphicLayer.createGraphic(options);
4097
+ return this.context.currentFloor?.graphicLayer.createGraphic(options);
3884
4098
  }
3885
4099
  removePoiById(id) {
3886
- var _a;
3887
- return (_a = this.context.currentFloor) == null ? void 0 : _a.poiLayer.removePoiById(id);
4100
+ return this.context.currentFloor?.poiLayer.removePoiById(id);
3888
4101
  }
3889
4102
  getPoiById(id) {
3890
- var _a;
3891
- return (_a = this.context.currentFloor) == null ? void 0 : _a.poiLayer.getPoiById(id);
4103
+ return this.context.currentFloor?.poiLayer.getPoiById(id);
3892
4104
  }
3893
4105
  getPois() {
3894
- var _a;
3895
- return (((_a = this.context.currentFloor) == null ? void 0 : _a.poiLayer.pois) || []).filter((item) => !item.options.built_in);
4106
+ return (this.context.currentFloor?.poiLayer.pois || []).filter(
4107
+ (item) => !item.options.built_in
4108
+ );
3896
4109
  }
3897
4110
  clearPoi() {
3898
4111
  if (this.context.currentFloor) {
@@ -3902,7 +4115,27 @@ var BMap = class extends EventDispatcher7 {
3902
4115
  removeSelectGraphic(graphic) {
3903
4116
  this.context.selection.remove(graphic);
3904
4117
  }
4118
+ resize = () => {
4119
+ this.context.cameraBound.setEnable(false);
4120
+ this.context.onWindowResize();
4121
+ const azimuthal = this.context.control.getAzimuthalAngle();
4122
+ const zoom = this.context.camera.zoom;
4123
+ this.context.control.minZoom = 0;
4124
+ this.context.control.maxZoom = Infinity;
4125
+ this.context.camera.zoom = 1;
4126
+ this.context.setAzimuthalAngle(0, 0);
4127
+ const basicZoom = this.context.getFitCameraToGroundZoom(void 0, 0);
4128
+ this.basicZoom = basicZoom || 0;
4129
+ this.context.control.minZoom = this.basicZoom;
4130
+ this.context.control.maxZoom = this.basicZoom * 25;
4131
+ this.context.camera.zoom = zoom;
4132
+ this.context.control.addEventListener("change", this.onControlChange);
4133
+ this.context.setAzimuthalAngle(azimuthal, 0);
4134
+ this.context.cameraBound.setEnable(true);
4135
+ };
3905
4136
  dispose() {
4137
+ this.timer.dispose();
4138
+ this.plugins.forEach((plugin) => plugin.dispose());
3906
4139
  this.context.dispose();
3907
4140
  this.floorDataMap.clear();
3908
4141
  this.buildingGroundMap.clear();
@@ -3916,6 +4149,9 @@ export {
3916
4149
  BMap,
3917
4150
  BaseSvg,
3918
4151
  Context,
4152
+ Equipment,
4153
+ EventName,
4154
+ Events,
3919
4155
  Floor,
3920
4156
  Graphic,
3921
4157
  GraphicLayer,
@@ -3924,6 +4160,7 @@ export {
3924
4160
  Layer,
3925
4161
  MapTypePolar,
3926
4162
  Model,
4163
+ Navigation,
3927
4164
  Overlay,
3928
4165
  Poi,
3929
4166
  PoiLayer,