@kimap/indoor-positioning-sdk-vue2 3.4.2 → 3.4.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/index.js CHANGED
@@ -31,6 +31,9 @@ function KMCreateMap(config) {
31
31
  var utils = require('./src/utils/index.js');
32
32
  var modules = require('./src/modules/index.js');
33
33
 
34
+ // 导出 DOM 标记类
35
+ var KMDOMMarker = require('./src/KMDOMMarker.js');
36
+
34
37
  module.exports = {
35
38
  // Vue组件
36
39
  KimapComponent: KimapComponent,
@@ -41,6 +44,9 @@ module.exports = {
41
44
  // 直接导出SDK类(高级用法)
42
45
  KimapSDK: KimapSDK,
43
46
 
47
+ // DOM 标记类(面向对象风格)
48
+ KMDOMMarker: KMDOMMarker,
49
+
44
50
  // 工具类
45
51
  BuildingCoordSystem: utils.BuildingCoordSystem,
46
52
  CoordTransformer: utils.CoordTransformer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimap/indoor-positioning-sdk-vue2",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,240 @@
1
+ /**
2
+ * KMDOMMarker - 面向对象风格的 DOM 标记类
3
+ * 兼容 Vue2 + Webpack3 + Babel6
4
+ *
5
+ * 用法:
6
+ * var marker = new KMDOMMarker({
7
+ * id: 'marker-1',
8
+ * position: { x: 10, y: 0, z: 5 },
9
+ * domElement: document.createElement('div'),
10
+ * offset: { x: 0, y: -20 }
11
+ * }).addTo(sdk);
12
+ *
13
+ * // 平滑移动
14
+ * marker.animateTo({ x: 20, y: 0, z: 10 }, 1000);
15
+ *
16
+ * // 移除
17
+ * marker.remove();
18
+ */
19
+
20
+ function KMDOMMarker(config) {
21
+ if (!config) {
22
+ throw new Error('KMDOMMarker: config is required');
23
+ }
24
+
25
+ this.id = config.id || 'km-marker-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
26
+ this.domElement = config.domElement;
27
+ this.offset = config.offset || { x: 0, y: 0 };
28
+ this.sdk = null;
29
+ this._animationId = null;
30
+
31
+ // 存储位置(支持 THREE.Vector3 或普通对象)
32
+ var pos = config.position || { x: 0, y: 0, z: 0 };
33
+ this.position = {
34
+ x: pos.x || 0,
35
+ y: pos.y || 0,
36
+ z: pos.z || 0
37
+ };
38
+ }
39
+
40
+ /**
41
+ * 添加到 SDK
42
+ * @param {KimapSDK} sdk - SDK 实例
43
+ * @returns {KMDOMMarker} this
44
+ */
45
+ KMDOMMarker.prototype.addTo = function(sdk) {
46
+ if (!sdk) {
47
+ throw new Error('KMDOMMarker.addTo: sdk is required');
48
+ }
49
+
50
+ this.sdk = sdk;
51
+
52
+ // 调用 SDK 的 addCustomDOM 方法
53
+ sdk.addCustomDOM({
54
+ id: this.id,
55
+ position: this.position,
56
+ domElement: this.domElement,
57
+ offset: this.offset
58
+ });
59
+
60
+ return this;
61
+ };
62
+
63
+ /**
64
+ * 从 SDK 移除
65
+ * @returns {KMDOMMarker} this
66
+ */
67
+ KMDOMMarker.prototype.remove = function() {
68
+ // 取消正在进行的动画
69
+ if (this._animationId) {
70
+ cancelAnimationFrame(this._animationId);
71
+ this._animationId = null;
72
+ }
73
+
74
+ if (this.sdk) {
75
+ this.sdk.removeCustomDOM(this.id);
76
+ this.sdk = null;
77
+ }
78
+
79
+ return this;
80
+ };
81
+
82
+ /**
83
+ * 设置位置(立即更新)
84
+ * @param {Object} position - { x, y, z }
85
+ * @returns {KMDOMMarker} this
86
+ */
87
+ KMDOMMarker.prototype.setPosition = function(position) {
88
+ if (!position) return this;
89
+
90
+ this.position.x = position.x !== undefined ? position.x : this.position.x;
91
+ this.position.y = position.y !== undefined ? position.y : this.position.y;
92
+ this.position.z = position.z !== undefined ? position.z : this.position.z;
93
+
94
+ // 更新 SDK 中的位置
95
+ if (this.sdk && this.sdk.customDOMs && this.sdk.customDOMs[this.id]) {
96
+ var domData = this.sdk.customDOMs[this.id];
97
+ domData.position.x = this.position.x;
98
+ domData.position.y = this.position.y;
99
+ domData.position.z = this.position.z;
100
+ this.sdk.updateDOMPosition(this.id);
101
+ }
102
+
103
+ return this;
104
+ };
105
+
106
+ /**
107
+ * 平滑移动到目标位置
108
+ * @param {Object} targetPosition - { x, y, z }
109
+ * @param {number} duration - 动画时长(毫秒),默认 1000
110
+ * @returns {Promise} 动画完成后 resolve
111
+ */
112
+ KMDOMMarker.prototype.animateTo = function(targetPosition, duration) {
113
+ var self = this;
114
+ duration = duration || 1000;
115
+
116
+ return new Promise(function(resolve) {
117
+ // 取消之前的动画
118
+ if (self._animationId) {
119
+ cancelAnimationFrame(self._animationId);
120
+ self._animationId = null;
121
+ }
122
+
123
+ var startPosition = {
124
+ x: self.position.x,
125
+ y: self.position.y,
126
+ z: self.position.z
127
+ };
128
+
129
+ var targetPos = {
130
+ x: targetPosition.x !== undefined ? targetPosition.x : startPosition.x,
131
+ y: targetPosition.y !== undefined ? targetPosition.y : startPosition.y,
132
+ z: targetPosition.z !== undefined ? targetPosition.z : startPosition.z
133
+ };
134
+
135
+ var startTime = null;
136
+
137
+ function animate(currentTime) {
138
+ if (!startTime) startTime = currentTime;
139
+
140
+ var elapsed = currentTime - startTime;
141
+ var progress = Math.min(elapsed / duration, 1);
142
+
143
+ // 使用 easeInOutQuad 缓动函数
144
+ var eased = progress < 0.5
145
+ ? 2 * progress * progress
146
+ : 1 - Math.pow(-2 * progress + 2, 2) / 2;
147
+
148
+ // 计算当前位置
149
+ var currentPos = {
150
+ x: startPosition.x + (targetPos.x - startPosition.x) * eased,
151
+ y: startPosition.y + (targetPos.y - startPosition.y) * eased,
152
+ z: startPosition.z + (targetPos.z - startPosition.z) * eased
153
+ };
154
+
155
+ // 更新位置
156
+ self.setPosition(currentPos);
157
+
158
+ if (progress < 1) {
159
+ self._animationId = requestAnimationFrame(animate);
160
+ } else {
161
+ self._animationId = null;
162
+ resolve();
163
+ }
164
+ }
165
+
166
+ self._animationId = requestAnimationFrame(animate);
167
+ });
168
+ };
169
+
170
+ /**
171
+ * 设置偏移量
172
+ * @param {Object} offset - { x, y }
173
+ * @returns {KMDOMMarker} this
174
+ */
175
+ KMDOMMarker.prototype.setOffset = function(offset) {
176
+ if (!offset) return this;
177
+
178
+ this.offset.x = offset.x !== undefined ? offset.x : this.offset.x;
179
+ this.offset.y = offset.y !== undefined ? offset.y : this.offset.y;
180
+
181
+ // 更新 SDK 中的偏移量
182
+ if (this.sdk && this.sdk.customDOMs && this.sdk.customDOMs[this.id]) {
183
+ this.sdk.customDOMs[this.id].offset = this.offset;
184
+ this.sdk.updateDOMPosition(this.id);
185
+ }
186
+
187
+ return this;
188
+ };
189
+
190
+ /**
191
+ * 显示标记
192
+ * @returns {KMDOMMarker} this
193
+ */
194
+ KMDOMMarker.prototype.show = function() {
195
+ if (this.domElement) {
196
+ this.domElement.style.display = '';
197
+ }
198
+ return this;
199
+ };
200
+
201
+ /**
202
+ * 隐藏标记
203
+ * @returns {KMDOMMarker} this
204
+ */
205
+ KMDOMMarker.prototype.hide = function() {
206
+ if (this.domElement) {
207
+ this.domElement.style.display = 'none';
208
+ }
209
+ return this;
210
+ };
211
+
212
+ /**
213
+ * 获取当前位置
214
+ * @returns {Object} { x, y, z }
215
+ */
216
+ KMDOMMarker.prototype.getPosition = function() {
217
+ return {
218
+ x: this.position.x,
219
+ y: this.position.y,
220
+ z: this.position.z
221
+ };
222
+ };
223
+
224
+ /**
225
+ * 获取 DOM 元素
226
+ * @returns {HTMLElement}
227
+ */
228
+ KMDOMMarker.prototype.getDOMElement = function() {
229
+ return this.domElement;
230
+ };
231
+
232
+ /**
233
+ * 检查是否已添加到 SDK
234
+ * @returns {boolean}
235
+ */
236
+ KMDOMMarker.prototype.isAdded = function() {
237
+ return this.sdk !== null;
238
+ };
239
+
240
+ module.exports = KMDOMMarker;
@@ -691,13 +691,12 @@
691
691
  };
692
692
 
693
693
  // 定位策略:
694
- // 1. XZ平面:将模型中心对齐到origin的XZ位置
695
- // 2. Y方向:将模型底部(box.min.y)对齐到origin.y(通常是地面)
694
+ // 将模型左上角(min.x, min.z)对齐到原点,使(0,0)在左上角
696
695
  var origin = this.coordinateSystem.origin;
697
696
  this.mapModel.position.set(
698
- origin.x - center.x, // X方向居中
697
+ origin.x - box.min.x, // X方向:左边界对齐
699
698
  origin.y - box.min.y, // Y方向:底部对齐地面
700
- origin.z - center.z // Z方向居中
699
+ origin.z - box.min.z // Z方向:上边界对齐
701
700
  );
702
701
 
703
702
  console.log('📦 模型包围盒:');
package/src/KimapCore.js CHANGED
@@ -555,13 +555,14 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
555
555
  box.getCenter(center);
556
556
 
557
557
  var origin = self.coordinateSystem.origin;
558
+ // 将模型左上角(min.x, min.z)对齐到原点,而不是居中
558
559
  self.mapModel.position.set(
559
- origin.x - center.x, // X方向居中
560
+ origin.x - box.min.x, // X方向:左边界对齐
560
561
  origin.y - box.min.y, // Y方向:底部对齐地面
561
- origin.z - center.z // Z方向居中
562
+ origin.z - box.min.z // Z方向:上边界对齐
562
563
  );
563
564
 
564
- console.log('✅ 模型已居中对齐到原点');
565
+ console.log('✅ 模型左上角已对齐到原点');
565
566
 
566
567
  // 统计模型信息
567
568
  var meshCount = 0;
@@ -735,10 +736,11 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
735
736
  box.getCenter(center);
736
737
 
737
738
  var origin = self.coordinateSystem.origin;
739
+ // 将模型左上角(min.x, min.z)对齐到原点,而不是居中
738
740
  self.mapModel.position.set(
739
- origin.x - center.x, // X方向居中
741
+ origin.x - box.min.x, // X方向:左边界对齐
740
742
  origin.y - box.min.y, // Y方向:底部对齐地面
741
- origin.z - center.z // Z方向居中
743
+ origin.z - box.min.z // Z方向:上边界对齐
742
744
  );
743
745
 
744
746
  console.log('✅ 模型已居中对齐到原点');