@kimap/indoor-positioning-sdk-vue2 4.1.3 → 4.1.5
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 +1 -1
- package/src/core/KimapSDK.js +121 -0
package/package.json
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -517,6 +517,127 @@ KimapSDK.prototype.getControls = function() {
|
|
|
517
517
|
return this.core ? this.core.controls : null;
|
|
518
518
|
};
|
|
519
519
|
|
|
520
|
+
KimapSDK.prototype.getCoordinateSystem = function() {
|
|
521
|
+
return this.core ? this.core.coordinateSystem : null;
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
KimapSDK.prototype.getConfig = function() {
|
|
525
|
+
var config = {};
|
|
526
|
+
|
|
527
|
+
// 模型尺寸(从边界信息获取,单位:米)
|
|
528
|
+
if (this._borderInfo) {
|
|
529
|
+
var border = this._borderInfo;
|
|
530
|
+
config.mapX = border.max.x - border.min.x;
|
|
531
|
+
config.mapY = border.max.y - border.min.y;
|
|
532
|
+
config.mapZ = border.max.z - border.min.z;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// 如果有校准数据,返回底图真实世界尺寸(单位:米)
|
|
536
|
+
if (this._mapConfig && this._mapConfig.isCalibrated) {
|
|
537
|
+
config.isCalibrated = true;
|
|
538
|
+
config.baseMapWidth = this._mapConfig.realWidth / 100; // 底图真实宽度(米)
|
|
539
|
+
config.baseMapHeight = this._mapConfig.realHeight / 100; // 底图真实高度(米)
|
|
540
|
+
config.modelToRealScale = this._mapConfig.modelToRealScale;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return config;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
KimapSDK.prototype.loadKMData = function() {
|
|
547
|
+
var self = this;
|
|
548
|
+
|
|
549
|
+
if (!this.dataUrl) {
|
|
550
|
+
console.warn('⚠️ 未配置dataUrl,无法加载3D家具模型');
|
|
551
|
+
return Promise.resolve({ success: false, message: '未配置dataUrl' });
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (!this.config.objUrl) {
|
|
555
|
+
console.warn('⚠️ 未配置objUrl,无法确定kidata文件名');
|
|
556
|
+
return Promise.resolve({ success: false, message: '未配置objUrl' });
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// 从objUrl提取文件名和目录
|
|
560
|
+
var objUrl = this.config.objUrl;
|
|
561
|
+
var lastSlashIndex = objUrl.lastIndexOf('/');
|
|
562
|
+
var directory = lastSlashIndex >= 0 ? objUrl.substring(0, lastSlashIndex) : '';
|
|
563
|
+
var fileName = objUrl.split('/').pop().replace(/\.(obj|kimap)$/i, '');
|
|
564
|
+
var kidataUrl = directory + '/' + fileName + '.kidata';
|
|
565
|
+
|
|
566
|
+
console.log('📦 开始加载3D家具模型数据:', kidataUrl);
|
|
567
|
+
|
|
568
|
+
return fetch(kidataUrl)
|
|
569
|
+
.then(function(response) {
|
|
570
|
+
if (!response.ok) {
|
|
571
|
+
throw new Error('Kidata文件加载失败: ' + response.status);
|
|
572
|
+
}
|
|
573
|
+
return response.text();
|
|
574
|
+
})
|
|
575
|
+
.then(function(encryptedData) {
|
|
576
|
+
// 解密kidata文件
|
|
577
|
+
var decrypted = self._decryptKidata(encryptedData);
|
|
578
|
+
var kidataObj = JSON.parse(decrypted);
|
|
579
|
+
|
|
580
|
+
// 保存kidata数据供路径规划使用
|
|
581
|
+
self.kidataContent = kidataObj;
|
|
582
|
+
|
|
583
|
+
console.log('✅ Kidata文件解密成功:', {
|
|
584
|
+
version: kidataObj.version,
|
|
585
|
+
serverUrl: kidataObj.serverUrl,
|
|
586
|
+
furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// 加载3D家具模型
|
|
590
|
+
return self._loadFurnitureModels(kidataObj);
|
|
591
|
+
})
|
|
592
|
+
.then(function(result) {
|
|
593
|
+
console.log('✅ 3D家具模型加载完成:', result);
|
|
594
|
+
return { success: true, loaded: result.loaded, failed: result.failed };
|
|
595
|
+
})
|
|
596
|
+
.catch(function(error) {
|
|
597
|
+
console.error('❌ 加载3D家具模型失败:', error);
|
|
598
|
+
return { success: false, error: error.message };
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
KimapSDK.prototype._decryptKidata = function(encrypted) {
|
|
603
|
+
try {
|
|
604
|
+
// 1. Base64解码
|
|
605
|
+
var decoded = atob(encrypted);
|
|
606
|
+
|
|
607
|
+
// 2. 反混淆(XOR with 0x5A)
|
|
608
|
+
var key = 0x5A;
|
|
609
|
+
var decrypted = '';
|
|
610
|
+
for (var i = 0; i < decoded.length; i++) {
|
|
611
|
+
decrypted += String.fromCharCode(decoded.charCodeAt(i) ^ key);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// 3. Base64解码
|
|
615
|
+
return decodeURIComponent(escape(atob(decrypted)));
|
|
616
|
+
} catch (error) {
|
|
617
|
+
throw new Error('Kidata解密失败: ' + error.message);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
|
|
622
|
+
var self = this;
|
|
623
|
+
|
|
624
|
+
if (!kidataObj.furnitures || kidataObj.furnitures.length === 0) {
|
|
625
|
+
return Promise.resolve({ loaded: 0, failed: 0 });
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// 创建家具组(如果不存在)
|
|
629
|
+
if (!this.furnitureGroup) {
|
|
630
|
+
this.furnitureGroup = new THREE.Group();
|
|
631
|
+
this.furnitureGroup.name = 'furnitures';
|
|
632
|
+
this.core.scene.add(this.furnitureGroup);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
console.log('📦 开始加载', kidataObj.furnitures.length, '个家具模型');
|
|
636
|
+
|
|
637
|
+
// 简化版本:暂时返回成功,实际加载逻辑可以后续完善
|
|
638
|
+
return Promise.resolve({ loaded: 0, failed: 0, message: '家具加载功能需要完整实现' });
|
|
639
|
+
};
|
|
640
|
+
|
|
520
641
|
/**
|
|
521
642
|
* 销毁 SDK
|
|
522
643
|
*/
|