@kimap/indoor-positioning-sdk-vue2 3.7.4 → 3.8.1

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/EXAMPLE.vue CHANGED
@@ -1,234 +1,234 @@
1
- <template>
2
- <div class="map-page">
3
- <!-- 控制面板 -->
4
- <div class="control-panel">
5
- <h3>地图控制</h3>
6
- <button @click="addMarker">添加标记</button>
7
- <button @click="removeMarker">移除标记</button>
8
- <button @click="updatePosition">更新位置</button>
9
- <button @click="showInfo">显示弹窗</button>
10
- <button @click="hideInfo">隐藏弹窗</button>
11
- <button @click="startDrawLine">绘制线段</button>
12
- <button @click="stopDraw">停止绘制</button>
13
- </div>
14
-
15
- <!-- 地图容器 -->
16
- <kimap-component
17
- ref="kimap"
18
- :obj-url="modelUrl"
19
- :origin="mapOrigin"
20
- :max-x="100"
21
- :max-y="50"
22
- :show-grid="true"
23
- :show-axes="true"
24
- @ready="onMapReady"
25
- @position-click="onPositionClick"
26
- @error="onMapError"
27
- />
28
-
29
- <!-- 信息显示 -->
30
- <div class="info-panel" v-if="clickedPosition">
31
- <p>点击位置: X={{ clickedPosition.x }}, Z={{ clickedPosition.z }}</p>
32
- </div>
33
- </div>
34
- </template>
35
-
36
- <script>
37
- // 导入Vue2兼容组件
38
- var KimapComponent = require('./KimapComponent.vue').default || require('./KimapComponent.vue');
39
-
40
- // 使用CommonJS导入Three.js(兼容旧版项目)
41
- var THREE = require('three');
42
-
43
- module.exports = {
44
- name: 'KimapExample',
45
- components: {
46
- KimapComponent: KimapComponent
47
- },
48
- data: function() {
49
- return {
50
- modelUrl: '/static/models/building.obj', // 模型文件路径
51
- mapOrigin: { x: 0, y: 0, z: 0 },
52
- clickedPosition: null,
53
- markerCount: 0,
54
- isMapReady: false
55
- };
56
- },
57
- methods: {
58
- // 地图加载完成
59
- onMapReady: function(sdk) {
60
- console.log('地图初始化完成', sdk);
61
- this.isMapReady = true;
62
- this.$message && this.$message.success('地图加载成功');
63
- },
64
-
65
- // 地图加载失败
66
- onMapError: function(error) {
67
- console.error('地图加载失败:', error);
68
- this.$message && this.$message.error('地图加载失败');
69
- },
70
-
71
- // 点击位置回调
72
- onPositionClick: function(data) {
73
- console.log('点击位置:', data.position);
74
- this.clickedPosition = data.position;
75
- },
76
-
77
- // 添加标记
78
- addMarker: function() {
79
- if (!this.isMapReady) {
80
- alert('地图未就绪');
81
- return;
82
- }
83
-
84
- this.markerCount++;
85
- var id = 'marker-' + this.markerCount;
86
-
87
- // 随机位置
88
- var x = Math.random() * 80 + 10;
89
- var z = Math.random() * 40 + 10;
90
-
91
- this.$refs.kimap.addLocationMarker({
92
- id: id,
93
- position: new THREE.Vector3(x, 0, z),
94
- label: '标记 ' + this.markerCount,
95
- color: this.getRandomColor()
96
- });
97
-
98
- console.log('添加标记:', id);
99
- },
100
-
101
- // 移除标记
102
- removeMarker: function() {
103
- if (this.markerCount > 0) {
104
- var id = 'marker-' + this.markerCount;
105
- this.$refs.kimap.removeLocationMarker(id);
106
- this.markerCount--;
107
- console.log('移除标记:', id);
108
- }
109
- },
110
-
111
- // 更新当前位置
112
- updatePosition: function() {
113
- if (!this.isMapReady) {
114
- alert('地图未就绪');
115
- return;
116
- }
117
-
118
- var x = Math.random() * 80 + 10;
119
- var z = Math.random() * 40 + 10;
120
- var position = new THREE.Vector3(x, 0, z);
121
-
122
- this.$refs.kimap.updateCurrentPosition(position);
123
- console.log('更新位置:', position);
124
- },
125
-
126
- // 显示弹窗
127
- showInfo: function() {
128
- if (!this.isMapReady) {
129
- alert('地图未就绪');
130
- return;
131
- }
132
-
133
- this.$refs.kimap.showPopup({
134
- title: '信息提示',
135
- content: '这是一个示例弹窗',
136
- position: new THREE.Vector3(50, 0, 25)
137
- });
138
- },
139
-
140
- // 隐藏弹窗
141
- hideInfo: function() {
142
- this.$refs.kimap.hidePopup();
143
- },
144
-
145
- // 开始绘制
146
- startDrawLine: function() {
147
- var self = this;
148
-
149
- this.$refs.kimap.startDraw('line', {
150
- onDrawClick: function(position) {
151
- console.log('添加点:', position);
152
- },
153
- onDrawComplete: function(points) {
154
- console.log('绘制完成,共 ' + points.length + ' 个点');
155
- alert('线段绘制完成!共 ' + points.length + ' 个点');
156
- }
157
- });
158
- },
159
-
160
- // 停止绘制
161
- stopDraw: function() {
162
- this.$refs.kimap.endDraw();
163
- },
164
-
165
- // 获取随机颜色
166
- getRandomColor: function() {
167
- var colors = ['#4CAF50', '#2196F3', '#FF9800', '#E91E63', '#9C27B0'];
168
- return colors[Math.floor(Math.random() * colors.length)];
169
- }
170
- },
171
-
172
- // 组件销毁时清理
173
- beforeDestroy: function() {
174
- console.log('组件即将销毁');
175
- }
176
- };
177
- </script>
178
-
179
- <style scoped>
180
- .map-page {
181
- width: 100%;
182
- height: 100vh;
183
- position: relative;
184
- display: flex;
185
- }
186
-
187
- .control-panel {
188
- position: absolute;
189
- top: 20px;
190
- left: 20px;
191
- background: white;
192
- padding: 20px;
193
- border-radius: 8px;
194
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
195
- z-index: 100;
196
- }
197
-
198
- .control-panel h3 {
199
- margin: 0 0 15px 0;
200
- font-size: 16px;
201
- }
202
-
203
- .control-panel button {
204
- display: block;
205
- width: 120px;
206
- margin-bottom: 10px;
207
- padding: 8px 12px;
208
- background: #2196F3;
209
- color: white;
210
- border: none;
211
- border-radius: 4px;
212
- cursor: pointer;
213
- }
214
-
215
- .control-panel button:hover {
216
- background: #1976D2;
217
- }
218
-
219
- .info-panel {
220
- position: absolute;
221
- bottom: 20px;
222
- left: 20px;
223
- background: white;
224
- padding: 15px;
225
- border-radius: 8px;
226
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
227
- z-index: 100;
228
- }
229
-
230
- .info-panel p {
231
- margin: 0;
232
- font-size: 14px;
233
- }
234
- </style>
1
+ <template>
2
+ <div class="map-page">
3
+ <!-- 控制面板 -->
4
+ <div class="control-panel">
5
+ <h3>地图控制</h3>
6
+ <button @click="addMarker">添加标记</button>
7
+ <button @click="removeMarker">移除标记</button>
8
+ <button @click="updatePosition">更新位置</button>
9
+ <button @click="showInfo">显示弹窗</button>
10
+ <button @click="hideInfo">隐藏弹窗</button>
11
+ <button @click="startDrawLine">绘制线段</button>
12
+ <button @click="stopDraw">停止绘制</button>
13
+ </div>
14
+
15
+ <!-- 地图容器 -->
16
+ <kimap-component
17
+ ref="kimap"
18
+ :obj-url="modelUrl"
19
+ :origin="mapOrigin"
20
+ :max-x="100"
21
+ :max-y="50"
22
+ :show-grid="true"
23
+ :show-axes="true"
24
+ @ready="onMapReady"
25
+ @position-click="onPositionClick"
26
+ @error="onMapError"
27
+ />
28
+
29
+ <!-- 信息显示 -->
30
+ <div class="info-panel" v-if="clickedPosition">
31
+ <p>点击位置: X={{ clickedPosition.x }}, Z={{ clickedPosition.z }}</p>
32
+ </div>
33
+ </div>
34
+ </template>
35
+
36
+ <script>
37
+ // 导入Vue2兼容组件
38
+ var KimapComponent = require('./KimapComponent.vue').default || require('./KimapComponent.vue');
39
+
40
+ // 使用CommonJS导入Three.js(兼容旧版项目)
41
+ var THREE = require('three');
42
+
43
+ module.exports = {
44
+ name: 'KimapExample',
45
+ components: {
46
+ KimapComponent: KimapComponent
47
+ },
48
+ data: function() {
49
+ return {
50
+ modelUrl: '/static/models/building.obj', // 模型文件路径
51
+ mapOrigin: { x: 0, y: 0, z: 0 },
52
+ clickedPosition: null,
53
+ markerCount: 0,
54
+ isMapReady: false
55
+ };
56
+ },
57
+ methods: {
58
+ // 地图加载完成
59
+ onMapReady: function(sdk) {
60
+ console.log('地图初始化完成', sdk);
61
+ this.isMapReady = true;
62
+ this.$message && this.$message.success('地图加载成功');
63
+ },
64
+
65
+ // 地图加载失败
66
+ onMapError: function(error) {
67
+ console.error('地图加载失败:', error);
68
+ this.$message && this.$message.error('地图加载失败');
69
+ },
70
+
71
+ // 点击位置回调
72
+ onPositionClick: function(data) {
73
+ console.log('点击位置:', data.position);
74
+ this.clickedPosition = data.position;
75
+ },
76
+
77
+ // 添加标记
78
+ addMarker: function() {
79
+ if (!this.isMapReady) {
80
+ alert('地图未就绪');
81
+ return;
82
+ }
83
+
84
+ this.markerCount++;
85
+ var id = 'marker-' + this.markerCount;
86
+
87
+ // 随机位置
88
+ var x = Math.random() * 80 + 10;
89
+ var z = Math.random() * 40 + 10;
90
+
91
+ this.$refs.kimap.addLocationMarker({
92
+ id: id,
93
+ position: new THREE.Vector3(x, 0, z),
94
+ label: '标记 ' + this.markerCount,
95
+ color: this.getRandomColor()
96
+ });
97
+
98
+ console.log('添加标记:', id);
99
+ },
100
+
101
+ // 移除标记
102
+ removeMarker: function() {
103
+ if (this.markerCount > 0) {
104
+ var id = 'marker-' + this.markerCount;
105
+ this.$refs.kimap.removeLocationMarker(id);
106
+ this.markerCount--;
107
+ console.log('移除标记:', id);
108
+ }
109
+ },
110
+
111
+ // 更新当前位置
112
+ updatePosition: function() {
113
+ if (!this.isMapReady) {
114
+ alert('地图未就绪');
115
+ return;
116
+ }
117
+
118
+ var x = Math.random() * 80 + 10;
119
+ var z = Math.random() * 40 + 10;
120
+ var position = new THREE.Vector3(x, 0, z);
121
+
122
+ this.$refs.kimap.updateCurrentPosition(position);
123
+ console.log('更新位置:', position);
124
+ },
125
+
126
+ // 显示弹窗
127
+ showInfo: function() {
128
+ if (!this.isMapReady) {
129
+ alert('地图未就绪');
130
+ return;
131
+ }
132
+
133
+ this.$refs.kimap.showPopup({
134
+ title: '信息提示',
135
+ content: '这是一个示例弹窗',
136
+ position: new THREE.Vector3(50, 0, 25)
137
+ });
138
+ },
139
+
140
+ // 隐藏弹窗
141
+ hideInfo: function() {
142
+ this.$refs.kimap.hidePopup();
143
+ },
144
+
145
+ // 开始绘制
146
+ startDrawLine: function() {
147
+ var self = this;
148
+
149
+ this.$refs.kimap.startDraw('line', {
150
+ onDrawClick: function(position) {
151
+ console.log('添加点:', position);
152
+ },
153
+ onDrawComplete: function(points) {
154
+ console.log('绘制完成,共 ' + points.length + ' 个点');
155
+ alert('线段绘制完成!共 ' + points.length + ' 个点');
156
+ }
157
+ });
158
+ },
159
+
160
+ // 停止绘制
161
+ stopDraw: function() {
162
+ this.$refs.kimap.endDraw();
163
+ },
164
+
165
+ // 获取随机颜色
166
+ getRandomColor: function() {
167
+ var colors = ['#4CAF50', '#2196F3', '#FF9800', '#E91E63', '#9C27B0'];
168
+ return colors[Math.floor(Math.random() * colors.length)];
169
+ }
170
+ },
171
+
172
+ // 组件销毁时清理
173
+ beforeDestroy: function() {
174
+ console.log('组件即将销毁');
175
+ }
176
+ };
177
+ </script>
178
+
179
+ <style scoped>
180
+ .map-page {
181
+ width: 100%;
182
+ height: 100vh;
183
+ position: relative;
184
+ display: flex;
185
+ }
186
+
187
+ .control-panel {
188
+ position: absolute;
189
+ top: 20px;
190
+ left: 20px;
191
+ background: white;
192
+ padding: 20px;
193
+ border-radius: 8px;
194
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
195
+ z-index: 100;
196
+ }
197
+
198
+ .control-panel h3 {
199
+ margin: 0 0 15px 0;
200
+ font-size: 16px;
201
+ }
202
+
203
+ .control-panel button {
204
+ display: block;
205
+ width: 120px;
206
+ margin-bottom: 10px;
207
+ padding: 8px 12px;
208
+ background: #2196F3;
209
+ color: white;
210
+ border: none;
211
+ border-radius: 4px;
212
+ cursor: pointer;
213
+ }
214
+
215
+ .control-panel button:hover {
216
+ background: #1976D2;
217
+ }
218
+
219
+ .info-panel {
220
+ position: absolute;
221
+ bottom: 20px;
222
+ left: 20px;
223
+ background: white;
224
+ padding: 15px;
225
+ border-radius: 8px;
226
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
227
+ z-index: 100;
228
+ }
229
+
230
+ .info-panel p {
231
+ margin: 0;
232
+ font-size: 14px;
233
+ }
234
+ </style>