@aibee/crc-bmap 0.0.128 → 0.0.130

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
@@ -454,7 +454,7 @@ var require_Graph = __commonJS({
454
454
  });
455
455
 
456
456
  // src/bmap.ts
457
- import { EventDispatcher as EventDispatcher7, Vector3 as Vector319 } from "three";
457
+ import { EventDispatcher as EventDispatcher7, Vector3 as Vector320 } from "three";
458
458
 
459
459
  // src/utils/timer.ts
460
460
  var Timer = class {
@@ -624,8 +624,10 @@ function hasChinese(str) {
624
624
  }
625
625
 
626
626
  // src/utils/texture.ts
627
- import { DataTexture, RGBAFormat, LinearFilter } from "three";
627
+ import { DataTexture, RGBAFormat, LinearFilter, TextureLoader } from "three";
628
+ var urlTextureMap = /* @__PURE__ */ new Map();
628
629
  var textTextureMap = /* @__PURE__ */ new Map();
630
+ var textureLoader = new TextureLoader();
629
631
  function initCanvas() {
630
632
  const canvas2 = document.createElement("canvas");
631
633
  canvas2.width = 1024;
@@ -675,12 +677,38 @@ function getTextureByText(text) {
675
677
  return texture;
676
678
  }
677
679
  function clearTextTexture() {
680
+ textTextureMap.forEach((v, _) => {
681
+ v.dispose();
682
+ });
683
+ urlTextureMap.forEach((v) => {
684
+ if (v instanceof Promise) {
685
+ v.then((r) => r.dispose());
686
+ } else {
687
+ v.dispose();
688
+ }
689
+ });
678
690
  textTextureMap.clear();
691
+ urlTextureMap.clear();
679
692
  }
680
693
  function clearCanvas() {
681
694
  ctx = null;
682
695
  canvas = null;
683
696
  }
697
+ async function getTextureByUrl(url) {
698
+ if (urlTextureMap.has(url)) {
699
+ return urlTextureMap.get(url);
700
+ }
701
+ const texturePromise = textureLoader.loadAsync(url);
702
+ texturePromise.then((texture) => {
703
+ texture.format = RGBAFormat;
704
+ texture.magFilter = LinearFilter;
705
+ texture.minFilter = LinearFilter;
706
+ texture.colorSpace = "srgb";
707
+ urlTextureMap.set(url, texture);
708
+ });
709
+ urlTextureMap.set(url, texturePromise);
710
+ return texturePromise;
711
+ }
684
712
 
685
713
  // src/utils/coordinate.ts
686
714
  import { Vector3, Vector2 as Vector22 } from "three";
@@ -1152,6 +1180,9 @@ function moveOnRoute(startPoint, endPoint, distance) {
1152
1180
  const [startX, startY] = startPoint;
1153
1181
  const [endX, endY] = endPoint;
1154
1182
  const routeLength = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
1183
+ if (routeLength === 0 || routeLength < distance) {
1184
+ return [...endPoint];
1185
+ }
1155
1186
  const ratio = distance / routeLength;
1156
1187
  const newX = startX + (endX - startX) * ratio;
1157
1188
  const newY = startY + (endY - startY) * ratio;
@@ -2012,11 +2043,11 @@ function toWebWorker(obj) {
2012
2043
  // src/context.ts
2013
2044
  import {
2014
2045
  EventDispatcher as EventDispatcher6,
2015
- Box2,
2016
- Vector3 as Vector318,
2017
- Vector2 as Vector26,
2018
- Raycaster as Raycaster3,
2019
- Box3 as Box39,
2046
+ Box2 as Box23,
2047
+ Vector3 as Vector319,
2048
+ Vector2 as Vector29,
2049
+ Raycaster as Raycaster5,
2050
+ Box3 as Box310,
2020
2051
  Color as Color6,
2021
2052
  AmbientLight as AmbientLight2
2022
2053
  } from "three";
@@ -3007,14 +3038,14 @@ var Poi = class extends EventDispatcher2 {
3007
3038
  };
3008
3039
 
3009
3040
  // src/elements/floor.ts
3010
- import { Box3 as Box35, Object3D as Object3D8, Vector3 as Vector38 } from "three";
3041
+ import { Box3 as Box35, Object3D as Object3D8, Vector3 as Vector39 } from "three";
3011
3042
 
3012
3043
  // src/elements/heatmap.ts
3013
3044
  import {
3014
3045
  MeshBasicMaterial as MeshBasicMaterial2,
3015
3046
  Object3D as Object3D5,
3016
3047
  PlaneGeometry as PlaneGeometry2,
3017
- Texture,
3048
+ Texture as Texture2,
3018
3049
  DoubleSide as DoubleSide2,
3019
3050
  Mesh as Mesh3,
3020
3051
  Matrix3,
@@ -3055,7 +3086,7 @@ var HeatmapElement = class extends Object3D5 {
3055
3086
  this.remove(this.plane);
3056
3087
  }
3057
3088
  const geometry = new PlaneGeometry2(width, height);
3058
- const texture = new Texture(this.div.firstChild);
3089
+ const texture = new Texture2(this.div.firstChild);
3059
3090
  texture.needsUpdate = true;
3060
3091
  const material = new MeshBasicMaterial2({
3061
3092
  transparent: true,
@@ -3338,6 +3369,160 @@ var PoiLayer = class extends Layer {
3338
3369
  }
3339
3370
  };
3340
3371
 
3372
+ // src/layer/poi-layer2.ts
3373
+ import { debounce as debounce3 } from "lodash";
3374
+ import { Vector2 as Vector25, Vector3 as Vector38 } from "three";
3375
+ var PoiLayer2 = class extends Layer {
3376
+ pois = [];
3377
+ debounceCollisionDetection;
3378
+ timer = new Timer();
3379
+ constructor(context) {
3380
+ super(context);
3381
+ this.registryEvent();
3382
+ this.debounceCollisionDetection = debounce3(this.collisionDetection, 10);
3383
+ }
3384
+ clear() {
3385
+ this.pois.forEach((item) => {
3386
+ item.dispose();
3387
+ });
3388
+ this.pois = [];
3389
+ return this;
3390
+ }
3391
+ createPoi(options) {
3392
+ const poi = new Poi2(this.context, options);
3393
+ this.pushPoi(poi);
3394
+ poi.addEventListener(
3395
+ "change-level",
3396
+ () => this.changePoiLevelOrCollisionEnable(poi)
3397
+ );
3398
+ poi.addEventListener(
3399
+ "change-collision_enable",
3400
+ () => this.changePoiLevelOrCollisionEnable(poi)
3401
+ );
3402
+ Promise.resolve().then(() => {
3403
+ this.debounceCollisionDetection();
3404
+ });
3405
+ return poi;
3406
+ }
3407
+ changePoiLevelOrCollisionEnable(poi) {
3408
+ const index = this.pois.findIndex((item) => item === poi);
3409
+ if (index === -1) {
3410
+ return;
3411
+ }
3412
+ this.pois.splice(index, 1);
3413
+ this.pushPoi(poi);
3414
+ }
3415
+ removePoi(poi) {
3416
+ const index = this.pois.findIndex((item) => item === poi);
3417
+ if (index === -1) {
3418
+ return;
3419
+ }
3420
+ this.remove(poi);
3421
+ this.pois.splice(index, 1);
3422
+ poi.dispose();
3423
+ }
3424
+ removePoiById(id) {
3425
+ const poi = this.pois.find((item) => item.options.id === id);
3426
+ if (poi) {
3427
+ this.removePoi(poi);
3428
+ }
3429
+ }
3430
+ getPoiById(id) {
3431
+ const poi = this.pois.find((item) => item.options.id === id);
3432
+ return poi || null;
3433
+ }
3434
+ /**
3435
+ * 保存poi按照level排序
3436
+ * @param poi
3437
+ */
3438
+ pushPoi(poi) {
3439
+ this.add(poi);
3440
+ if (!poi.options.collision_enable) {
3441
+ this.pois.unshift(poi);
3442
+ return;
3443
+ }
3444
+ if (poi.options.level === 0) {
3445
+ this.pois.push(poi);
3446
+ return;
3447
+ }
3448
+ for (let i = 0; i < this.pois.length; i++) {
3449
+ const item = this.pois[i];
3450
+ if (!item.options.collision_enable) {
3451
+ continue;
3452
+ }
3453
+ if (item.options.level <= poi.options.level) {
3454
+ this.pois.splice(i, 0, poi);
3455
+ return;
3456
+ }
3457
+ }
3458
+ this.pois.push(poi);
3459
+ }
3460
+ getPoiByDeviceXy(x, y) {
3461
+ const v2 = new Vector25(x, y);
3462
+ const pois = this.pois.filter((item) => {
3463
+ return item instanceof Poi2 && item.box.containsPoint(v2);
3464
+ });
3465
+ return pois;
3466
+ }
3467
+ onUpdate = () => {
3468
+ this.timer.requestAnimationFrame(() => {
3469
+ this.collisionDetection();
3470
+ });
3471
+ };
3472
+ /**
3473
+ * 碰撞检测
3474
+ */
3475
+ collisionDetection() {
3476
+ const range = [];
3477
+ const { camera } = this.context;
3478
+ camera.updateMatrixWorld();
3479
+ const isValid = (n) => n <= 1 && n >= -1;
3480
+ const m4 = camera.projectionMatrix.clone();
3481
+ m4.multiply(camera.matrixWorldInverse);
3482
+ const pois = this.pois.filter((item) => {
3483
+ if (item.visible) {
3484
+ const vector = new Vector38().setFromMatrixPosition(item.matrixWorld);
3485
+ vector.applyMatrix4(m4);
3486
+ item.screenPosition = vector;
3487
+ return isValid(vector.x) && isValid(vector.y) && isValid(vector.z);
3488
+ }
3489
+ return false;
3490
+ });
3491
+ pois.forEach((item, index) => {
3492
+ const box = item.getBox(
3493
+ item.screenPosition
3494
+ );
3495
+ if (index === 0 || !item.options.collision_enable) {
3496
+ range.push(box);
3497
+ item.parentSetVisible(true);
3498
+ return;
3499
+ }
3500
+ const valid = range.some((rangeBox) => {
3501
+ return rangeBox.intersectsBox(box);
3502
+ });
3503
+ item.parentSetVisible(!valid);
3504
+ if (!valid) {
3505
+ range.push(box);
3506
+ }
3507
+ });
3508
+ }
3509
+ registryEvent() {
3510
+ this.context.addEventListener("update", this.onUpdate);
3511
+ }
3512
+ unRegistryEvent() {
3513
+ this.context.removeEventListener("update", this.onUpdate);
3514
+ }
3515
+ dispose() {
3516
+ this.timer.dispose();
3517
+ this.pois.forEach((item) => item.dispose());
3518
+ this.pois.length = 0;
3519
+ this.debounceCollisionDetection = () => {
3520
+ };
3521
+ super.dispose();
3522
+ this.unRegistryEvent();
3523
+ }
3524
+ };
3525
+
3341
3526
  // src/elements/floor.ts
3342
3527
  var Floor = class extends Object3D8 {
3343
3528
  constructor(context) {
@@ -3346,6 +3531,7 @@ var Floor = class extends Object3D8 {
3346
3531
  this.groundLayer = new Layer(this.context);
3347
3532
  this.graphicLayer = new GraphicLayer(this.context);
3348
3533
  this.poiLayer = new PoiLayer(this.context);
3534
+ this.poiLayer2 = new PoiLayer2(this.context);
3349
3535
  this.wallLayer = new Layer(this.context);
3350
3536
  this.textureLayer = new Layer(this.context);
3351
3537
  this.glbModelLayer = new Layer(this.context);
@@ -3353,6 +3539,7 @@ var Floor = class extends Object3D8 {
3353
3539
  this.mergeGraphicLayer = new Layer(this.context);
3354
3540
  this.groundUpper.add(this.graphicLayer);
3355
3541
  this.groundUpper.add(this.poiLayer);
3542
+ this.groundUpper.add(this.poiLayer2);
3356
3543
  this.groundUpper.add(this.wallLayer);
3357
3544
  this.groundUpper.add(this.textureLayer);
3358
3545
  this.groundUpper.add(this.glbModelLayer);
@@ -3364,6 +3551,7 @@ var Floor = class extends Object3D8 {
3364
3551
  }
3365
3552
  graphicLayer;
3366
3553
  poiLayer;
3554
+ poiLayer2;
3367
3555
  wallLayer;
3368
3556
  textureLayer;
3369
3557
  glbModelLayer;
@@ -3379,9 +3567,10 @@ var Floor = class extends Object3D8 {
3379
3567
  groundMaxHeight = 0;
3380
3568
  name = "";
3381
3569
  key = "";
3570
+ box = new Box35();
3382
3571
  getPosition() {
3383
3572
  const box = new Box35().setFromObject(this);
3384
- return box.getCenter(new Vector38());
3573
+ return box.getCenter(new Vector39());
3385
3574
  }
3386
3575
  createGround(options) {
3387
3576
  const ground = new Graphic(this.context, options);
@@ -3406,7 +3595,7 @@ var Floor = class extends Object3D8 {
3406
3595
  return !!(this.grounds.size || this.graphicLayer.children.length);
3407
3596
  }
3408
3597
  getCenter() {
3409
- return new Box35().setFromObject(this).getCenter(new Vector38());
3598
+ return new Box35().setFromObject(this).getCenter(new Vector39());
3410
3599
  }
3411
3600
  addModel(options) {
3412
3601
  const model = new Model(this.context, options);
@@ -3416,8 +3605,8 @@ var Floor = class extends Object3D8 {
3416
3605
  }
3417
3606
  addShadow() {
3418
3607
  const box = new Box35().setFromObject(this.groundUpper);
3419
- const center2 = box.getCenter(new Vector38());
3420
- const size = box.getSize(new Vector38());
3608
+ const center2 = box.getCenter(new Vector39());
3609
+ const size = box.getSize(new Vector39());
3421
3610
  this.shadow.setPosition(center2);
3422
3611
  this.shadow.changeLightCamera(size);
3423
3612
  }
@@ -3450,11 +3639,15 @@ var Floor = class extends Object3D8 {
3450
3639
  setShadowVisible(visible) {
3451
3640
  this.shadow.visible = visible;
3452
3641
  }
3642
+ updateBox() {
3643
+ this.box.setFromObject(this);
3644
+ }
3453
3645
  dispose() {
3454
3646
  this.shadow.dispose();
3455
3647
  this.groundLayer.dispose();
3456
3648
  this.graphicLayer.dispose();
3457
3649
  this.poiLayer.dispose();
3650
+ this.poiLayer2.dispose();
3458
3651
  this.wallLayer.dispose();
3459
3652
  this.textureLayer.dispose();
3460
3653
  this.glbModelLayer.dispose();
@@ -3471,7 +3664,7 @@ var Floor = class extends Object3D8 {
3471
3664
  };
3472
3665
 
3473
3666
  // src/elements/base-svg.ts
3474
- import { EventDispatcher as EventDispatcher3, Vector3 as Vector39 } from "three";
3667
+ import { EventDispatcher as EventDispatcher3, Vector3 as Vector310 } from "three";
3475
3668
  var BaseSvg = class extends EventDispatcher3 {
3476
3669
  constructor(context) {
3477
3670
  super();
@@ -3509,7 +3702,7 @@ var BaseSvg = class extends EventDispatcher3 {
3509
3702
  const { clientWidth, clientHeight } = renderer.domElement;
3510
3703
  const nx = x / clientWidth * 2 - 1;
3511
3704
  const ny = 1 - y / clientHeight * 2;
3512
- const v = new Vector39(nx, ny, 0);
3705
+ const v = new Vector310(nx, ny, 0);
3513
3706
  return v.unproject(camera);
3514
3707
  }
3515
3708
  getSvgCoordinate(vector) {
@@ -3868,7 +4061,7 @@ import {
3868
4061
  Mesh as Mesh4,
3869
4062
  Object3D as Object3D9,
3870
4063
  ShaderMaterial as ShaderMaterial2,
3871
- Vector3 as Vector310
4064
+ Vector3 as Vector311
3872
4065
  } from "three";
3873
4066
  import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils";
3874
4067
  var Wall = class extends Object3D9 {
@@ -3978,8 +4171,8 @@ var Wall = class extends Object3D9 {
3978
4171
  for (let i = 0; i < curCds.length; i++) {
3979
4172
  const cur = curCds[i];
3980
4173
  const next = i + 1 === curCds.length ? curCds[0] : curCds[i + 1];
3981
- points.push(new Vector310(cur[0], cur[1], _height));
3982
- points.push(new Vector310(next[0], next[1], _height));
4174
+ points.push(new Vector311(cur[0], cur[1], _height));
4175
+ points.push(new Vector311(next[0], next[1], _height));
3983
4176
  }
3984
4177
  }
3985
4178
  return points;
@@ -4015,16 +4208,29 @@ var Wall = class extends Object3D9 {
4015
4208
  };
4016
4209
 
4017
4210
  // src/elements/ground-texture.ts
4018
- import { ExtrudeGeometry as ExtrudeGeometry3, Mesh as Mesh5, Object3D as Object3D10 } from "three";
4211
+ import {
4212
+ DoubleSide as DoubleSide3,
4213
+ Float32BufferAttribute,
4214
+ Mesh as Mesh5,
4215
+ MeshBasicMaterial as MeshBasicMaterial3,
4216
+ Object3D as Object3D10,
4217
+ ShapeGeometry
4218
+ } from "three";
4219
+ import { mergeGeometries as mergeGeometries2 } from "three/examples/jsm/utils/BufferGeometryUtils";
4019
4220
  var defaultOptions3 = {
4020
4221
  uuid: "",
4021
4222
  iconUrl: "",
4022
4223
  name: "",
4023
- secondRotate: 0,
4024
4224
  airHeight: 0,
4025
4225
  deltaHeight: 0,
4026
4226
  height: 0,
4027
- geometry: { cds: [], type: "polygon", coords: [], curveCpt: [], curveIndex: [] },
4227
+ geometry: {
4228
+ cds: [],
4229
+ type: "polygon",
4230
+ coords: [],
4231
+ curveCpt: [],
4232
+ curveIndex: []
4233
+ },
4028
4234
  opacity: 1,
4029
4235
  visible: true
4030
4236
  };
@@ -4032,37 +4238,40 @@ var GroundTexture = class extends Object3D10 {
4032
4238
  constructor(context, options) {
4033
4239
  super();
4034
4240
  this.context = context;
4035
- this.options = proxyOptions(
4036
- { ...defaultOptions3, ...options },
4037
- this
4038
- );
4241
+ this.options = options.map((item) => ({ ...defaultOptions3, ...item }));
4039
4242
  this.init();
4040
4243
  }
4041
4244
  options;
4042
4245
  mesh;
4043
4246
  async init() {
4044
- const { deltaHeight, airHeight, geometry, iconUrl, opacity } = this.options;
4045
- const shape = initShape(
4046
- geometry.coords[0],
4047
- geometry.coords.slice(1)
4048
- );
4049
- const extrudeGeometry = new ExtrudeGeometry3(shape, {
4050
- steps: 1,
4051
- bevelEnabled: false,
4052
- depth: 0,
4053
- curveSegments: 4
4054
- });
4055
- const planeMaterial = await this.context.materialFactory.createGroundTextureMaterial({
4056
- url: iconUrl,
4057
- opacity
4247
+ const geometries = this.options.map((options) => {
4248
+ const { geometry: geometry2 } = options;
4249
+ const shape = initShape(geometry2.coords[0], geometry2.coords.slice(1));
4250
+ const shapeGeometry = new ShapeGeometry(shape, 4);
4251
+ const uvs = [1, 1, 0, 1, 0, 0, 1, 0];
4252
+ shapeGeometry.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
4253
+ return shapeGeometry;
4058
4254
  });
4059
- const mesh = new Mesh5(extrudeGeometry, planeMaterial);
4255
+ const geometry = mergeGeometries2(geometries, true);
4256
+ geometries.forEach((geometry2) => geometry2.dispose());
4257
+ const materials = await Promise.all(this.options.map(async (option) => {
4258
+ const { iconUrl } = option;
4259
+ const texture = await this.context.textureFactory.getTexture(iconUrl);
4260
+ const material = new MeshBasicMaterial3({
4261
+ map: texture,
4262
+ alphaTest: 0.2,
4263
+ side: DoubleSide3
4264
+ });
4265
+ return material;
4266
+ }));
4267
+ const mesh = new Mesh5(geometry, materials);
4060
4268
  this.mesh = mesh;
4061
- this.mesh.position.z = airHeight + deltaHeight;
4269
+ this.position.z += 4e-3;
4062
4270
  this.add(mesh);
4063
4271
  }
4064
4272
  dispose() {
4065
4273
  this.mesh?.geometry.dispose();
4274
+ (this.mesh?.material).forEach((item) => item.dispose());
4066
4275
  this.clear();
4067
4276
  }
4068
4277
  };
@@ -4076,7 +4285,9 @@ var defaultGlbOptions = {
4076
4285
  width: 0,
4077
4286
  rotate: 1,
4078
4287
  airHeight: 1,
4079
- deltaHeight: 0
4288
+ deltaHeight: 0,
4289
+ center_x: 0,
4290
+ center_y: 0
4080
4291
  };
4081
4292
  var GlbModel = class extends Object3D11 {
4082
4293
  constructor(context, options) {
@@ -4096,8 +4307,7 @@ var GlbModel = class extends Object3D11 {
4096
4307
  const scale = this.options.width / max;
4097
4308
  this.scale.set(scale, scale, scale);
4098
4309
  this.add(object.scene);
4099
- const center2 = getCenter(this.options.geometry.coords[0]);
4100
- this.position.set(center2[0], center2[1], 0);
4310
+ this.position.set(this.options.center_x, this.options.center_y, 0);
4101
4311
  this.position.z += this.options.airHeight + this.options.deltaHeight;
4102
4312
  this.model = object;
4103
4313
  this.rotateZ(this.options.rotate);
@@ -4109,8 +4319,8 @@ var GlbModel = class extends Object3D11 {
4109
4319
  };
4110
4320
 
4111
4321
  // src/elements/lane.ts
4112
- import { BufferGeometry as BufferGeometry3, LineSegments as LineSegments3, Mesh as Mesh6, Object3D as Object3D12, ShapeGeometry, Vector3 as Vector313 } from "three";
4113
- import { mergeGeometries as mergeGeometries2 } from "three/examples/jsm/utils/BufferGeometryUtils";
4322
+ import { BufferGeometry as BufferGeometry3, LineSegments as LineSegments3, Mesh as Mesh6, Object3D as Object3D12, ShapeGeometry as ShapeGeometry2, Vector3 as Vector313 } from "three";
4323
+ import { mergeGeometries as mergeGeometries3 } from "three/examples/jsm/utils/BufferGeometryUtils";
4114
4324
  import { Line2 } from "three/examples/jsm/lines/Line2";
4115
4325
  import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
4116
4326
  var Lane = class extends Object3D12 {
@@ -4129,16 +4339,17 @@ var Lane = class extends Object3D12 {
4129
4339
  lineGeometry;
4130
4340
  Mesh;
4131
4341
  LineMesh;
4342
+ doubleLines = [];
4132
4343
  initGeometry() {
4133
4344
  const geometries = this.options.map((option) => {
4134
4345
  const shape = initShape(
4135
4346
  option.geometry.coords[0].slice(0, -1),
4136
4347
  option.geometry.coords.slice(1)
4137
4348
  );
4138
- const geometry = new ShapeGeometry(shape, 4);
4349
+ const geometry = new ShapeGeometry2(shape, 4);
4139
4350
  return geometry;
4140
4351
  });
4141
- this.geometry = mergeGeometries2(geometries);
4352
+ this.geometry = mergeGeometries3(geometries);
4142
4353
  geometries.forEach((item) => item.dispose());
4143
4354
  }
4144
4355
  initMaterial() {
@@ -4190,13 +4401,13 @@ var Lane = class extends Object3D12 {
4190
4401
  }
4191
4402
  return obj;
4192
4403
  }, {});
4193
- Object.values(group).map((options2) => {
4404
+ this.doubleLines = Object.values(group).map((options2) => {
4194
4405
  const material = this.context.materialFactory.createLine2MaterialMap({
4195
4406
  color: options2[0].secondColor,
4196
4407
  width: 0.2,
4197
4408
  dashed: options2[0].dashed
4198
4409
  });
4199
- options2.map((option) => {
4410
+ return options2.map((option) => {
4200
4411
  const geometry = new LineGeometry();
4201
4412
  const vec = option.geometry.otherCoords[1].map((item) => [...item, 0]).flat(2);
4202
4413
  geometry.setPositions(vec);
@@ -4204,15 +4415,16 @@ var Lane = class extends Object3D12 {
4204
4415
  line.computeLineDistances();
4205
4416
  line.position.z += 1e-3;
4206
4417
  this.add(line);
4418
+ return line;
4207
4419
  });
4208
- });
4420
+ }).flat(2);
4209
4421
  }
4210
4422
  initLineGeometry() {
4211
4423
  const geometries = this.options.map((option) => {
4212
4424
  const points = this.getBorderPoints(option);
4213
4425
  return new BufferGeometry3().setFromPoints(points);
4214
4426
  });
4215
- this.lineGeometry = mergeGeometries2(geometries);
4427
+ this.lineGeometry = mergeGeometries3(geometries);
4216
4428
  }
4217
4429
  createBorder() {
4218
4430
  const line = new LineSegments3(this.lineGeometry, this.lineMaterial);
@@ -4234,6 +4446,7 @@ var Lane = class extends Object3D12 {
4234
4446
  dispose() {
4235
4447
  this.geometry?.dispose();
4236
4448
  this.lineGeometry?.dispose();
4449
+ this.doubleLines.map((item) => item.geometry.dispose());
4237
4450
  this.clear();
4238
4451
  }
4239
4452
  };
@@ -4241,7 +4454,7 @@ var Lane = class extends Object3D12 {
4241
4454
  // src/elements/merge-graphic.ts
4242
4455
  import {
4243
4456
  Object3D as Object3D13,
4244
- ExtrudeGeometry as ExtrudeGeometry5,
4457
+ ExtrudeGeometry as ExtrudeGeometry3,
4245
4458
  Mesh as Mesh7,
4246
4459
  Vector3 as Vector314,
4247
4460
  BufferGeometry as BufferGeometry4,
@@ -4249,7 +4462,7 @@ import {
4249
4462
  ShaderMaterial as ShaderMaterial3,
4250
4463
  Color as Color4
4251
4464
  } from "three";
4252
- import { mergeGeometries as mergeGeometries3 } from "three/examples/jsm/utils/BufferGeometryUtils";
4465
+ import { mergeGeometries as mergeGeometries4 } from "three/examples/jsm/utils/BufferGeometryUtils";
4253
4466
  var MergeGraphic = class extends Object3D13 {
4254
4467
  constructor(context, options) {
4255
4468
  super();
@@ -4279,7 +4492,7 @@ var MergeGraphic = class extends Object3D13 {
4279
4492
  option.geometry.coords[0],
4280
4493
  option.geometry.coords.slice(1)
4281
4494
  );
4282
- const geometry2 = new ExtrudeGeometry5(shape, {
4495
+ const geometry2 = new ExtrudeGeometry3(shape, {
4283
4496
  steps: 1,
4284
4497
  bevelEnabled: false,
4285
4498
  depth: option.height,
@@ -4287,7 +4500,7 @@ var MergeGraphic = class extends Object3D13 {
4287
4500
  });
4288
4501
  return geometry2;
4289
4502
  });
4290
- const geometry = mergeGeometries3(geometries);
4503
+ const geometry = mergeGeometries4(geometries);
4291
4504
  geometries.forEach((geometry2) => geometry2.dispose());
4292
4505
  return geometry;
4293
4506
  }
@@ -4404,13 +4617,241 @@ var MergeGraphic = class extends Object3D13 {
4404
4617
  }
4405
4618
  };
4406
4619
 
4620
+ // src/elements/poi2.ts
4621
+ import {
4622
+ Box2 as Box22,
4623
+ Object3D as Object3D14,
4624
+ Sprite,
4625
+ SpriteMaterial,
4626
+ Vector2 as Vector26
4627
+ } from "three";
4628
+ var defaultOptions4 = {
4629
+ text: "",
4630
+ icon: "",
4631
+ icon_size: [18, 18],
4632
+ level: 1,
4633
+ collision_enable: true,
4634
+ opacity: 1,
4635
+ id: "",
4636
+ position: { x: 0, y: 0, z: 0 },
4637
+ text_font_size: 14
4638
+ };
4639
+ var Poi2 = class extends Object3D14 {
4640
+ constructor(context, options) {
4641
+ super();
4642
+ this.context = context;
4643
+ this.options = proxyOptions(
4644
+ { ...defaultOptions4, ...options },
4645
+ this
4646
+ );
4647
+ this.position.set(
4648
+ this.options.position.x,
4649
+ this.options.position.y,
4650
+ this.options.position.z
4651
+ );
4652
+ this.registryEvent();
4653
+ this.init();
4654
+ }
4655
+ options;
4656
+ textAspect = 1;
4657
+ spriteText;
4658
+ spriteIcon;
4659
+ box = new Box22();
4660
+ boxHelper;
4661
+ get durIconAndText() {
4662
+ return this.options.icon && this.options.text ? 2 : 0;
4663
+ }
4664
+ get offset() {
4665
+ return this.options.icon && this.options.text ? 0 : 0.5;
4666
+ }
4667
+ get iconWidth() {
4668
+ return this.options.icon ? this.options.icon_size[0] : 0;
4669
+ }
4670
+ get iconHeight() {
4671
+ return this.options.icon ? this.options.icon_size[1] : 0;
4672
+ }
4673
+ get textWidth() {
4674
+ return this.options.text ? this.options.text_font_size * this.textAspect : 0;
4675
+ }
4676
+ get textHeight() {
4677
+ return this.options.text ? this.options.text_font_size : 0;
4678
+ }
4679
+ get deltaZ() {
4680
+ const { offset, iconHeight, durIconAndText, textHeight } = this;
4681
+ let dz = offset * (iconHeight + durIconAndText + textHeight) / this.context.camera.zoom;
4682
+ dz += 0.1;
4683
+ return dz;
4684
+ }
4685
+ registryEvent() {
4686
+ this.context.addEventListener("control-zoom-change", this._initScale);
4687
+ this.addEventListener("change-icon", async ({ value }) => {
4688
+ if (this.spriteIcon) {
4689
+ this.remove(this.spriteIcon);
4690
+ this.spriteIcon = void 0;
4691
+ }
4692
+ await this.initIcon();
4693
+ this.initSize();
4694
+ this._initScale({ zoom: this.context.camera.zoom });
4695
+ });
4696
+ this.addEventListener("change-text", ({ value }) => {
4697
+ if (this.spriteText) {
4698
+ this.remove(this.spriteText);
4699
+ this.spriteText = void 0;
4700
+ }
4701
+ this.initText();
4702
+ this.initSize();
4703
+ this._initScale({ zoom: this.context.camera.zoom });
4704
+ });
4705
+ }
4706
+ unRegistryEvent() {
4707
+ this.context.removeEventListener("control-zoom-change", this._initScale);
4708
+ }
4709
+ async initIcon() {
4710
+ if (this.options.icon) {
4711
+ const texture = await getTextureByUrl(this.options.icon);
4712
+ const spriteIcon = new Sprite(
4713
+ new SpriteMaterial({
4714
+ map: texture,
4715
+ transparent: true,
4716
+ alphaTest: 0.2
4717
+ })
4718
+ );
4719
+ spriteIcon.renderOrder = 1e5;
4720
+ texture.needsUpdate = true;
4721
+ this.add(spriteIcon);
4722
+ this.spriteIcon = spriteIcon;
4723
+ }
4724
+ }
4725
+ initText() {
4726
+ if (this.options.text) {
4727
+ const texture = getTextureByText(this.options.text);
4728
+ this.textAspect = texture.image.width / texture.image.height;
4729
+ const spriteText = new Sprite(
4730
+ new SpriteMaterial({
4731
+ map: texture,
4732
+ transparent: true,
4733
+ alphaTest: 0.2
4734
+ })
4735
+ );
4736
+ spriteText.renderOrder = 100001;
4737
+ texture.needsUpdate = true;
4738
+ this.spriteText = spriteText;
4739
+ this.add(spriteText);
4740
+ }
4741
+ }
4742
+ initSize() {
4743
+ let iconCenterY = 0;
4744
+ let textCenterY = 0;
4745
+ const { icon, text } = this.options;
4746
+ if (icon) {
4747
+ if (text) {
4748
+ iconCenterY = 0;
4749
+ textCenterY = iconCenterY * (this.iconHeight / this.textHeight) - this.iconHeight / this.textHeight - this.durIconAndText / this.textHeight;
4750
+ } else {
4751
+ iconCenterY = 0.5;
4752
+ textCenterY = 0;
4753
+ }
4754
+ } else if (text) {
4755
+ textCenterY = 0.5;
4756
+ iconCenterY = 0;
4757
+ } else {
4758
+ iconCenterY = 0;
4759
+ textCenterY = 0;
4760
+ }
4761
+ this.spriteIcon?.center.set(0.5, iconCenterY);
4762
+ this.spriteText?.center.set(0.5, textCenterY);
4763
+ }
4764
+ async init() {
4765
+ await this.initIcon();
4766
+ this.initText();
4767
+ this.initSize();
4768
+ this._initScale({ zoom: this.context.camera.zoom });
4769
+ }
4770
+ _initScale = ({ zoom }) => {
4771
+ if (this.spriteText) {
4772
+ const scaleText = this.textHeight / zoom;
4773
+ this.spriteText.scale.set(this.textAspect * scaleText, scaleText, 0.1);
4774
+ }
4775
+ if (this.spriteIcon) {
4776
+ this.spriteIcon?.scale.set(
4777
+ this.options.icon_size[0] / zoom,
4778
+ this.options.icon_size[1] / zoom,
4779
+ 0.1
4780
+ );
4781
+ }
4782
+ this.resetZ();
4783
+ };
4784
+ resetZ() {
4785
+ const dz = this.deltaZ;
4786
+ if (this.spriteIcon) {
4787
+ this.spriteIcon.position.z = dz;
4788
+ }
4789
+ if (this.spriteText) {
4790
+ this.spriteText.position.z = dz;
4791
+ }
4792
+ }
4793
+ getBox(v3) {
4794
+ const {
4795
+ clientSize: { width, height }
4796
+ } = this.context;
4797
+ const x = width * (v3.x + 1) / 2;
4798
+ let y = height * (-v3.y + 1) / 2;
4799
+ y += this.offset * (this.iconHeight + this.durIconAndText + this.textHeight);
4800
+ const halfIconWidth = this.iconWidth / 2;
4801
+ const boundIcon = new Box22(
4802
+ new Vector26(x - halfIconWidth, y - this.iconHeight),
4803
+ new Vector26(x + halfIconWidth, y)
4804
+ );
4805
+ const halfTextWidth = this.textWidth / 2;
4806
+ const boundText = new Box22(
4807
+ new Vector26(x - halfTextWidth, y - this.textHeight - this.durIconAndText - this.iconHeight),
4808
+ new Vector26(
4809
+ x + halfTextWidth,
4810
+ y - this.iconHeight - this.durIconAndText
4811
+ )
4812
+ );
4813
+ this.box = boundText.union(boundIcon);
4814
+ return this.box;
4815
+ }
4816
+ renderBoxHelper() {
4817
+ if (!this.boxHelper) {
4818
+ const div = document.createElement("div");
4819
+ div.style.position = "fixed";
4820
+ this.boxHelper = div;
4821
+ div.style.border = "1px solid red";
4822
+ div.style.pointerEvents = "none";
4823
+ this.context.container.appendChild(div);
4824
+ }
4825
+ this.boxHelper.style.left = this.box.min.x + "px";
4826
+ this.boxHelper.style.top = this.box.min.y + "px";
4827
+ this.boxHelper.style.width = this.box.max.x - this.box.min.x + "px";
4828
+ this.boxHelper.style.height = this.box.max.y - this.box.min.y + "px";
4829
+ }
4830
+ // 碰撞检测设置显隐
4831
+ parentSetVisible(visible) {
4832
+ if (this.spriteText) {
4833
+ this.spriteText.visible = visible;
4834
+ }
4835
+ if (this.spriteIcon) {
4836
+ this.spriteIcon.visible = visible;
4837
+ }
4838
+ if (this.boxHelper) {
4839
+ this.boxHelper.style.display = visible ? "block" : "none";
4840
+ }
4841
+ }
4842
+ dispose() {
4843
+ this.unRegistryEvent();
4844
+ this.spriteText = void 0;
4845
+ }
4846
+ };
4847
+
4407
4848
  // src/operations/selection/box-selection.ts
4408
- import { Frustum } from "three";
4849
+ import { Frustum as Frustum2 } from "three";
4409
4850
  var BoxSelection = class extends BaseSvg {
4410
4851
  startPoint;
4411
4852
  endPoint;
4412
4853
  rect;
4413
- frustum = new Frustum();
4854
+ frustum = new Frustum2();
4414
4855
  constructor(context) {
4415
4856
  super(context);
4416
4857
  const { config: { selectBox: { fill, stroke } } } = context;
@@ -4661,7 +5102,7 @@ var Selection = class extends EventDispatcher4 {
4661
5102
  };
4662
5103
 
4663
5104
  // src/operations/hover/hover-helper.ts
4664
- import { EventDispatcher as EventDispatcher5 } from "three";
5105
+ import { EventDispatcher as EventDispatcher5, Vector2 as Vector27 } from "three";
4665
5106
  var HoverHelper = class extends EventDispatcher5 {
4666
5107
  constructor(context) {
4667
5108
  super();
@@ -4685,11 +5126,20 @@ var HoverHelper = class extends EventDispatcher5 {
4685
5126
  let distance = 1e4;
4686
5127
  poiGraphics.forEach((graphic) => {
4687
5128
  const poi = pois.find((poi2) => poi2.options.id === graphic.options.id);
4688
- const { x, y } = poi.clientPos;
4689
- let curDistance = Math.sqrt((x - e.offsetX) ** 2 + (y - e.offsetY) ** 2);
4690
- if (curDistance < distance) {
4691
- distance = curDistance;
4692
- resGraphic = graphic;
5129
+ if (poi instanceof Poi) {
5130
+ const { x, y } = poi.clientPos;
5131
+ let curDistance = Math.sqrt((x - e.offsetX) ** 2 + (y - e.offsetY) ** 2);
5132
+ if (curDistance < distance) {
5133
+ distance = curDistance;
5134
+ resGraphic = graphic;
5135
+ }
5136
+ } else if (poi instanceof Poi2) {
5137
+ const { x, y } = poi.box.getCenter(new Vector27());
5138
+ let curDistance = Math.sqrt((x - e.offsetX) ** 2 + (y - e.offsetY) ** 2);
5139
+ if (curDistance < distance) {
5140
+ distance = curDistance;
5141
+ resGraphic = graphic;
5142
+ }
4693
5143
  }
4694
5144
  });
4695
5145
  allGraphics.add(resGraphic);
@@ -4769,8 +5219,8 @@ import {
4769
5219
  MeshStandardMaterial as MeshStandardMaterial2,
4770
5220
  MeshBasicMaterial as MeshBasicMaterial5,
4771
5221
  ShaderMaterial as ShaderMaterial4,
4772
- DoubleSide as DoubleSide3,
4773
- Vector2 as Vector25
5222
+ DoubleSide as DoubleSide4,
5223
+ Vector2 as Vector28
4774
5224
  } from "three";
4775
5225
  function vectorToString(vector) {
4776
5226
  return `${vector.x}-${vector.y}-${vector.z}`;
@@ -4913,7 +5363,7 @@ var MaterialFactory = class {
4913
5363
  },
4914
5364
  vertexShader,
4915
5365
  fragmentShader,
4916
- side: DoubleSide3
5366
+ side: DoubleSide4
4917
5367
  });
4918
5368
  this.shaderMaterialMap.set(key, material);
4919
5369
  return material;
@@ -4926,9 +5376,10 @@ var MaterialFactory = class {
4926
5376
  const texture = await this.context.textureFactory.getTexture(url);
4927
5377
  const material = new MeshBasicMaterial5({
4928
5378
  map: texture,
4929
- transparent: true,
4930
- opacity
5379
+ alphaTest: 0.2,
5380
+ side: DoubleSide4
4931
5381
  });
5382
+ texture.needsUpdate = true;
4932
5383
  this.groundTextureMaterialMap.set(key, material);
4933
5384
  return material;
4934
5385
  }
@@ -4945,7 +5396,7 @@ var MaterialFactory = class {
4945
5396
  dashSize: 1,
4946
5397
  gapSize: 3,
4947
5398
  dashScale: 1,
4948
- resolution: new Vector25(this.context.clientSize.width, this.context.clientSize.height)
5399
+ resolution: new Vector28(this.context.clientSize.width, this.context.clientSize.height)
4949
5400
  });
4950
5401
  this.line2MaterialMap.set(key, material);
4951
5402
  return material;
@@ -4980,7 +5431,7 @@ var MaterialFactory = class {
4980
5431
  };
4981
5432
 
4982
5433
  // src/utils/camera-bound.ts
4983
- import { Box3 as Box38, Vector3 as Vector317 } from "three";
5434
+ import { Box3 as Box39, Vector3 as Vector318 } from "three";
4984
5435
  var CameraBound = class {
4985
5436
  constructor(context) {
4986
5437
  this.context = context;
@@ -4988,11 +5439,15 @@ var CameraBound = class {
4988
5439
  this.changePrevCamera();
4989
5440
  }
4990
5441
  prevCamera = {
4991
- position: new Vector317(),
5442
+ position: new Vector318(),
4992
5443
  zoom: 1,
4993
- target: new Vector317()
5444
+ target: new Vector318()
4994
5445
  };
4995
5446
  enable = true;
5447
+ box = new Box39();
5448
+ updateBox() {
5449
+ this.box.setFromObject(this.context.scene);
5450
+ }
4996
5451
  setEnable(enable) {
4997
5452
  this.enable = enable;
4998
5453
  if (enable) {
@@ -5027,13 +5482,13 @@ var CameraBound = class {
5027
5482
  if (!floors.length) {
5028
5483
  return null;
5029
5484
  }
5030
- const box = new Box38().setFromObject(this.context.scene);
5485
+ const box = this.box;
5031
5486
  const { camera, clientSize: { width: w, height: h } } = this.context;
5032
5487
  const { min, max } = box;
5033
5488
  const lb = vector3ToDevice(min, camera, w, h);
5034
5489
  const rt = vector3ToDevice(max, camera, w, h);
5035
- const lt = vector3ToDevice(new Vector317(min.x, max.y, max.z), camera, w, h);
5036
- const rb = vector3ToDevice(new Vector317(max.x, min.y, min.z), camera, w, h);
5490
+ const lt = vector3ToDevice(new Vector318(min.x, max.y, max.z), camera, w, h);
5491
+ const rb = vector3ToDevice(new Vector318(max.x, min.y, min.z), camera, w, h);
5037
5492
  const left = Math.min(lb.x, rt.x, lt.x, rb.x);
5038
5493
  const right = Math.max(lb.x, rt.x, lt.x, rb.x);
5039
5494
  const top = Math.min(lb.y, rt.y, lt.y, rb.y);
@@ -5072,24 +5527,31 @@ var CameraBound = class {
5072
5527
  };
5073
5528
 
5074
5529
  // src/factory/texture.ts
5075
- import { TextureLoader } from "three";
5530
+ import { TextureLoader as TextureLoader2 } from "three";
5076
5531
  var TextureFactory = class {
5077
5532
  constructor(context) {
5078
5533
  this.context = context;
5079
5534
  }
5080
5535
  textureMap = /* @__PURE__ */ new Map();
5081
- loader = new TextureLoader();
5536
+ loader = new TextureLoader2();
5082
5537
  async getTexture(url) {
5083
5538
  if (this.textureMap.has(url)) {
5084
5539
  return this.textureMap.get(url);
5085
5540
  }
5086
- const texture = await this.loader.loadAsync(url);
5087
- this.textureMap.set(url, texture);
5088
- return texture;
5541
+ const texturePromise = this.loader.loadAsync(url).then((texture) => {
5542
+ this.textureMap.set(url, texture);
5543
+ return texture;
5544
+ });
5545
+ this.textureMap.set(url, texturePromise);
5546
+ return texturePromise;
5089
5547
  }
5090
5548
  dispose() {
5091
5549
  this.textureMap.forEach((texture) => {
5092
- texture.dispose();
5550
+ if (texture instanceof Promise) {
5551
+ texture.then((res) => res.dispose());
5552
+ } else {
5553
+ texture.dispose();
5554
+ }
5093
5555
  });
5094
5556
  this.textureMap.clear();
5095
5557
  }
@@ -5134,6 +5596,7 @@ var Context = class extends EventDispatcher6 {
5134
5596
  y: 0
5135
5597
  };
5136
5598
  renderRf = 0;
5599
+ prevCameraZoom = 1;
5137
5600
  resizeClientSize() {
5138
5601
  const { x, y, width, height } = this.container.getBoundingClientRect();
5139
5602
  this.clientSize = {
@@ -5146,6 +5609,7 @@ var Context = class extends EventDispatcher6 {
5146
5609
  init() {
5147
5610
  const { clientWidth: w, clientHeight: h } = this.container;
5148
5611
  this.camera = initCamera(w, h);
5612
+ this.prevCameraZoom = this.camera.zoom;
5149
5613
  this.renderer.setSize(w, h);
5150
5614
  this.control = initControl(this.camera, this.renderer.domElement);
5151
5615
  this.control.maxPolarAngle = this.config.control.maxPolar;
@@ -5157,13 +5621,17 @@ var Context = class extends EventDispatcher6 {
5157
5621
  this.currentFloor?.setShadowOpacity(polarAngle / this.config.control.maxPolar);
5158
5622
  this.dispatchEvent({ type: "change-ratio", px: (this.basicRatio || 0) * this.camera.zoom });
5159
5623
  this.dispatchEvent({ type: "control-change" });
5624
+ if (this.prevCameraZoom !== this.camera.zoom) {
5625
+ this.dispatchEvent({ type: "control-zoom-change", zoom: this.camera.zoom });
5626
+ this.prevCameraZoom = this.camera.zoom;
5627
+ }
5160
5628
  });
5161
5629
  this.cameraBound = new CameraBound(this);
5162
5630
  }
5163
5631
  /**
5164
5632
  * 获取两个点之间的像素数
5165
5633
  */
5166
- getRatio(point1 = new Vector318(0, 0, 0), point22 = new Vector318(100, 0, 0)) {
5634
+ getRatio(point1 = new Vector319(0, 0, 0), point22 = new Vector319(100, 0, 0)) {
5167
5635
  const { clientWidth, clientHeight } = this.container;
5168
5636
  const device1 = vector3ToDevice(point1, this.camera, clientWidth, clientHeight);
5169
5637
  const device2 = vector3ToDevice(point22, this.camera, clientWidth, clientHeight);
@@ -5188,6 +5656,7 @@ var Context = class extends EventDispatcher6 {
5188
5656
  this.lights.position.x = position.x;
5189
5657
  this.lights.position.y = position.y;
5190
5658
  }
5659
+ this.cameraBound.updateBox();
5191
5660
  }
5192
5661
  onWindowResize = () => {
5193
5662
  const { container, camera, renderer } = this;
@@ -5224,10 +5693,10 @@ var Context = class extends EventDispatcher6 {
5224
5693
  * @returns
5225
5694
  */
5226
5695
  getGraphicsByDeviceXy(x, y) {
5227
- const point3 = new Vector26();
5696
+ const point3 = new Vector29();
5228
5697
  point3.x = x / this.clientSize.width * 2 - 1;
5229
5698
  point3.y = y / this.clientSize.height * -2 + 1;
5230
- const raycaster = new Raycaster3();
5699
+ const raycaster = new Raycaster5();
5231
5700
  raycaster.setFromCamera(point3, this.camera);
5232
5701
  raycaster.ray.origin.sub(raycaster.ray.direction.clone().multiplyScalar(100));
5233
5702
  const res = this.currentFloor?.graphicLayer.getGraphicByRaycaster(raycaster);
@@ -5241,7 +5710,8 @@ var Context = class extends EventDispatcher6 {
5241
5710
  */
5242
5711
  getPoisByDeviceXy(x, y) {
5243
5712
  const pois = this.currentFloor?.poiLayer.getPoiByDeviceXy(x, y);
5244
- return pois || [];
5713
+ const res = this.currentFloor?.poiLayer2.getPoiByDeviceXy(x, y);
5714
+ return (pois || []).concat(res || []);
5245
5715
  }
5246
5716
  onPointerover = (e) => {
5247
5717
  const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
@@ -5364,7 +5834,7 @@ var Context = class extends EventDispatcher6 {
5364
5834
  );
5365
5835
  }
5366
5836
  getCameraLookAt() {
5367
- return new Vector318().subVectors(this.control.target, this.camera.position);
5837
+ return new Vector319().subVectors(this.control.target, this.camera.position);
5368
5838
  }
5369
5839
  /**
5370
5840
  * 按照一个中心点设置相机的放大缩小
@@ -5416,28 +5886,28 @@ var Context = class extends EventDispatcher6 {
5416
5886
  if (force2DView) {
5417
5887
  this.setPolarAngle(0, 0);
5418
5888
  }
5419
- const boundingBox = new Box39().setFromObject(object);
5889
+ const boundingBox = new Box310().setFromObject(object);
5420
5890
  this.setPolarAngle(polar, 0);
5421
5891
  const { max, min } = boundingBox;
5422
- const leftTop = new Vector318(min.x, max.y, max.z);
5423
- const rightTop = new Vector318(max.x, max.y, max.z);
5424
- const rightBottom = new Vector318(max.x, min.y, min.z);
5425
- const leftBottom = new Vector318(min.x, min.y, min.z);
5892
+ const leftTop = new Vector319(min.x, max.y, max.z);
5893
+ const rightTop = new Vector319(max.x, max.y, max.z);
5894
+ const rightBottom = new Vector319(max.x, min.y, min.z);
5895
+ const leftBottom = new Vector319(min.x, min.y, min.z);
5426
5896
  const leftTop2d = vector3ToDevice(leftTop, this.camera, width, height);
5427
5897
  const rightTop2d = vector3ToDevice(rightTop, this.camera, width, height);
5428
5898
  const leftBottom2d = vector3ToDevice(leftBottom, this.camera, width, height);
5429
5899
  const rightBottom2d = vector3ToDevice(rightBottom, this.camera, width, height);
5430
- const boundingBox2d = new Box2().setFromPoints([
5431
- new Vector26(leftTop2d.x, leftTop2d.y),
5432
- new Vector26(rightTop2d.x, rightTop2d.y),
5433
- new Vector26(leftBottom2d.x, leftBottom2d.y),
5434
- new Vector26(rightBottom2d.x, rightBottom2d.y)
5900
+ const boundingBox2d = new Box23().setFromPoints([
5901
+ new Vector29(leftTop2d.x, leftTop2d.y),
5902
+ new Vector29(rightTop2d.x, rightTop2d.y),
5903
+ new Vector29(leftBottom2d.x, leftBottom2d.y),
5904
+ new Vector29(rightBottom2d.x, rightBottom2d.y)
5435
5905
  ]);
5436
- const size = boundingBox2d.getSize(new Vector26());
5906
+ const size = boundingBox2d.getSize(new Vector29());
5437
5907
  const xScale = (width - right - left) / size.x;
5438
5908
  const yScale = (height - top - bottom) / size.y;
5439
5909
  const scale = Math.min(xScale, yScale);
5440
- const center2 = new Vector318((max.x + min.x) / 2, (max.y + min.y) / 2, (max.z + min.z) / 2);
5910
+ const center2 = new Vector319((max.x + min.x) / 2, (max.y + min.y) / 2, (max.z + min.z) / 2);
5441
5911
  return { zoom: scale * this.camera.zoom, center: center2 };
5442
5912
  }
5443
5913
  /**
@@ -5469,10 +5939,17 @@ var Context = class extends EventDispatcher6 {
5469
5939
  * @param duration 动画持续时间
5470
5940
  */
5471
5941
  setCameraPosition(position, duration) {
5942
+ const start = this.camera.position.clone();
5943
+ const lookAtVector = this.getCameraLookAt();
5944
+ if (!duration) {
5945
+ this.control.enabled = false;
5946
+ this.camera.position.copy(position.clone().sub(lookAtVector));
5947
+ this.control.target.copy(position.clone());
5948
+ this.control.update();
5949
+ this.control.enabled = true;
5950
+ }
5472
5951
  return timeoutPromise(
5473
5952
  new Promise((resolve) => {
5474
- const start = this.camera.position.clone();
5475
- const lookAtVector = this.getCameraLookAt();
5476
5953
  const tween = new Tween(start, this.tweenGroup).to(position, duration).onUpdate(() => {
5477
5954
  this.camera.position.copy(start.clone().sub(lookAtVector));
5478
5955
  this.control.target.copy(start.clone());
@@ -5599,7 +6076,7 @@ function getConfig(config) {
5599
6076
  }
5600
6077
 
5601
6078
  // src/bmap.ts
5602
- import { debounce as debounce3 } from "lodash";
6079
+ import { debounce as debounce4 } from "lodash";
5603
6080
 
5604
6081
  // src/api/floor.ts
5605
6082
  async function loadBuildingGround({ brand, project }, config) {
@@ -5849,6 +6326,7 @@ var BMap = class extends EventDispatcher7 {
5849
6326
  if (createdFloor) {
5850
6327
  createdFloor.curFloor.name = floor;
5851
6328
  this.triggerHooks("switch_floor_before" /* SWITCH_FLOOR_BEFORE */, createdFloor);
6329
+ createdFloor.curFloor.updateBox();
5852
6330
  this.context.switchFloor(createdFloor.curFloor);
5853
6331
  this.initialFloorCamera();
5854
6332
  this.triggerHooks("switch_floor_after" /* SWITCH_FLOOR_AFTER */, createdFloor);
@@ -5988,7 +6466,7 @@ var BMap = class extends EventDispatcher7 {
5988
6466
  } = this.context;
5989
6467
  const device = vector3ToDevice(position, camera, width, height);
5990
6468
  const offsetX = device.x - width / 2;
5991
- const v3 = new Vector319();
6469
+ const v3 = new Vector320();
5992
6470
  v3.setFromMatrixColumn(this.context.camera.matrix, 0);
5993
6471
  v3.normalize();
5994
6472
  v3.multiplyScalar(offsetX / this.context.camera.zoom);
@@ -6093,7 +6571,7 @@ var BMap = class extends EventDispatcher7 {
6093
6571
  window.addEventListener("keydown", this.onKeydown);
6094
6572
  window.addEventListener("keyup", this.onKeyUp);
6095
6573
  if (this.config.resizeObserver) {
6096
- const observe = new ResizeObserver(debounce3(this.resize, 5));
6574
+ const observe = new ResizeObserver(debounce4(this.resize, 5));
6097
6575
  observe.observe(this.container);
6098
6576
  this.observe = observe;
6099
6577
  }
@@ -6213,15 +6691,16 @@ var BMap = class extends EventDispatcher7 {
6213
6691
  return this.context.currentFloor?.graphicLayer.createGraphic(options);
6214
6692
  }
6215
6693
  removePoiById(id) {
6216
- return this.context.currentFloor?.poiLayer.removePoiById(id);
6694
+ this.context.currentFloor?.poiLayer.removePoiById(id);
6695
+ this.context.currentFloor?.poiLayer2.removePoiById(id);
6217
6696
  }
6218
6697
  getPoiById(id) {
6219
- return this.context.currentFloor?.poiLayer.getPoiById(id);
6698
+ return this.context.currentFloor?.poiLayer.getPoiById(id) || this.context.currentFloor?.poiLayer2.getPoiById(id);
6220
6699
  }
6221
6700
  getPois() {
6222
- return (this.context.currentFloor?.poiLayer.pois || []).filter(
6701
+ return [...(this.context.currentFloor?.poiLayer.pois || []).filter(
6223
6702
  (item) => !item.options.built_in
6224
- );
6703
+ ), ...this.context.currentFloor?.poiLayer2.pois || []];
6225
6704
  }
6226
6705
  clearPoi() {
6227
6706
  if (this.context.currentFloor) {
@@ -6362,11 +6841,11 @@ function Worker2() {
6362
6841
  // src/plugins/navigation/path.ts
6363
6842
  import {
6364
6843
  Mesh as Mesh8,
6365
- Object3D as Object3D16,
6366
- TextureLoader as TextureLoader2,
6844
+ Object3D as Object3D17,
6845
+ TextureLoader as TextureLoader3,
6367
6846
  Color as Color8,
6368
- Vector2 as Vector28,
6369
- Vector3 as Vector321,
6847
+ Vector2 as Vector211,
6848
+ Vector3 as Vector322,
6370
6849
  NormalBlending,
6371
6850
  RepeatWrapping
6372
6851
  } from "three";
@@ -6374,8 +6853,8 @@ import {
6374
6853
  // src/external/meshLine.js
6375
6854
  import {
6376
6855
  BufferGeometry as BufferGeometry5,
6377
- Matrix4,
6378
- Vector3 as Vector320,
6856
+ Matrix4 as Matrix42,
6857
+ Vector3 as Vector321,
6379
6858
  Ray as Ray2,
6380
6859
  Sphere,
6381
6860
  LineSegments as LineSegments5,
@@ -6384,7 +6863,7 @@ import {
6384
6863
  ShaderMaterial as ShaderMaterial5,
6385
6864
  UniformsLib,
6386
6865
  Color as Color7,
6387
- Vector2 as Vector27
6866
+ Vector2 as Vector210
6388
6867
  } from "three";
6389
6868
  var MeshLine = class extends BufferGeometry5 {
6390
6869
  constructor() {
@@ -6402,7 +6881,7 @@ var MeshLine = class extends BufferGeometry5 {
6402
6881
  this._points = [];
6403
6882
  this._geom = null;
6404
6883
  this.widthCallback = null;
6405
- this.matrixWorld = new Matrix4();
6884
+ this.matrixWorld = new Matrix42();
6406
6885
  Object.defineProperties(this, {
6407
6886
  // this is now a bufferGeometry
6408
6887
  // add getter to support previous api
@@ -6455,7 +6934,7 @@ MeshLine.prototype.setPoints = function(points, wcb) {
6455
6934
  this.widthCallback = wcb;
6456
6935
  this.positions = [];
6457
6936
  this.counters = [];
6458
- if (points.length && points[0] instanceof Vector320) {
6937
+ if (points.length && points[0] instanceof Vector321) {
6459
6938
  for (var j = 0; j < points.length; j++) {
6460
6939
  var p = points[j];
6461
6940
  var c = j / points.length;
@@ -6476,10 +6955,10 @@ MeshLine.prototype.setPoints = function(points, wcb) {
6476
6955
  this.process();
6477
6956
  };
6478
6957
  function MeshLineRaycast(raycaster, intersects) {
6479
- var inverseMatrix = new Matrix4();
6958
+ var inverseMatrix = new Matrix42();
6480
6959
  var ray = new Ray2();
6481
6960
  var sphere = new Sphere();
6482
- var interRay = new Vector320();
6961
+ var interRay = new Vector321();
6483
6962
  var geometry = this.geometry;
6484
6963
  if (!geometry.boundingSphere) geometry.computeBoundingSphere();
6485
6964
  sphere.copy(geometry.boundingSphere);
@@ -6489,9 +6968,9 @@ function MeshLineRaycast(raycaster, intersects) {
6489
6968
  }
6490
6969
  inverseMatrix.copy(this.matrixWorld).invert();
6491
6970
  ray.copy(raycaster.ray).applyMatrix4(inverseMatrix);
6492
- var vStart = new Vector320();
6493
- var vEnd = new Vector320();
6494
- var interSegment = new Vector320();
6971
+ var vStart = new Vector321();
6972
+ var vEnd = new Vector321();
6973
+ var interSegment = new Vector321();
6495
6974
  var step = this instanceof LineSegments5 ? 2 : 1;
6496
6975
  var index = geometry.index;
6497
6976
  var attributes = geometry.attributes;
@@ -6545,8 +7024,8 @@ MeshLine.prototype.getDistance = function(i) {
6545
7024
  let maxLength = 0;
6546
7025
  for (let k = 0; k < i; k++) {
6547
7026
  const index = 6 * k;
6548
- const p0 = new Vector320(this.positions[index], this.positions[index + 1], this.positions[index + 2]);
6549
- const p1 = new Vector320(this.positions[index + 6], this.positions[index + 7], this.positions[index + 8]);
7027
+ const p0 = new Vector321(this.positions[index], this.positions[index + 1], this.positions[index + 2]);
7028
+ const p1 = new Vector321(this.positions[index + 6], this.positions[index + 7], this.positions[index + 8]);
6550
7029
  const distance = p0.distanceTo(p1);
6551
7030
  maxLength += distance;
6552
7031
  }
@@ -6781,6 +7260,7 @@ ShaderChunk["meshline_frag"] = [
6781
7260
  "uniform float visibility;",
6782
7261
  "uniform float alphaTest;",
6783
7262
  "uniform vec2 repeat;",
7263
+ "uniform float thresholdRatio;",
6784
7264
  "",
6785
7265
  "varying vec2 vUV;",
6786
7266
  "varying vec4 vColor;",
@@ -6801,6 +7281,9 @@ ShaderChunk["meshline_frag"] = [
6801
7281
  " gl_FragColor.a *= step(vCounters, visibility);",
6802
7282
  "",
6803
7283
  ShaderChunk.fog_fragment,
7284
+ "if (vUV.x <= thresholdRatio) {",
7285
+ "gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);",
7286
+ "}",
6804
7287
  "}"
6805
7288
  ].join("\n");
6806
7289
  var MeshLineMaterial = class extends ShaderMaterial5 {
@@ -6814,7 +7297,7 @@ var MeshLineMaterial = class extends ShaderMaterial5 {
6814
7297
  useAlphaMap: { value: 0 },
6815
7298
  color: { value: new Color7(16777215) },
6816
7299
  opacity: { value: 1 },
6817
- resolution: { value: new Vector27(1, 1) },
7300
+ resolution: { value: new Vector210(1, 1) },
6818
7301
  sizeAttenuation: { value: 1 },
6819
7302
  dashArray: { value: 0 },
6820
7303
  dashOffset: { value: 0 },
@@ -6822,7 +7305,12 @@ var MeshLineMaterial = class extends ShaderMaterial5 {
6822
7305
  useDash: { value: 0 },
6823
7306
  visibility: { value: 1 },
6824
7307
  alphaTest: { value: 0 },
6825
- repeat: { value: new Vector27(1, 1) }
7308
+ repeat: { value: new Vector210(1, 1) },
7309
+ thresholdRatio: { value: 0 },
7310
+ transparent: { value: true },
7311
+ depthTest: { vale: false },
7312
+ depthWrite: { value: false },
7313
+ alphaTest: { value: 0.2 }
6826
7314
  }),
6827
7315
  vertexShader: ShaderChunk.meshline_vert,
6828
7316
  fragmentShader: ShaderChunk.meshline_frag
@@ -6974,6 +7462,15 @@ var MeshLineMaterial = class extends ShaderMaterial5 {
6974
7462
  set: function(value) {
6975
7463
  this.uniforms.repeat.value.copy(value);
6976
7464
  }
7465
+ },
7466
+ thresholdRatio: {
7467
+ enumerable: true,
7468
+ get: function() {
7469
+ return this.uniforms.thresholdRatio.value;
7470
+ },
7471
+ set: function(value) {
7472
+ this.uniforms.thresholdRatio.value = value;
7473
+ }
6977
7474
  }
6978
7475
  });
6979
7476
  this.setValues(parameters);
@@ -7009,12 +7506,13 @@ var defaultConfig2 = {
7009
7506
  lineWidth: 8,
7010
7507
  color: 16777215
7011
7508
  };
7012
- var Path2 = class extends Object3D16 {
7509
+ var Path2 = class extends Object3D17 {
7013
7510
  constructor(navigation, config) {
7014
7511
  super();
7015
7512
  this.navigation = navigation;
7016
7513
  this.config = Object.assign({}, defaultConfig2, config);
7017
7514
  this.registryEvent();
7515
+ this.prevCameraZoom = this.navigation.bmap.context.camera.zoom;
7018
7516
  }
7019
7517
  mesh = null;
7020
7518
  geometry = null;
@@ -7022,7 +7520,9 @@ var Path2 = class extends Object3D16 {
7022
7520
  texture = null;
7023
7521
  config = defaultConfig2;
7024
7522
  points = [];
7523
+ pathDistance = 0;
7025
7524
  basicRepeat = 1;
7525
+ prevCameraZoom = 0;
7026
7526
  registryEvent() {
7027
7527
  this.navigation.bmap.context.addEventListener(
7028
7528
  "control-change",
@@ -7038,7 +7538,11 @@ var Path2 = class extends Object3D16 {
7038
7538
  this.navigation.bmap.context.removeEventListener("update", this.onUpdate);
7039
7539
  }
7040
7540
  onControlChange = () => {
7041
- this.changeRepeat();
7541
+ const zoom = this.navigation.bmap.context.camera.zoom;
7542
+ if (zoom !== this.prevCameraZoom) {
7543
+ this.prevCameraZoom = zoom;
7544
+ this.changeRepeat();
7545
+ }
7042
7546
  };
7043
7547
  onUpdate = () => {
7044
7548
  if (!this.texture) {
@@ -7058,7 +7562,7 @@ var Path2 = class extends Object3D16 {
7058
7562
  }
7059
7563
  } = this;
7060
7564
  const screenPoints = points.map(
7061
- ([x, y]) => vector3ToDevice(new Vector321(x, y, 0), camera, width, height)
7565
+ ([x, y]) => vector3ToDevice(new Vector322(x, y, 0), camera, width, height)
7062
7566
  ).map(({ x, y }) => [x, y]);
7063
7567
  const pointLength = getPathLength(screenPoints);
7064
7568
  return pointLength / 32;
@@ -7068,11 +7572,11 @@ var Path2 = class extends Object3D16 {
7068
7572
  return;
7069
7573
  }
7070
7574
  const repeat = this.getRepeat();
7071
- this.material.repeat = new Vector28(repeat, 1);
7575
+ this.material.repeat = new Vector211(repeat, 1);
7072
7576
  }
7073
7577
  loadTexture(url) {
7074
7578
  return new Promise((r, j) => {
7075
- new TextureLoader2().load(url, r, void 0, j);
7579
+ new TextureLoader3().load(url, r, void 0, j);
7076
7580
  });
7077
7581
  }
7078
7582
  transformPoints(points) {
@@ -7084,12 +7588,20 @@ var Path2 = class extends Object3D16 {
7084
7588
  }
7085
7589
  updatePoints(points) {
7086
7590
  this.points = points;
7591
+ this.pathDistance = getPathLength(points);
7087
7592
  this.changeRepeat();
7088
7593
  const _points = this.transformPoints(points);
7089
7594
  if (this.geometry) {
7090
7595
  this.geometry.setPoints(_points);
7091
7596
  }
7092
7597
  }
7598
+ movePath(distance) {
7599
+ if (!this.material || !this.pathDistance) {
7600
+ return;
7601
+ }
7602
+ const ratio = distance / this.pathDistance;
7603
+ this.material.thresholdRatio = ratio;
7604
+ }
7093
7605
  async create(points) {
7094
7606
  const lineGeometry = this.geometry = new MeshLine();
7095
7607
  this.updatePoints(points);
@@ -7103,7 +7615,7 @@ var Path2 = class extends Object3D16 {
7103
7615
  useMap: true,
7104
7616
  color: new Color8(this.config.color),
7105
7617
  transparent: true,
7106
- resolution: new Vector28(
7618
+ resolution: new Vector211(
7107
7619
  this.navigation.bmap.context.clientSize.width,
7108
7620
  this.navigation.bmap.context.clientSize.height
7109
7621
  ),
@@ -7112,9 +7624,10 @@ var Path2 = class extends Object3D16 {
7112
7624
  lineWidth: this.config.lineWidth * 2,
7113
7625
  map: this.texture,
7114
7626
  blending: NormalBlending,
7115
- repeat: new Vector28(this.getRepeat(), 1)
7627
+ repeat: new Vector211(this.getRepeat(), 1)
7116
7628
  });
7117
7629
  const mesh = this.mesh = new Mesh8(lineGeometry, material);
7630
+ mesh.renderOrder = 9;
7118
7631
  this.add(mesh);
7119
7632
  return mesh;
7120
7633
  }
@@ -7129,6 +7642,7 @@ var Path2 = class extends Object3D16 {
7129
7642
 
7130
7643
  // src/plugins/navigation/navigation.ts
7131
7644
  import { Group as TweenGroup2, Tween as Tween2 } from "@tweenjs/tween.js";
7645
+ import { Vector3 as Vector323 } from "three";
7132
7646
  var defaultConfig3 = {
7133
7647
  path: {},
7134
7648
  speed: 10,
@@ -7147,6 +7661,8 @@ var Navigation = class extends Plugin {
7147
7661
  options;
7148
7662
  pathTween = new TweenGroup2();
7149
7663
  startPoi = null;
7664
+ movedDistance = 0;
7665
+ pathStart = [0, 0];
7150
7666
  // 处理路线动画
7151
7667
  animationPathOptions = {
7152
7668
  cPathIndex: 0
@@ -7211,6 +7727,10 @@ var Navigation = class extends Plugin {
7211
7727
  this.pathTween.getAll().forEach((item) => item.stop());
7212
7728
  this.pathTween.removeAll();
7213
7729
  }
7730
+ if (this.startPoi) {
7731
+ this.bmap.context.currentFloor?.poiLayer2.removePoi(this.startPoi);
7732
+ this.startPoi = null;
7733
+ }
7214
7734
  }
7215
7735
  onSwitchFloor = ({ data: { curFloor } }) => {
7216
7736
  if (this.paths.length) {
@@ -7290,6 +7810,8 @@ var Navigation = class extends Plugin {
7290
7810
  this.animationPathOptions = {
7291
7811
  cPathIndex: 0
7292
7812
  };
7813
+ this.movedDistance = 0;
7814
+ this.pathStart = cPath[0];
7293
7815
  if (this.path) {
7294
7816
  this.path.updatePoints(cPath);
7295
7817
  } else {
@@ -7299,15 +7821,17 @@ var Navigation = class extends Plugin {
7299
7821
  this.bmap.context.scene.add(this.path);
7300
7822
  }
7301
7823
  if (this.startPoi) {
7302
- this.startPoi.dispose();
7824
+ this.bmap.context.currentFloor?.poiLayer2.removePoi(this.startPoi);
7303
7825
  this.startPoi = null;
7304
7826
  }
7305
7827
  if (this.options.needStartPoi) {
7306
- this.startPoi = this.bmap.context.currentFloor?.addPoi({
7828
+ this.startPoi = new Poi2(this.bmap.context, {
7307
7829
  ...this.options.startPoi,
7830
+ id: "navigation_start_poi",
7308
7831
  position: { x: cPath[0][0], y: cPath[0][1], z: 1e-4 },
7309
7832
  collision_enable: false
7310
7833
  }) || null;
7834
+ this.bmap.context.currentFloor?.poiLayer2.pushPoi(this.startPoi);
7311
7835
  }
7312
7836
  }
7313
7837
  catmullRomCurve3(points) {
@@ -7316,7 +7840,7 @@ var Navigation = class extends Plugin {
7316
7840
  /**
7317
7841
  * 按照指定速度移动到目标位置
7318
7842
  * @param point 目标位置
7319
- * @param speed 移动速度
7843
+ * @param speed 移动速度 / 米/s
7320
7844
  */
7321
7845
  async animationTo(point3, speed = this.options.speed) {
7322
7846
  if (point3.floor !== this.bmap.context.currentFloor?.name || !this.path) {
@@ -7326,7 +7850,7 @@ var Navigation = class extends Plugin {
7326
7850
  animationPathOptions: { cPathIndex }
7327
7851
  } = this;
7328
7852
  const currentPath = [
7329
- this.path.points[0],
7853
+ this.pathStart,
7330
7854
  ...this.cPath.slice(cPathIndex + 1)
7331
7855
  ];
7332
7856
  const translatedPos = this.translatePoints([point3.pos])[0];
@@ -7372,40 +7896,169 @@ var Navigation = class extends Plugin {
7372
7896
  moveDistanceArray.push(getLength(currentPath[index], pos));
7373
7897
  moveDistance = moveDistanceArray.reduce((sum, cur) => sum + cur, 0);
7374
7898
  }
7375
- const speedSecond = this.kmPerHourToMetersPerSecond(speed);
7376
- const timeSecond = moveDistance / speedSecond;
7899
+ const timeSecond = moveDistance / speed;
7377
7900
  this.pathTween.getAll().forEach((item) => item.stop());
7378
7901
  this.pathTween.removeAll();
7379
7902
  const start = { distance: 0 };
7903
+ const prevCPathIndex = this.animationPathOptions.cPathIndex;
7904
+ let pastRouteLength = 0;
7905
+ let pastRouteIndex = 0;
7380
7906
  return new Promise((resolve) => {
7381
- const tween = new Tween2(start, this.pathTween).to({ distance: moveDistance }, timeSecond * 1e3).onUpdate(() => {
7382
- for (let i = 0; i < moveDistanceArray.length; i++) {
7383
- const sumDistance = moveDistanceArray.slice(0, i + 1).reduce((sum, cur) => sum + cur, 0);
7384
- if (sumDistance >= start.distance) {
7385
- const prevDistance = sumDistance - moveDistanceArray[i];
7386
- const needDistance = start.distance - prevDistance;
7387
- const startPoint = currentPath[i];
7388
- const nextPoint = currentPath[i + 1];
7389
- const pos2 = moveOnRoute(startPoint, nextPoint, needDistance);
7390
- this.path?.updatePoints([pos2, ...currentPath.slice(i + 1)]);
7391
- this.animationPathOptions.cPathIndex += i;
7392
- if (this.startPoi) {
7393
- this.startPoi.position.setX(pos2[0]).setY(pos2[1]);
7394
- }
7395
- this.dispatchEvent({ type: "path-animation" });
7396
- return;
7397
- }
7907
+ const tween = new Tween2(start, this.pathTween).to({ distance: moveDistance }, timeSecond * 1e3).onUpdate(async () => {
7908
+ let dis = start.distance - pastRouteLength;
7909
+ while (moveDistanceArray.length && dis > moveDistanceArray[0]) {
7910
+ pastRouteLength += moveDistanceArray.shift();
7911
+ pastRouteIndex++;
7912
+ dis = start.distance - pastRouteLength;
7913
+ }
7914
+ const startPoint = currentPath[pastRouteIndex];
7915
+ const nextPoint = currentPath[pastRouteIndex + 1];
7916
+ if (!nextPoint) {
7917
+ return;
7398
7918
  }
7919
+ const pos2 = moveOnRoute(startPoint, nextPoint, dis);
7920
+ this.pathStart = pos2;
7921
+ this.path?.movePath(this.movedDistance + start.distance);
7922
+ this.animationPathOptions.cPathIndex = prevCPathIndex + pastRouteIndex;
7923
+ if (this.startPoi) {
7924
+ this.startPoi.position.setX(pos2[0]).setY(pos2[1]);
7925
+ const target = new Vector323(pos2[0], pos2[1], 0);
7926
+ const offset = new Vector323();
7927
+ offset.setFromMatrixColumn(this.bmap.context.camera.matrix, 1);
7928
+ offset.normalize();
7929
+ offset.multiplyScalar(150 / this.bmap.context.camera.zoom);
7930
+ target.add(offset);
7931
+ this.bmap.context.setCameraPosition(target, 0);
7932
+ }
7933
+ tween.pause();
7934
+ await this.changeCameraToPathUp(200);
7935
+ tween.resume();
7936
+ this.dispatchEvent({ type: "path-animation", pathIndex: this.animationPathOptions.cPathIndex });
7399
7937
  }).onComplete(() => {
7400
7938
  this.pathTween.remove(tween);
7401
7939
  this.dispatchEvent({ type: "path-animation-end" });
7940
+ this.movedDistance += moveDistance;
7941
+ resolve(true);
7942
+ }).start();
7943
+ });
7944
+ }
7945
+ // 计算路线的方向
7946
+ getPathDirection() {
7947
+ const path = this.cPath.slice(this.animationPathOptions.cPathIndex);
7948
+ if (path.length < 3) {
7949
+ return null;
7950
+ }
7951
+ const p0 = path[0];
7952
+ const p1 = path[1];
7953
+ const p2 = path[2];
7954
+ const angle = calc_angle(p0, p1, p2);
7955
+ if (Math.abs(angle) >= 179 && Math.abs(angle) <= 180) {
7956
+ const v1 = new Vector323(p2[0] - p1[0], p2[1] - p1[1], 0).normalize();
7957
+ const v2 = new Vector323(0, 1, 0).normalize();
7958
+ const angle2 = v1.angleTo(v2);
7959
+ const cross = new Vector323().crossVectors(v2, v1);
7960
+ const sign = Object.is(cross.y, 0) ? -1 : 1;
7961
+ const finalAngle = sign * angle2;
7962
+ return finalAngle;
7963
+ } else {
7964
+ return null;
7965
+ }
7966
+ }
7967
+ // 把相机旋转到路线的上方向
7968
+ async changeCameraToPathUp(duration = 100) {
7969
+ let angle = this.getPathDirection();
7970
+ if (angle === null) {
7971
+ return;
7972
+ }
7973
+ const currentAngle = this.bmap.context.control.getAzimuthalAngle();
7974
+ if (Math.abs(currentAngle - angle) > Math.PI) {
7975
+ if (currentAngle > 0) {
7976
+ angle = Math.PI * 2 + angle;
7977
+ } else {
7978
+ angle = angle - Math.PI * 2;
7979
+ }
7980
+ }
7981
+ const diffAngle = Math.abs(angle - this.bmap.context.control.getAzimuthalAngle());
7982
+ if (diffAngle < 0.01) {
7983
+ return;
7984
+ }
7985
+ const { control } = this.bmap.context;
7986
+ return new Promise((resolve) => {
7987
+ const start = { azimuthal: control.getAzimuthalAngle() };
7988
+ const end = { azimuthal: angle };
7989
+ const tween = new Tween2(start, this.pathTween).to(end, duration).onUpdate(() => {
7990
+ control.target.copy(this.startPoi.position);
7991
+ control.maxAzimuthAngle = start.azimuthal;
7992
+ control.minAzimuthAngle = start.azimuthal;
7993
+ control.update();
7994
+ const target = this.startPoi.position.clone();
7995
+ const offset = new Vector323();
7996
+ offset.setFromMatrixColumn(this.bmap.context.camera.matrix, 1);
7997
+ offset.normalize();
7998
+ offset.multiplyScalar(150 / this.bmap.context.camera.zoom);
7999
+ target.add(offset);
8000
+ this.bmap.context.setCameraPosition(target, 0);
8001
+ }).onComplete(() => {
8002
+ control.enabled = true;
8003
+ this.pathTween.remove(tween);
7402
8004
  resolve(true);
8005
+ }).onStart(() => {
8006
+ control.enabled = false;
7403
8007
  }).start();
7404
8008
  });
7405
8009
  }
7406
- kmPerHourToMetersPerSecond(speedInKmPerHour) {
7407
- const speedInMetersPerSecond = speedInKmPerHour * 1e3 / 3600;
7408
- return speedInMetersPerSecond;
8010
+ async initNavigationCamera() {
8011
+ await this.translateCameraToStartPoi(300);
8012
+ await this.changeCameraToPathUp(300);
8013
+ }
8014
+ async translateCameraToStartPoi(duration = 100) {
8015
+ if (!this.startPoi) {
8016
+ return;
8017
+ }
8018
+ const {
8019
+ clientSize: { width, height },
8020
+ camera,
8021
+ control
8022
+ } = this.bmap.context;
8023
+ const halfWidth = Math.round(width / 2);
8024
+ const halfHeight = Math.round(height / 2);
8025
+ const target = control.target.clone();
8026
+ const device = vector3ToDevice(this.startPoi.position, camera, width, height);
8027
+ const offsetX = device.x - halfWidth;
8028
+ const offsetY = halfHeight - device.y + 150;
8029
+ console.log(device, offsetX, offsetY, this.startPoi.position, halfWidth, halfHeight);
8030
+ if (Math.abs(offsetX) < 1 && Math.abs(offsetY) < 1) {
8031
+ return;
8032
+ }
8033
+ if (Math.abs(offsetX) >= 1) {
8034
+ const xv3 = new Vector323();
8035
+ xv3.setFromMatrixColumn(camera.matrix, 0);
8036
+ xv3.normalize();
8037
+ xv3.multiplyScalar(offsetX / camera.zoom);
8038
+ target.add(new Vector323(xv3.x, 0, 0));
8039
+ }
8040
+ if (Math.abs(offsetY) >= 1) {
8041
+ const v3 = new Vector323();
8042
+ v3.setFromMatrixColumn(camera.matrix, 1);
8043
+ v3.normalize();
8044
+ v3.multiplyScalar(offsetY / camera.zoom);
8045
+ target.add(new Vector323(0, v3.y, 0));
8046
+ }
8047
+ return this.bmap.context.setCameraPosition(target, duration);
8048
+ }
8049
+ async initCameraZoom(duration = 100) {
8050
+ if (!this.startPoi) {
8051
+ return;
8052
+ }
8053
+ const { clientSize: { width, height }, currentFloor } = this.bmap.context;
8054
+ const { max, min } = currentFloor.box;
8055
+ const baseScale = Math.min(width / (max.x - min.x), height / (max.y - min.y));
8056
+ const zoom = baseScale * (max.x - min.x) / 20;
8057
+ return this.bmap.context.setZoom(
8058
+ zoom,
8059
+ this.startPoi.position,
8060
+ duration
8061
+ );
7409
8062
  }
7410
8063
  dispose() {
7411
8064
  this.worker.terminate();
@@ -7542,6 +8195,7 @@ var MulFloors = class extends Plugin {
7542
8195
  this.group.add(this.poiLayer, ...floors);
7543
8196
  scene.add(this.group);
7544
8197
  this.floors = floors;
8198
+ this.bmap.context.cameraBound.updateBox();
7545
8199
  }
7546
8200
  hide() {
7547
8201
  const { scene } = this.bmap.context;
@@ -7740,7 +8394,10 @@ var AibeeLoader = class {
7740
8394
  try {
7741
8395
  const cacheVersion = await this.getCacheData(VersionStoreName, cacheKey);
7742
8396
  if (cacheVersion === floorInfo.version_id) {
7743
- const res = await this.getCacheData(MapDataStoreName, cacheKey);
8397
+ const res = await this.getCacheData(
8398
+ MapDataStoreName,
8399
+ cacheKey
8400
+ );
7744
8401
  if (res) {
7745
8402
  return this.getDataByJson(res);
7746
8403
  }
@@ -7754,6 +8411,7 @@ var AibeeLoader = class {
7754
8411
  const cacheKey = this.getFloorCacheKey(floorInfo);
7755
8412
  console.time(`zstd_json`);
7756
8413
  const res1 = await fetch(floorInfo.map_url).then((res) => res.json());
8414
+ res1.floor = floorInfo.floor;
7757
8415
  console.timeEnd(`zstd_json`);
7758
8416
  this.setCacheData(MapDataStoreName, cacheKey, res1);
7759
8417
  this.setCacheData(VersionStoreName, cacheKey, floorInfo.version_id);
@@ -7761,25 +8419,33 @@ var AibeeLoader = class {
7761
8419
  }
7762
8420
  // 获取路网数据
7763
8421
  async getRoadNetworkData() {
7764
- const res = await Promise.all(this.floors.map(async (item) => {
7765
- const cacheKey = this.getFloorCacheKey(item);
7766
- try {
7767
- const cacheVersion = await this.getCacheData(VersionStoreName, cacheKey);
7768
- if (cacheVersion === item.version_id) {
7769
- const res2 = await this.getCacheData(RoadNetworkDataStoreName, cacheKey);
7770
- if (res2) {
7771
- return res2;
8422
+ const res = await Promise.all(
8423
+ this.floors.map(async (item) => {
8424
+ const cacheKey = this.getFloorCacheKey(item);
8425
+ try {
8426
+ const cacheVersion = await this.getCacheData(
8427
+ VersionStoreName,
8428
+ cacheKey
8429
+ );
8430
+ if (cacheVersion === item.version_id) {
8431
+ const res2 = await this.getCacheData(
8432
+ RoadNetworkDataStoreName,
8433
+ cacheKey
8434
+ );
8435
+ if (res2) {
8436
+ return res2;
8437
+ }
7772
8438
  }
8439
+ const route = await fetch(item.route_url).then((res2) => res2.json());
8440
+ this.setCacheData(RoadNetworkDataStoreName, cacheKey, route);
8441
+ return route;
8442
+ } catch {
8443
+ const route = await fetch(item.route_url).then((res2) => res2.json());
8444
+ this.setCacheData(RoadNetworkDataStoreName, cacheKey, route);
8445
+ return route;
7773
8446
  }
7774
- const route = await fetch(item.route_url).then((res2) => res2.json());
7775
- await this.setCacheData(RoadNetworkDataStoreName, cacheKey, route);
7776
- return route;
7777
- } catch {
7778
- const route = await fetch(item.route_url).then((res2) => res2.json());
7779
- await this.setCacheData(RoadNetworkDataStoreName, cacheKey, route);
7780
- return route;
7781
- }
7782
- }));
8447
+ })
8448
+ );
7783
8449
  return res.filter((item) => item.points);
7784
8450
  }
7785
8451
  // 空闲时间请求其他数据
@@ -7787,7 +8453,9 @@ var AibeeLoader = class {
7787
8453
  }
7788
8454
  // 获取多楼层数据
7789
8455
  async getMulFloorsData(floors) {
7790
- return Promise.all(floors.map((floor) => this.getFloorData(floor))).then((data) => data.filter((item) => item));
8456
+ return Promise.all(floors.map((floor) => this.getFloorData(floor))).then(
8457
+ (data) => data.filter((item) => item)
8458
+ );
7791
8459
  }
7792
8460
  async getDataByUrl(url) {
7793
8461
  const data = await fetch(url).then((res) => res.json());
@@ -7820,38 +8488,61 @@ var AibeeLoader = class {
7820
8488
  });
7821
8489
  floor.userData.graphics = graphics;
7822
8490
  floor.userData.graphicMap = graphicMap;
7823
- const group = canMergeGraphics.reduce((obj, options) => {
7824
- const { fillColor, fillOpacity, strokeColor, strokeOpacity, height } = options;
7825
- const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}-${height}`;
7826
- if (obj[key]) {
7827
- obj[key].push(options);
7828
- } else {
7829
- obj[key] = [options];
7830
- }
7831
- return obj;
7832
- }, {});
8491
+ const group = canMergeGraphics.reduce(
8492
+ (obj, options) => {
8493
+ const {
8494
+ fillColor,
8495
+ fillOpacity,
8496
+ strokeColor,
8497
+ strokeOpacity,
8498
+ height
8499
+ } = options;
8500
+ const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}-${height}`;
8501
+ if (obj[key]) {
8502
+ obj[key].push(options);
8503
+ } else {
8504
+ obj[key] = [options];
8505
+ }
8506
+ return obj;
8507
+ },
8508
+ {}
8509
+ );
7833
8510
  Object.values(group).forEach((options) => {
7834
- const mergeGeometries4 = new MergeGraphic(this.bmap.context, options);
7835
- floor.mergeGraphicLayer.add(mergeGeometries4);
8511
+ const mergeGeometries5 = new MergeGraphic(
8512
+ this.bmap.context,
8513
+ options
8514
+ );
8515
+ floor.mergeGraphicLayer.add(mergeGeometries5);
7836
8516
  });
7837
8517
  break;
7838
8518
  case "ground":
7839
8519
  transformGraphicData(layer.elements, center2);
7840
- const grounds = layer.elements.map((options) => new Graphic(this.bmap.context, options));
8520
+ const grounds = layer.elements.map(
8521
+ (options) => new Graphic(this.bmap.context, options)
8522
+ );
7841
8523
  floor.addGrounds(grounds);
7842
8524
  break;
7843
8525
  case "wall":
7844
8526
  transformGraphicData(layer.elements, center2);
7845
- const wallGroup = layer.elements.reduce((obj, options) => {
7846
- const { fillColor, fillOpacity, strokeColor, strokeOpacity, height } = options;
7847
- const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}-${height}`;
7848
- if (obj[key]) {
7849
- obj[key].push(options);
7850
- } else {
7851
- obj[key] = [options];
7852
- }
7853
- return obj;
7854
- }, {});
8527
+ const wallGroup = layer.elements.reduce(
8528
+ (obj, options) => {
8529
+ const {
8530
+ fillColor,
8531
+ fillOpacity,
8532
+ strokeColor,
8533
+ strokeOpacity,
8534
+ height
8535
+ } = options;
8536
+ const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}-${height}`;
8537
+ if (obj[key]) {
8538
+ obj[key].push(options);
8539
+ } else {
8540
+ obj[key] = [options];
8541
+ }
8542
+ return obj;
8543
+ },
8544
+ {}
8545
+ );
7855
8546
  Object.values(wallGroup).forEach((optionArray) => {
7856
8547
  const wall = new Wall(this.bmap.context, optionArray);
7857
8548
  floor.wallLayer.add(wall);
@@ -7859,16 +8550,19 @@ var AibeeLoader = class {
7859
8550
  break;
7860
8551
  case "lane":
7861
8552
  transformGraphicData(layer.elements, center2);
7862
- const laneGroup = layer.elements.reduce((obj, options) => {
7863
- const { fillColor, fillOpacity, strokeColor, strokeOpacity } = options;
7864
- const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}`;
7865
- if (obj[key]) {
7866
- obj[key].push(options);
7867
- } else {
7868
- obj[key] = [options];
7869
- }
7870
- return obj;
7871
- }, {});
8553
+ const laneGroup = layer.elements.reduce(
8554
+ (obj, options) => {
8555
+ const { fillColor, fillOpacity, strokeColor, strokeOpacity } = options;
8556
+ const key = `${fillColor}-${fillOpacity}-${strokeColor}-${strokeOpacity}`;
8557
+ if (obj[key]) {
8558
+ obj[key].push(options);
8559
+ } else {
8560
+ obj[key] = [options];
8561
+ }
8562
+ return obj;
8563
+ },
8564
+ {}
8565
+ );
7872
8566
  Object.values(laneGroup).forEach((optionArray) => {
7873
8567
  const lane = new Lane(this.bmap.context, optionArray);
7874
8568
  floor.laneLayer.add(lane);
@@ -7877,19 +8571,23 @@ var AibeeLoader = class {
7877
8571
  case "texture2d":
7878
8572
  case "texture3d":
7879
8573
  transformGraphicData(layer.elements, center2);
7880
- layer.elements.forEach((options) => {
7881
- const texture = new GroundTexture(this.bmap.context, options);
7882
- floor.textureLayer.add(texture);
7883
- });
8574
+ const texture = new GroundTexture(this.bmap.context, layer.elements);
8575
+ floor.textureLayer.add(texture);
7884
8576
  break;
7885
8577
  case "glb":
7886
8578
  transformGraphicData(layer.elements, center2);
7887
8579
  layer.elements.forEach((options) => {
8580
+ const pos = translatePosToCenter(
8581
+ [options.center_x, options.center_y],
8582
+ center2
8583
+ );
7888
8584
  const model = new GlbModel(this.bmap.context, {
7889
8585
  ...options,
7890
8586
  url: options.secondUrl,
7891
8587
  rotate: options.secondRotate,
7892
- width: options.secondWidth
8588
+ width: options.secondWidth,
8589
+ center_x: pos[0],
8590
+ center_y: pos[1]
7893
8591
  });
7894
8592
  floor.glbModelLayer.add(model);
7895
8593
  });
@@ -7897,17 +8595,21 @@ var AibeeLoader = class {
7897
8595
  case "store":
7898
8596
  transformGraphicData(layer.elements, center2);
7899
8597
  layer.elements.map((options) => {
7900
- const pos = translatePosToCenter([options.center_x, options.center_y], center2);
8598
+ const pos = translatePosToCenter(
8599
+ [options.center_x, options.center_y],
8600
+ center2
8601
+ );
7901
8602
  const graphic = floor.addGraphic(options);
7902
8603
  floor.userData.graphics.push(graphic);
7903
8604
  floor.userData.graphicMap.set(options.id, graphic);
7904
- const poi = floor.poiLayer.createPoi({
8605
+ const poi = new Poi2(this.bmap.context, {
7905
8606
  id: options.id,
7906
8607
  icon: options.poi_info.icon,
7907
- texts: [{ text: options.poi_info.showName || options.store_name || options.poi_info.text }],
7908
- position: { x: pos[0], y: pos[1], z: options.airHeight },
8608
+ text: options.poi_info.showName || options.store_name || options.poi_info.text,
8609
+ position: { x: pos[0], y: pos[1], z: options.airHeight + options.height },
7909
8610
  icon_size: [18, 18]
7910
8611
  });
8612
+ floor.poiLayer2.pushPoi(poi);
7911
8613
  if (poi) {
7912
8614
  poi.userData.type = "store";
7913
8615
  poi.userData.data = options;
@@ -7917,22 +8619,24 @@ var AibeeLoader = class {
7917
8619
  case "facility":
7918
8620
  transformGraphicData(layer.elements, center2);
7919
8621
  layer.elements.map((options) => {
7920
- const pos = translatePosToCenter(options.geometry.cds, center2);
8622
+ const pos = translatePosToCenter(
8623
+ options.geometry.cds,
8624
+ center2
8625
+ );
7921
8626
  const graphic = floor.addGraphic(options);
7922
8627
  floor.userData.graphics.push(graphic);
7923
8628
  floor.userData.graphicMap.set(options.id, graphic);
7924
8629
  if (options.poi_info) {
7925
- const poi = floor.poiLayer.createPoi({
8630
+ const poi = new Poi2(this.bmap.context, {
7926
8631
  id: options.id,
7927
8632
  icon: options.poi_info.icon,
7928
- texts: [{ text: options.poi_info.showName || options.store_name || options.poi_info.text }],
7929
- position: { x: pos[0], y: pos[1], z: options.airHeight },
8633
+ text: options.poi_info.showName || options.store_name || options.poi_info.text,
8634
+ position: { x: pos[0], y: pos[1], z: options.airHeight + options.height },
7930
8635
  icon_size: [18, 18]
7931
8636
  });
7932
- if (poi) {
7933
- poi.userData.type = "facility";
7934
- poi.userData.data = options;
7935
- }
8637
+ floor.poiLayer2.pushPoi(poi);
8638
+ poi.userData.type = "facility";
8639
+ poi.userData.data = options;
7936
8640
  }
7937
8641
  });
7938
8642
  break;
@@ -7944,17 +8648,25 @@ var AibeeLoader = class {
7944
8648
  const graphic = floor.addGraphic(options);
7945
8649
  parkingSpacesGraphics.push(graphic);
7946
8650
  parkingSpacesGraphicMap.set(options.id, graphic);
7947
- const pos = translatePosToCenter([options.center_x, options.center_y], center2);
8651
+ const pos = translatePosToCenter(
8652
+ [options.center_x, options.center_y],
8653
+ center2
8654
+ );
7948
8655
  if (options.texts[0]) {
7949
- const poi = floor.poiLayer.createPoi({
8656
+ const poi = new Poi2(this.bmap.context, {
7950
8657
  id: options.id,
7951
- texts: [{ text: options.texts[0] }],
7952
- position: { x: pos[0], y: pos[1], z: options.airHeight }
8658
+ text: options.texts[0],
8659
+ position: {
8660
+ x: pos[0],
8661
+ y: pos[1],
8662
+ z: options.airHeight + options.height
8663
+ }
7953
8664
  });
7954
8665
  if (poi) {
7955
8666
  poi.userData.type = "parkingSpace";
7956
8667
  poi.userData.data = options;
7957
8668
  }
8669
+ floor.poiLayer2.pushPoi(poi);
7958
8670
  }
7959
8671
  });
7960
8672
  floor.userData.parkingSpaces = parkingSpacesGraphics;
@@ -7965,6 +8677,8 @@ var AibeeLoader = class {
7965
8677
  floor.userData.center = center2;
7966
8678
  floor.userData.height = data.floorHeight;
7967
8679
  floor.name = data.floor;
8680
+ floor.userData.data = data;
8681
+ floor.updateBox();
7968
8682
  return floor;
7969
8683
  }
7970
8684
  clear() {
@@ -7999,7 +8713,9 @@ export {
7999
8713
  Overlay,
8000
8714
  PathDirection,
8001
8715
  Poi,
8716
+ Poi2,
8002
8717
  PoiLayer,
8718
+ PoiLayer2,
8003
8719
  RoadNetwork,
8004
8720
  RoadNetwork2,
8005
8721
  SelectBox,
@@ -8032,6 +8748,7 @@ export {
8032
8748
  disposeLoader,
8033
8749
  distancePointToSegment,
8034
8750
  generatorKeyByObj,
8751
+ getAngle,
8035
8752
  getCenter,
8036
8753
  getConfig,
8037
8754
  getDirectPath,
@@ -8039,6 +8756,7 @@ export {
8039
8756
  getLongestSideDir,
8040
8757
  getPathLength,
8041
8758
  getTextureByText,
8759
+ getTextureByUrl,
8042
8760
  hasChinese,
8043
8761
  initCamera,
8044
8762
  initCanvas,