@kimap/indoor-positioning-sdk-vue2 4.1.4 → 4.1.6

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": "4.1.4",
3
+ "version": "4.1.6",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -521,6 +521,138 @@ KimapSDK.prototype.getCoordinateSystem = function() {
521
521
  return this.core ? this.core.coordinateSystem : null;
522
522
  };
523
523
 
524
+ KimapSDK.prototype.getConfig = function() {
525
+ var config = {};
526
+
527
+ // 从coordinateSystem获取scale
528
+ if (this.core && this.core.coordinateSystem) {
529
+ var coordSys = this.core.coordinateSystem;
530
+ if (coordSys.scale) {
531
+ config.scale = coordSys.scale;
532
+ }
533
+ // 添加坐标系统信息
534
+ config.maxX = coordSys.maxX;
535
+ config.maxY = coordSys.maxY;
536
+ config.maxZ = coordSys.maxZ;
537
+ }
538
+
539
+ // 模型尺寸(从边界信息获取,单位:米)
540
+ if (this._borderInfo) {
541
+ var border = this._borderInfo;
542
+ config.mapX = border.max.x - border.min.x;
543
+ config.mapY = border.max.y - border.min.y;
544
+ config.mapZ = border.max.z - border.min.z;
545
+ }
546
+
547
+ // 如果有校准数据,返回底图真实世界尺寸(单位:米)
548
+ if (this._mapConfig && this._mapConfig.isCalibrated) {
549
+ config.isCalibrated = true;
550
+ config.baseMapWidth = this._mapConfig.realWidth / 100; // 底图真实宽度(米)
551
+ config.baseMapHeight = this._mapConfig.realHeight / 100; // 底图真实高度(米)
552
+ config.modelToRealScale = this._mapConfig.modelToRealScale;
553
+ // 添加完整的mapConfig数据
554
+ config.realWidth = this._mapConfig.realWidth;
555
+ config.realHeight = this._mapConfig.realHeight;
556
+ }
557
+
558
+ return config;
559
+ };
560
+
561
+ KimapSDK.prototype.loadKMData = function() {
562
+ var self = this;
563
+
564
+ if (!this.dataUrl) {
565
+ console.warn('⚠️ 未配置dataUrl,无法加载3D家具模型');
566
+ return Promise.resolve({ success: false, message: '未配置dataUrl' });
567
+ }
568
+
569
+ if (!this.config.objUrl) {
570
+ console.warn('⚠️ 未配置objUrl,无法确定kidata文件名');
571
+ return Promise.resolve({ success: false, message: '未配置objUrl' });
572
+ }
573
+
574
+ // 从objUrl提取文件名和目录
575
+ var objUrl = this.config.objUrl;
576
+ var lastSlashIndex = objUrl.lastIndexOf('/');
577
+ var directory = lastSlashIndex >= 0 ? objUrl.substring(0, lastSlashIndex) : '';
578
+ var fileName = objUrl.split('/').pop().replace(/\.(obj|kimap)$/i, '');
579
+ var kidataUrl = directory + '/' + fileName + '.kidata';
580
+
581
+ console.log('📦 开始加载3D家具模型数据:', kidataUrl);
582
+
583
+ return fetch(kidataUrl)
584
+ .then(function(response) {
585
+ if (!response.ok) {
586
+ throw new Error('Kidata文件加载失败: ' + response.status);
587
+ }
588
+ return response.text();
589
+ })
590
+ .then(function(encryptedData) {
591
+ // 解密kidata文件
592
+ var decrypted = self._decryptKidata(encryptedData);
593
+ var kidataObj = JSON.parse(decrypted);
594
+
595
+ // 保存kidata数据供路径规划使用
596
+ self.kidataContent = kidataObj;
597
+
598
+ console.log('✅ Kidata文件解密成功:', {
599
+ version: kidataObj.version,
600
+ serverUrl: kidataObj.serverUrl,
601
+ furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0
602
+ });
603
+
604
+ // 加载3D家具模型
605
+ return self._loadFurnitureModels(kidataObj);
606
+ })
607
+ .then(function(result) {
608
+ console.log('✅ 3D家具模型加载完成:', result);
609
+ return { success: true, loaded: result.loaded, failed: result.failed };
610
+ })
611
+ .catch(function(error) {
612
+ console.error('❌ 加载3D家具模型失败:', error);
613
+ return { success: false, error: error.message };
614
+ });
615
+ };
616
+
617
+ KimapSDK.prototype._decryptKidata = function(encrypted) {
618
+ try {
619
+ // 1. Base64解码
620
+ var decoded = atob(encrypted);
621
+
622
+ // 2. 反混淆(XOR with 0x5A)
623
+ var key = 0x5A;
624
+ var decrypted = '';
625
+ for (var i = 0; i < decoded.length; i++) {
626
+ decrypted += String.fromCharCode(decoded.charCodeAt(i) ^ key);
627
+ }
628
+
629
+ // 3. Base64解码
630
+ return decodeURIComponent(escape(atob(decrypted)));
631
+ } catch (error) {
632
+ throw new Error('Kidata解密失败: ' + error.message);
633
+ }
634
+ };
635
+
636
+ KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
637
+ var self = this;
638
+
639
+ if (!kidataObj.furnitures || kidataObj.furnitures.length === 0) {
640
+ return Promise.resolve({ loaded: 0, failed: 0 });
641
+ }
642
+
643
+ // 创建家具组(如果不存在)
644
+ if (!this.furnitureGroup) {
645
+ this.furnitureGroup = new THREE.Group();
646
+ this.furnitureGroup.name = 'furnitures';
647
+ this.core.scene.add(this.furnitureGroup);
648
+ }
649
+
650
+ console.log('📦 开始加载', kidataObj.furnitures.length, '个家具模型');
651
+
652
+ // 简化版本:暂时返回成功,实际加载逻辑可以后续完善
653
+ return Promise.resolve({ loaded: 0, failed: 0, message: '家具加载功能需要完整实现' });
654
+ };
655
+
524
656
  /**
525
657
  * 销毁 SDK
526
658
  */
@@ -41,10 +41,20 @@ function SceneCore(config) {
41
41
  this.mapModel = null;
42
42
 
43
43
  // 需要先加载 THREE 才能使用 THREE.Vector3
44
+ var mapWidth = config.maxX || 100;
45
+ var mapHeight = config.maxY || 50;
46
+ var mapDepth = config.maxZ || 10;
47
+
44
48
  this.coordinateSystem = {
45
49
  origin: config.origin || { x: 0, y: 0, z: 0 },
46
- maxX: config.maxX,
47
- maxY: config.maxY
50
+ maxX: mapWidth,
51
+ maxY: mapHeight,
52
+ maxZ: mapDepth,
53
+ scale: {
54
+ x: mapWidth,
55
+ y: mapDepth,
56
+ z: mapHeight
57
+ }
48
58
  };
49
59
  }
50
60