@lambo-design-mobile/lambo-js-bridge 1.0.0-beta.2 → 1.0.0-beta.21
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/.versionrc +23 -23
- package/CHANGELOG.md +221 -0
- package/README.md +318 -238
- package/demo/index.vue +261 -223
- package/index.js +3 -3
- package/package.json +4 -2
- package/src/sdk/BdMapUtils.js +74 -0
- package/src/sdk/BrowserAdapter.js +63 -63
- package/src/sdk/CordovaAdapter.js +20 -20
- package/src/sdk/DingTalkAdapter.js +20 -20
- package/src/sdk/LamboJsBridge.js +90 -73
- package/src/sdk/MobileIMAdaoter.js +67 -0
- package/src/sdk/WeComAdapter.js +367 -301
- package/src/sdk/WechatAdapter.js +69 -34
- package/src/sdk/YunTuAdapter.js +224 -163
- package/src/sdk/yuntu.js +55 -0
- package/yuntu.js +0 -42
package/demo/index.vue
CHANGED
|
@@ -1,223 +1,261 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<demo-section>
|
|
3
|
-
<demo-block title="初始化信息">
|
|
4
|
-
<pre v-
|
|
5
|
-
</demo-block>
|
|
6
|
-
|
|
7
|
-
<van-button @click="
|
|
8
|
-
<pre v-
|
|
9
|
-
</demo-block>
|
|
10
|
-
<demo-block title="
|
|
11
|
-
<van-button @click="
|
|
12
|
-
<pre v-
|
|
13
|
-
</demo-block>
|
|
14
|
-
<demo-block title="
|
|
15
|
-
<van-button @click="
|
|
16
|
-
<pre v-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</demo-block>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
// console.log('
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error('Error
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
async
|
|
125
|
-
try {
|
|
126
|
-
const options =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<demo-section>
|
|
3
|
+
<demo-block title="初始化信息">
|
|
4
|
+
<pre v-show="initInfo"><code>{{ initInfo }}</code></pre>
|
|
5
|
+
</demo-block>
|
|
6
|
+
<demo-block title="初始化地图Key">
|
|
7
|
+
<van-button @click="initKey">初始化地图Key</van-button>
|
|
8
|
+
<pre v-show="initKeyMessage"><code>{{ initKeyMessage }}</code></pre>
|
|
9
|
+
</demo-block>
|
|
10
|
+
<demo-block title="获取定位">
|
|
11
|
+
<van-button @click="getLocation">获取定位</van-button>
|
|
12
|
+
<pre v-show="location"><code>{{ location }}</code></pre>
|
|
13
|
+
</demo-block>
|
|
14
|
+
<demo-block title="扫码">
|
|
15
|
+
<van-button @click="scanCode">扫码</van-button>
|
|
16
|
+
<pre v-show="scanResult"><code>{{ scanResult }}</code></pre>
|
|
17
|
+
</demo-block>
|
|
18
|
+
<demo-block title="拍照">
|
|
19
|
+
<van-button @click="takePhoto">拍照</van-button>
|
|
20
|
+
<pre v-show="photoResult"><code>{{ photoResult }}</code></pre>
|
|
21
|
+
<div v-show="photoPreviews.length" :class="gridClass">
|
|
22
|
+
<div v-for="(preview, index) in photoPreviews" :key="index" class="photo-container">
|
|
23
|
+
<img :src="preview" alt="Photo Preview" class="photo">
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</demo-block>
|
|
27
|
+
<demo-block title="打开位置">
|
|
28
|
+
<van-button @click="openLocation">打开位置</van-button>
|
|
29
|
+
<pre v-show="openLocationResult"><code>{{ openLocationResult }}</code></pre>
|
|
30
|
+
</demo-block>
|
|
31
|
+
<demo-block title="文件预览">
|
|
32
|
+
<a href="javascript:void(0);" @click="previewFile">点击这里预览文件</a>
|
|
33
|
+
</demo-block>
|
|
34
|
+
|
|
35
|
+
</demo-section>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script>
|
|
39
|
+
import LamboJsBridge from "../src/sdk/LamboJsBridge";
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
name: 'js-bridge-demo',
|
|
43
|
+
data() {
|
|
44
|
+
return {
|
|
45
|
+
lamboBridge: null,
|
|
46
|
+
initInfo: '',
|
|
47
|
+
location: '',
|
|
48
|
+
scanResult: '',
|
|
49
|
+
photoResult: '',
|
|
50
|
+
openLocationResult: '', // 添加用于存储打开位置的返回值
|
|
51
|
+
latitude: 117.129, // 存储纬度
|
|
52
|
+
longitude: 36.662, // 存储经度
|
|
53
|
+
ossServerContext: 'ibp-upms-server',
|
|
54
|
+
ossImgPutUrl: '/oss/file/put',
|
|
55
|
+
ossImgGetUrl: '/oss/file/get/',
|
|
56
|
+
scale: 8,
|
|
57
|
+
name:'这里是位置名称name',
|
|
58
|
+
address:'这里是详细位置address',
|
|
59
|
+
wechatId: 'wx92fab9d3885b0298',
|
|
60
|
+
weComId: 'wx0eb3ba9d89eca3cb',
|
|
61
|
+
agentId:'1000065',
|
|
62
|
+
dingTalkId: '',
|
|
63
|
+
photoPreviews: [],
|
|
64
|
+
initKeyMessage: '' // 用于存储 initKey 的返回消息
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
computed: {
|
|
68
|
+
gridClass() {
|
|
69
|
+
const {length} = this.photoPreviews;
|
|
70
|
+
if (length === 1) {
|
|
71
|
+
return 'grid-single';
|
|
72
|
+
} if (length > 1 && length <= 4) {
|
|
73
|
+
return 'grid-two';
|
|
74
|
+
} if (length > 4) {
|
|
75
|
+
return 'grid-three';
|
|
76
|
+
}
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async created() {
|
|
81
|
+
const script = document.createElement('script')
|
|
82
|
+
script.src = '//dev.sunquan.tech/inspect/target.js'
|
|
83
|
+
script.async = true
|
|
84
|
+
document.getElementsByTagName('head')[0].appendChild(script)
|
|
85
|
+
const options = {
|
|
86
|
+
// 初始化参数,根据需要填写
|
|
87
|
+
wechatId:this.wechatId,
|
|
88
|
+
weComId:this.weComId,
|
|
89
|
+
agentId:this.agentId,
|
|
90
|
+
dingTalkId:this.dingTalkId,
|
|
91
|
+
pluginConfig:["localAuthPlugin","amapPlugin","tabBarPlugin","scanCodePlugin","filePreviewPlugin"],
|
|
92
|
+
};
|
|
93
|
+
this.$lamboJsBridge = new LamboJsBridge(options);
|
|
94
|
+
await this.getPlatform();
|
|
95
|
+
// await this.$lamboJsBridge.initializePlugin(options.pluginConfig);
|
|
96
|
+
},
|
|
97
|
+
methods: {
|
|
98
|
+
async getPlatform() {
|
|
99
|
+
try {
|
|
100
|
+
const info = await this.$lamboJsBridge.getPlatform(); // 获取初始化信息
|
|
101
|
+
this.initInfo = JSON.stringify(info, null, 2); // 美化输出
|
|
102
|
+
console.log('Init Info:', info);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Error getting init info:', error);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async getLocation() {
|
|
108
|
+
try {
|
|
109
|
+
const options ={
|
|
110
|
+
// 初始化参数,根据需要填写
|
|
111
|
+
};
|
|
112
|
+
const location = await this.$lamboJsBridge.getLocation(options);
|
|
113
|
+
console.log("location",location)
|
|
114
|
+
this.location += `${JSON.stringify(location)}\n`; // 追加新数据
|
|
115
|
+
this.latitude = location.latitude; // 存储纬度
|
|
116
|
+
this.longitude = location.longitude; // 存储经度
|
|
117
|
+
console.log("this.latitude:",this.latitude);
|
|
118
|
+
console.log("this.longitude:",this.longitude);
|
|
119
|
+
// console.log('Location:', location);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('Error getting location:', error);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async scanCode() {
|
|
125
|
+
try {
|
|
126
|
+
const options ={
|
|
127
|
+
// 初始化参数,根据需要填写
|
|
128
|
+
};
|
|
129
|
+
const result = await this.$lamboJsBridge.scanCode(options);
|
|
130
|
+
this.scanResult += `${JSON.stringify(result)}\n`; // 追加新数据
|
|
131
|
+
// console.log('Scan result:', result);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error('Error scanning code:', error);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async takePhoto() {
|
|
137
|
+
try {
|
|
138
|
+
const options = {
|
|
139
|
+
ossServerContext: this.ossServerContext,
|
|
140
|
+
ossImgPutUrl: this.ossImgPutUrl,
|
|
141
|
+
ossImgGetUrl: this.ossImgGetUrl,
|
|
142
|
+
outputType: ['info','data','oss'],
|
|
143
|
+
method: 'file',
|
|
144
|
+
// sourceType: 'gallery'
|
|
145
|
+
};
|
|
146
|
+
const photos = await this.$lamboJsBridge.takePhoto(options);
|
|
147
|
+
this.photoResult += `${JSON.stringify(photos)}\n`;
|
|
148
|
+
console.log("Photo result:", photos); // 调试输出
|
|
149
|
+
console.log("oss:",photos.imageOss)
|
|
150
|
+
|
|
151
|
+
photos.forEach(photo => {
|
|
152
|
+
if (photo.imageOss && photo.imageOss.url) {
|
|
153
|
+
this.photoPreviews.push(photo.imageOss.url); // 将图片URL添加到数组中
|
|
154
|
+
} else if (photo.imageData) {
|
|
155
|
+
this.photoPreviews.push(photo.imageData); // 如果OSS URL不存在,使用本地数据
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
console.log("Updated photoPreviews:", this.photoPreviews); // 调试输出
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Error taking photo:', error);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
async openLocation() {
|
|
165
|
+
try {
|
|
166
|
+
if (this.latitude !== null && this.longitude !== null) {
|
|
167
|
+
const options = {
|
|
168
|
+
// 初始化参数,根据需要修改
|
|
169
|
+
latitude: this.latitude,
|
|
170
|
+
longitude: this.longitude,
|
|
171
|
+
name: this.name,
|
|
172
|
+
address: this.address,
|
|
173
|
+
scale: this.scale,
|
|
174
|
+
type:"amap"
|
|
175
|
+
};
|
|
176
|
+
await this.$lamboJsBridge.openLocation(options);
|
|
177
|
+
this.openLocationResult = '位置已成功打开'; // 成功打开位置时存储信息
|
|
178
|
+
console.log('Location opened successfully');
|
|
179
|
+
} else {
|
|
180
|
+
this.openLocationResult = '没有可用的位置信息,请先获取定位。'; // 没有位置信息时存储错误信息
|
|
181
|
+
console.error('No location data available. Please get the location first.');
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
this.openLocationResult = `打开位置时出错: ${error.message}`; // 存储错误信息
|
|
185
|
+
console.error('Error opening location:', error);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async previewFile() {
|
|
189
|
+
try {
|
|
190
|
+
const options = {
|
|
191
|
+
title: '预览文件.txt', // 文件的标题
|
|
192
|
+
path: 'http://160.mall.eap.lambo.top/ecm-runtime-server/api/file/get/123456' ,// 文件的URL路径
|
|
193
|
+
tokenKey:"lambo-token-ibp"
|
|
194
|
+
};
|
|
195
|
+
const result = await this.$lamboJsBridge.filePreview(options);
|
|
196
|
+
console.log('File preview result:', result);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error('Error previewing file:', error);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
async initKey() {
|
|
202
|
+
try {
|
|
203
|
+
const result = await this.$lamboJsBridge.initKey( {"androidKey":"41c4c1f35d8d14f5bf1907c173924147","iosKey":"465abf5da8c8d62e3caa63952a0957a5"});
|
|
204
|
+
console.log('initKey result:', result);
|
|
205
|
+
this.initKeyMessage = `initKey result: ${JSON.stringify(result)}`;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
this.initKeyMessage = `初始化 Key 时出错: ${error.message}`;
|
|
208
|
+
console.error('Error initializing key:', error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
beforeRouteEnter (to, from, next) {
|
|
213
|
+
next(vm => {
|
|
214
|
+
if (from.name !== null) {
|
|
215
|
+
vm.$nextTick(() => {
|
|
216
|
+
window.location.reload();
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<style scoped>
|
|
225
|
+
pre {
|
|
226
|
+
background-color: #f5f5f5;
|
|
227
|
+
padding: 10px;
|
|
228
|
+
border-radius: 4px;
|
|
229
|
+
overflow: auto;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
code {
|
|
233
|
+
white-space: pre-wrap;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.grid-single {
|
|
237
|
+
display: grid;
|
|
238
|
+
grid-template-columns: 1fr;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.grid-two {
|
|
242
|
+
display: grid;
|
|
243
|
+
grid-template-columns: repeat(2, 1fr);
|
|
244
|
+
gap: 10px;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.grid-three {
|
|
248
|
+
display: grid;
|
|
249
|
+
grid-template-columns: repeat(3, 1fr);
|
|
250
|
+
gap: 10px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.photo-container {
|
|
254
|
+
margin-top: 10px;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.photo {
|
|
258
|
+
max-width: 100%;
|
|
259
|
+
border-radius: 4px;
|
|
260
|
+
}
|
|
261
|
+
</style>
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import LamboJsBridge from './src/sdk/LamboJsBridge'
|
|
2
|
-
|
|
3
|
-
export default LamboJsBridge
|
|
1
|
+
import LamboJsBridge from './src/sdk/LamboJsBridge'
|
|
2
|
+
|
|
3
|
+
export default LamboJsBridge
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambo-design-mobile/lambo-js-bridge",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "lambo",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"access": "public",
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
11
11
|
},
|
|
12
|
-
"dependencies": {
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"coordtransform": "^2.1.2"
|
|
14
|
+
},
|
|
13
15
|
"scripts": {
|
|
14
16
|
"release-js-bridge": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
|
15
17
|
"release-major": "standard-version --release-as major",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import config from "@lambo-design-mobile/shared/config/config";
|
|
2
|
+
import coordtransform from "coordtransform";
|
|
3
|
+
|
|
4
|
+
const addScript = function (src, cb) {
|
|
5
|
+
const script = document.createElement('script')
|
|
6
|
+
script.src = src
|
|
7
|
+
document.getElementsByTagName('head')[0].appendChild(script)
|
|
8
|
+
script.onload = function () {
|
|
9
|
+
if (!!cb) {
|
|
10
|
+
cb()
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function initBdMap() {
|
|
16
|
+
let tempAk = 'AWZBggDSk8Zsv2STX7S2SBYO6wsH7BVT'
|
|
17
|
+
if (config.akList) {
|
|
18
|
+
tempAk = config.akList[Math.random() * config.akList.length]
|
|
19
|
+
}
|
|
20
|
+
addScript('https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=' + tempAk)
|
|
21
|
+
addScript('https://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=' + tempAk)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getAddress(longitude, latitude) {
|
|
25
|
+
const myGeo = new BMap.Geocoder({extensions_town: false});
|
|
26
|
+
let city = ''
|
|
27
|
+
let province = ''
|
|
28
|
+
let address = ''
|
|
29
|
+
|
|
30
|
+
// 根据坐标得到地址描述
|
|
31
|
+
myGeo.getLocation(new BMap.Point(longitude, latitude), function(result){
|
|
32
|
+
if (result){
|
|
33
|
+
city = result.addressComponents.city
|
|
34
|
+
province = result.addressComponents.province
|
|
35
|
+
address = result.address
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
city,
|
|
40
|
+
province,
|
|
41
|
+
address
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getAxisByType(unifiedLocation, locationType) {
|
|
46
|
+
// 目前只有wgs84 bd09 gcj02 默认传进unifiedLocation 坐标系为gcj02 不转换
|
|
47
|
+
if(locationType === 'bd09') {
|
|
48
|
+
// 将 gcj02 坐标转换为 bd09
|
|
49
|
+
const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
|
|
50
|
+
unifiedLocation.longitude = bd09Lng;
|
|
51
|
+
unifiedLocation.latitude = bd09Lat;
|
|
52
|
+
}
|
|
53
|
+
else if(locationType === 'wgs84'){
|
|
54
|
+
// 将 gcj02 坐标转换为 bd09
|
|
55
|
+
const [wgs84Lng, wgs84Lat] = coordtransform.gcj02towgs84(unifiedLocation.longitude, unifiedLocation.latitude);
|
|
56
|
+
unifiedLocation.longitude = wgs84Lng;
|
|
57
|
+
unifiedLocation.latitude = wgs84Lat;
|
|
58
|
+
}
|
|
59
|
+
if (!unifiedLocation.latitude || !unifiedLocation.longitude) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return unifiedLocation
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getAddressByType(unifiedLocation, locationType) {
|
|
66
|
+
|
|
67
|
+
const [bd09Lng, bd09Lat] = coordtransform.gcj02tobd09(unifiedLocation.longitude, unifiedLocation.latitude);
|
|
68
|
+
// 根据坐标得到地址描述
|
|
69
|
+
const res = getAddress(bd09Lng, bd09Lat)
|
|
70
|
+
unifiedLocation.city = res.addressComponents.city
|
|
71
|
+
unifiedLocation.province = res.addressComponents.province
|
|
72
|
+
unifiedLocation.address = res.address
|
|
73
|
+
getAxisByType(unifiedLocation, locationType)
|
|
74
|
+
}
|