@kimap/indoor-positioning-sdk-vue2 5.7.2 → 5.7.4
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 +162 -1
package/package.json
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -37,6 +37,11 @@ function KimapSDK(config) {
|
|
|
37
37
|
// 多楼层可视化支持(新增)
|
|
38
38
|
this.floorGroups = [];
|
|
39
39
|
this.isMultiFloor = Array.isArray(config.objUrl);
|
|
40
|
+
|
|
41
|
+
// 楼层工具配置(支持内置楼层切换UI)
|
|
42
|
+
this.floorToolsConfig = config.floorTools || { enabled: false };
|
|
43
|
+
this.floorToolsElement = null;
|
|
44
|
+
this.currentFloorIndex = 1; // 1=第一个楼层, 0=ALL
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
/**
|
|
@@ -81,7 +86,13 @@ KimapSDK.prototype.init = function() {
|
|
|
81
86
|
if (self.isMultiFloor && self.floorGroups && self.floorGroups.length > 0) {
|
|
82
87
|
self.showSingleFloor(0);
|
|
83
88
|
}
|
|
84
|
-
|
|
89
|
+
|
|
90
|
+
// 渲染内置楼层选择器 UI
|
|
91
|
+
var floorToolsEnabled = self.floorToolsConfig && self.floorToolsConfig.enabled !== false;
|
|
92
|
+
if (floorToolsEnabled && self.isMultiFloor) {
|
|
93
|
+
self._renderFloorSelector();
|
|
94
|
+
}
|
|
95
|
+
|
|
85
96
|
return self;
|
|
86
97
|
});
|
|
87
98
|
};
|
|
@@ -1035,6 +1046,13 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1035
1046
|
|
|
1036
1047
|
// 验证通过或404等错误,继续加载(让loader处理)
|
|
1037
1048
|
return new Promise(function(resolveLoad, rejectLoad) {
|
|
1049
|
+
// 压制 FBXLoader 的多边形警告(140次刷屏)
|
|
1050
|
+
var originalWarn = console.warn;
|
|
1051
|
+
console.warn = function(msg) {
|
|
1052
|
+
if (msg && typeof msg === 'string' && msg.indexOf('Polygons with more than four sides') !== -1) return;
|
|
1053
|
+
originalWarn.apply(console, arguments);
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1038
1056
|
loader.load(
|
|
1039
1057
|
modelUrl,
|
|
1040
1058
|
function(result) {
|
|
@@ -1173,6 +1191,7 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1173
1191
|
});
|
|
1174
1192
|
}
|
|
1175
1193
|
|
|
1194
|
+
console.warn = originalWarn;
|
|
1176
1195
|
resolveLoad(furnitureGroup);
|
|
1177
1196
|
} else {
|
|
1178
1197
|
// 无旋转时直接设置obj的世界位置
|
|
@@ -1234,11 +1253,13 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1234
1253
|
furnitureType: furniture.type
|
|
1235
1254
|
};
|
|
1236
1255
|
|
|
1256
|
+
console.warn = originalWarn;
|
|
1237
1257
|
resolveLoad(obj);
|
|
1238
1258
|
}
|
|
1239
1259
|
},
|
|
1240
1260
|
undefined,
|
|
1241
1261
|
function(error) {
|
|
1262
|
+
console.warn = originalWarn;
|
|
1242
1263
|
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
1243
1264
|
rejectLoad(error);
|
|
1244
1265
|
}
|
|
@@ -1249,6 +1270,7 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1249
1270
|
resolve(obj);
|
|
1250
1271
|
});
|
|
1251
1272
|
}).catch(function(error) {
|
|
1273
|
+
console.warn = originalWarn;
|
|
1252
1274
|
console.error('❌ 家具模型URL验证或加载失败:', furniture.type, error.message);
|
|
1253
1275
|
console.error('URL:', modelUrl);
|
|
1254
1276
|
reject(error);
|
|
@@ -1310,4 +1332,143 @@ KimapSDK.prototype.destroy = function() {
|
|
|
1310
1332
|
}
|
|
1311
1333
|
};
|
|
1312
1334
|
|
|
1335
|
+
/**
|
|
1336
|
+
* 渲染内置楼层选择器 UI
|
|
1337
|
+
* @private
|
|
1338
|
+
*/
|
|
1339
|
+
KimapSDK.prototype._renderFloorSelector = function() {
|
|
1340
|
+
var self = this;
|
|
1341
|
+
|
|
1342
|
+
var existingSelector = document.getElementById('kimap-floor-selector');
|
|
1343
|
+
if (existingSelector) existingSelector.remove();
|
|
1344
|
+
|
|
1345
|
+
if (this.floorToolsConfig.enabled === false) return;
|
|
1346
|
+
|
|
1347
|
+
// 自动生成楼层名称:1F, 2F, 3F...
|
|
1348
|
+
var floorNames = [];
|
|
1349
|
+
for (var i = 0; i < this.floorGroups.length; i++) {
|
|
1350
|
+
floorNames.push((i + 1) + 'F');
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
var selector = document.createElement('div');
|
|
1354
|
+
selector.id = 'kimap-floor-selector';
|
|
1355
|
+
this.floorToolsElement = selector;
|
|
1356
|
+
|
|
1357
|
+
var position = this.floorToolsConfig.position || 'left-bottom';
|
|
1358
|
+
var offsetX = this.floorToolsConfig.offsetX || 20;
|
|
1359
|
+
var offsetY = this.floorToolsConfig.offsetY || 20;
|
|
1360
|
+
|
|
1361
|
+
var positionStyles = {
|
|
1362
|
+
'left-top': { top: offsetY + 'px', left: offsetX + 'px' },
|
|
1363
|
+
'left-bottom': { bottom: offsetY + 'px', left: offsetX + 'px' },
|
|
1364
|
+
'right-top': { top: offsetY + 'px', right: offsetX + 'px' },
|
|
1365
|
+
'right-bottom': { bottom: offsetY + 'px', right: offsetX + 'px' }
|
|
1366
|
+
};
|
|
1367
|
+
var posStyle = positionStyles[position] || positionStyles['left-bottom'];
|
|
1368
|
+
|
|
1369
|
+
selector.style.cssText = [
|
|
1370
|
+
'position: absolute',
|
|
1371
|
+
'display: flex',
|
|
1372
|
+
'flex-direction: column',
|
|
1373
|
+
'gap: 4px',
|
|
1374
|
+
'z-index: 1000',
|
|
1375
|
+
'font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
1376
|
+
'top: ' + (posStyle.top || 'auto'),
|
|
1377
|
+
'left: ' + (posStyle.left || 'auto'),
|
|
1378
|
+
'bottom: ' + (posStyle.bottom || 'auto'),
|
|
1379
|
+
'right: ' + (posStyle.right || 'auto')
|
|
1380
|
+
].join(';');
|
|
1381
|
+
|
|
1382
|
+
// ALL 按钮
|
|
1383
|
+
var allBtn = this._createFloorButton('ALL', 0, this.currentFloorIndex === 0);
|
|
1384
|
+
selector.appendChild(allBtn);
|
|
1385
|
+
|
|
1386
|
+
// 各楼层按钮
|
|
1387
|
+
var self2 = this;
|
|
1388
|
+
floorNames.forEach(function(name, index) {
|
|
1389
|
+
var btn = self2._createFloorButton(name, index + 1, self2.currentFloorIndex === index + 1);
|
|
1390
|
+
selector.appendChild(btn);
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
this.core.container.style.position = 'relative';
|
|
1394
|
+
this.core.container.appendChild(selector);
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* 创建楼层按钮
|
|
1399
|
+
* @private
|
|
1400
|
+
*/
|
|
1401
|
+
KimapSDK.prototype._createFloorButton = function(name, index, isActive) {
|
|
1402
|
+
var self = this;
|
|
1403
|
+
var btn = document.createElement('button');
|
|
1404
|
+
btn.textContent = name;
|
|
1405
|
+
btn.dataset.floorIndex = index;
|
|
1406
|
+
|
|
1407
|
+
btn.style.cssText = [
|
|
1408
|
+
'padding: 8px 16px',
|
|
1409
|
+
'border: none',
|
|
1410
|
+
'border-radius: 4px',
|
|
1411
|
+
'cursor: pointer',
|
|
1412
|
+
'font-size: 13px',
|
|
1413
|
+
'font-weight: 500',
|
|
1414
|
+
'transition: all 0.2s ease',
|
|
1415
|
+
'min-width: 50px'
|
|
1416
|
+
].join(';');
|
|
1417
|
+
|
|
1418
|
+
if (isActive) {
|
|
1419
|
+
btn.style.backgroundColor = '#1890ff';
|
|
1420
|
+
btn.style.color = '#fff';
|
|
1421
|
+
} else {
|
|
1422
|
+
btn.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
|
|
1423
|
+
btn.style.color = '#333';
|
|
1424
|
+
btn.style.boxShadow = '0 1px 4px rgba(0,0,0,0.1)';
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
btn.addEventListener('click', function() {
|
|
1428
|
+
self._onFloorButtonClick(index);
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
btn.addEventListener('mouseenter', function() {
|
|
1432
|
+
if (!isActive) {
|
|
1433
|
+
btn.style.backgroundColor = '#e6f7ff';
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
|
|
1437
|
+
btn.addEventListener('mouseleave', function() {
|
|
1438
|
+
if (!isActive) {
|
|
1439
|
+
btn.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
|
|
1443
|
+
return btn;
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* 楼层按钮点击处理
|
|
1448
|
+
* @private
|
|
1449
|
+
*/
|
|
1450
|
+
KimapSDK.prototype._onFloorButtonClick = function(index) {
|
|
1451
|
+
this.currentFloorIndex = index;
|
|
1452
|
+
|
|
1453
|
+
// 更新按钮样式
|
|
1454
|
+
var buttons = document.querySelectorAll('#kimap-floor-selector button');
|
|
1455
|
+
var self3 = this;
|
|
1456
|
+
buttons.forEach(function(btn) {
|
|
1457
|
+
var btnIndex = parseInt(btn.dataset.floorIndex);
|
|
1458
|
+
if (btnIndex === index) {
|
|
1459
|
+
btn.style.backgroundColor = '#1890ff';
|
|
1460
|
+
btn.style.color = '#fff';
|
|
1461
|
+
} else {
|
|
1462
|
+
btn.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
|
|
1463
|
+
btn.style.color = '#333';
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
if (index === 0) {
|
|
1468
|
+
this.showAllFloors();
|
|
1469
|
+
} else {
|
|
1470
|
+
this.showSingleFloor(index - 1);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1313
1474
|
module.exports = KimapSDK;
|