@kimap/indoor-positioning-sdk-vue2 5.9.6 → 5.9.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimap/indoor-positioning-sdk-vue2",
3
- "version": "5.9.6",
3
+ "version": "5.9.8",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -146,6 +146,41 @@ KimapSDK.prototype.handleClick = function(event) {
146
146
  KimapSDK.prototype.startRenderLoop = function() {
147
147
  var self = this;
148
148
  var lastTime = Date.now();
149
+ var _cameraMoving = false;
150
+ var _movementTimer = null;
151
+
152
+ // 检测相机停止后打印俯仰角和缩放距离
153
+ function checkCameraStopped() {
154
+ if (!self.core || !self.core.camera || !self.core.controls) return;
155
+ var cam = self.core.camera;
156
+ var ctl = self.core.controls;
157
+ // 计算球面坐标中的俯仰角(极角,从+Y方向看过去)
158
+ var dx = cam.position.x - ctl.target.x;
159
+ var dy = cam.position.y - ctl.target.y;
160
+ var dz = cam.position.z - ctl.target.z;
161
+ var dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
162
+ // polar angle: 从+Y轴向下看的角度,0=正上方,PI/2=地平线
163
+ var polarRad = Math.acos(dy / dist);
164
+ // azimuth: 从+Z方向逆时针到XZ平面的角度
165
+ var azimuthRad = Math.atan2(dx, dz);
166
+ var polarDeg = (polarRad * 180 / Math.PI).toFixed(2);
167
+ var azimuthDeg = (azimuthRad * 180 / Math.PI).toFixed(2);
168
+ var distDeg = dist.toFixed(2);
169
+ console.log('[Camera Debug] 俯仰角: ' + polarDeg + '° | 方位角: ' + azimuthDeg + '° | 距离: ' + distDeg);
170
+ }
171
+
172
+ function onControlsChange() {
173
+ _cameraMoving = true;
174
+ if (_movementTimer) clearTimeout(_movementTimer);
175
+ _movementTimer = setTimeout(function() {
176
+ _cameraMoving = false;
177
+ checkCameraStopped();
178
+ }, 300);
179
+ }
180
+
181
+ if (this.core && this.core.controls) {
182
+ this.core.controls.addEventListener('change', onControlsChange);
183
+ }
149
184
 
150
185
  function animate() {
151
186
  self.animationFrameId = requestAnimationFrame(animate);
@@ -629,9 +664,9 @@ KimapSDK.prototype.showSingleFloor = function(floorIndex) {
629
664
  this.floorGroups.forEach(function(group, idx) {
630
665
  if (idx === floorIndex) {
631
666
  if (isFromAll) {
632
- // ALL→单楼:目标层保持在 ALL 位置
667
+ // ALL→单楼:目标层回到 Y=0 贴地
633
668
  group.visible = true;
634
- group.position.y = self.core.floorOriginalY[idx] || 0;
669
+ group.position.y = 0;
635
670
  } else {
636
671
  // 单楼→单楼:目标层滑入动画
637
672
  group.visible = true;
@@ -644,13 +679,9 @@ KimapSDK.prototype.showSingleFloor = function(floorIndex) {
644
679
  });
645
680
  }
646
681
  } else {
647
- if (isFromAll) {
648
- // ALL→单楼:其他楼层保持 ALL 位置,不隐藏
649
- group.visible = true;
650
- group.position.y = self.core.floorOriginalY[idx] || 0;
651
- } else {
652
- // 单楼→单楼:离场层立即消失
653
- group.visible = false;
682
+ // 无论 ALL→单楼 还是 单楼→单楼,非目标楼层一律隐藏
683
+ group.visible = false;
684
+ if (!isFromAll) {
654
685
  var origY = self.core.floorOriginalY[idx] || 0;
655
686
  group.position.y = -origY - 1;
656
687
  }
@@ -708,13 +739,13 @@ KimapSDK.prototype._adjustCameraToFloor = function(floorIndex) {
708
739
  box.getCenter(center);
709
740
  box.getSize(size);
710
741
  var maxSize = Math.max(size.x, size.z);
711
- var dist = maxSize * 1.5;
742
+ var dist = maxSize * 1.2;
712
743
 
713
- // -60° 俯角:camera.y = center.y + dist*1.732, camera.z = center.z + dist
744
+ // -60° 俯角:camera.y = center.y + dist*0.866, camera.z = center.z + dist*0.5
714
745
  var targetPosition = new THREE.Vector3(
715
746
  center.x,
716
- center.y + dist * 1.732,
717
- center.z + dist
747
+ center.y + dist * 0.866,
748
+ center.z + dist * 0.5
718
749
  );
719
750
 
720
751
  this._animateCamera({
@@ -774,13 +805,13 @@ KimapSDK.prototype._zoomToShowAllFloors = function() {
774
805
  box.getCenter(center);
775
806
  box.getSize(size);
776
807
  var maxSize = Math.max(size.x, size.z);
777
- var dist = maxSize * 2.5;
808
+ var dist = maxSize * 1.2;
778
809
 
779
- // -15° 俯角:sin(-15°)0.259, cos(-15°)0.966(从建筑斜上方俯视)
810
+ // -60° 俯角:sin(60°)=0.866, cos(60°)=0.5(从模型斜上方俯视)
780
811
  var targetPosition = new THREE.Vector3(
781
812
  center.x,
782
- center.y + dist * 0.259,
783
- center.z + dist * 0.966
813
+ center.y + dist * 0.866,
814
+ center.z + dist * 0.5
784
815
  );
785
816
 
786
817
  this._animateCamera({
@@ -1652,15 +1683,15 @@ KimapSDK.prototype.destroy = function() {
1652
1683
  if (this.animationFrameId) {
1653
1684
  cancelAnimationFrame(this.animationFrameId);
1654
1685
  }
1655
-
1686
+
1656
1687
  if (this.resizeHandler) {
1657
1688
  window.removeEventListener('resize', this.resizeHandler);
1658
1689
  }
1659
-
1690
+
1660
1691
  if (this.clickHandler && this.core && this.core.renderer) {
1661
1692
  this.core.renderer.domElement.removeEventListener('click', this.clickHandler);
1662
1693
  }
1663
-
1694
+
1664
1695
  if (this.core) {
1665
1696
  this.core.destroy();
1666
1697
  }
@@ -133,12 +133,29 @@ SceneCore.prototype.setCameraPosition = function() {
133
133
  var origin = this.coordinateSystem.origin;
134
134
  var maxX = this.coordinateSystem.maxX;
135
135
  var maxY = this.coordinateSystem.maxY;
136
-
136
+
137
137
  var centerX = origin.x + maxX / 2;
138
138
  var centerZ = origin.z;
139
- var distance = Math.max(maxX, maxY) * 1.5;
140
-
141
- this.camera.position.set(centerX, distance, centerZ + distance * 0.5);
139
+ var maxSize = Math.max(maxX, maxY);
140
+
141
+ // 单模型默认相机参数:俯仰角47.52°,方位角-37.94°,基准距离11.49
142
+ var pitchDeg = 47.52;
143
+ var azimuthDeg = -37.94;
144
+ var baseDistance = 11.49;
145
+ var distance = maxSize > 0 ? (baseDistance / 10) * maxSize : baseDistance;
146
+
147
+ var pitchRad = pitchDeg * Math.PI / 180;
148
+ var azimuthRad = azimuthDeg * Math.PI / 180;
149
+ var cosPitch = Math.cos(pitchRad);
150
+ var sinPitch = Math.sin(pitchRad);
151
+ var cosAzimuth = Math.cos(azimuthRad);
152
+ var sinAzimuth = Math.sin(azimuthRad);
153
+
154
+ this.camera.position.set(
155
+ centerX + distance * sinAzimuth * cosPitch,
156
+ distance * sinPitch,
157
+ centerZ + distance * cosAzimuth * cosPitch
158
+ );
142
159
  this.camera.lookAt(centerX, 0, centerZ);
143
160
  };
144
161
 
@@ -488,9 +505,25 @@ SceneCore.prototype._adjustCameraToAllFloors = function() {
488
505
  box.getCenter(center);
489
506
  box.getSize(size);
490
507
  var maxSize = Math.max(size.x, size.z);
491
- var distance = maxSize * 2;
492
508
 
493
- this.camera.position.set(center.x, center.y + distance * 1.5, center.z + distance);
509
+ // ALL多模型相机参数:俯仰角61.19°,方位角-47.86°,基准距离12.21
510
+ var pitchDeg = 61.19;
511
+ var azimuthDeg = -47.86;
512
+ var baseDistance = 12.21;
513
+ var distance = maxSize > 0 ? (baseDistance / 10) * maxSize : baseDistance;
514
+
515
+ var pitchRad = pitchDeg * Math.PI / 180;
516
+ var azimuthRad = azimuthDeg * Math.PI / 180;
517
+ var cosPitch = Math.cos(pitchRad);
518
+ var sinPitch = Math.sin(pitchRad);
519
+ var cosAzimuth = Math.cos(azimuthRad);
520
+ var sinAzimuth = Math.sin(azimuthRad);
521
+
522
+ this.camera.position.set(
523
+ center.x + distance * sinAzimuth * cosPitch,
524
+ center.y + distance * sinPitch,
525
+ center.z + distance * cosAzimuth * cosPitch
526
+ );
494
527
  this.camera.lookAt(center);
495
528
  if (this.controls) {
496
529
  this.controls.target.copy(center);
@@ -527,10 +560,25 @@ SceneCore.prototype.adjustCameraToFloor = function(floorIndex) {
527
560
  box.getCenter(center);
528
561
  box.getSize(size);
529
562
  var maxSize = Math.max(size.x, size.z);
530
- var distance = maxSize * 1.5;
531
563
 
532
- // -60° 俯角(与 ALL -45° 区分,单楼层更俯视)
533
- this.camera.position.set(center.x, center.y - distance * 1.732, center.z + distance);
564
+ // 单模型相机参数:俯仰角47.52°,方位角-37.94°,基准距离11.49
565
+ var pitchDeg = 47.52;
566
+ var azimuthDeg = -37.94;
567
+ var baseDistance = 11.49;
568
+ var distance = maxSize > 0 ? (baseDistance / 10) * maxSize : baseDistance;
569
+
570
+ var pitchRad = pitchDeg * Math.PI / 180;
571
+ var azimuthRad = azimuthDeg * Math.PI / 180;
572
+ var cosPitch = Math.cos(pitchRad);
573
+ var sinPitch = Math.sin(pitchRad);
574
+ var cosAzimuth = Math.cos(azimuthRad);
575
+ var sinAzimuth = Math.sin(azimuthRad);
576
+
577
+ this.camera.position.set(
578
+ center.x + distance * sinAzimuth * cosPitch,
579
+ center.y + distance * sinPitch,
580
+ center.z + distance * cosAzimuth * cosPitch
581
+ );
534
582
  var lookAtTgt = new THREE.Vector3(center.x, center.y, center.z);
535
583
  this.camera.lookAt(lookAtTgt);
536
584
  if (this.controls) {
@@ -919,7 +967,7 @@ SceneCore.prototype._processMaterial = function(child, materials, colorMap) {
919
967
  */
920
968
  SceneCore.prototype._adjustCameraToModel = function() {
921
969
  var self = this;
922
-
970
+
923
971
  try {
924
972
  var finalBox = new THREE.Box3().setFromObject(self.mapModel);
925
973
  var finalCenter = new THREE.Vector3();
@@ -929,12 +977,23 @@ SceneCore.prototype._adjustCameraToModel = function() {
929
977
  finalBox.getSize(finalSize);
930
978
  var maxSize = Math.max(finalSize.x, finalSize.z);
931
979
 
932
- var distance = maxSize * 1.5;
980
+ // 单模型相机参数:俯仰角47.52°,方位角-37.94°,基准距离11.49
981
+ var pitchDeg = 47.52;
982
+ var azimuthDeg = -37.94;
983
+ var baseDistance = 11.49;
984
+ var distance = maxSize > 0 ? (baseDistance / 10) * maxSize : baseDistance;
985
+
986
+ var pitchRad = pitchDeg * Math.PI / 180;
987
+ var azimuthRad = azimuthDeg * Math.PI / 180;
988
+ var cosPitch = Math.cos(pitchRad);
989
+ var sinPitch = Math.sin(pitchRad);
990
+ var cosAzimuth = Math.cos(azimuthRad);
991
+ var sinAzimuth = Math.sin(azimuthRad);
933
992
 
934
993
  self.camera.position.set(
935
- finalCenter.x,
936
- finalCenter.y + distance,
937
- finalCenter.z + distance * 0.5
994
+ finalCenter.x + distance * sinAzimuth * cosPitch,
995
+ finalCenter.y + distance * sinPitch,
996
+ finalCenter.z + distance * cosAzimuth * cosPitch
938
997
  );
939
998
  self.camera.lookAt(finalCenter.x, finalCenter.y, finalCenter.z);
940
999