Commit 778c4184 by 李伟康

修改地图

1 parent 08b23cc2
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"build": "^0.1.4", "build": "^0.1.4",
"core-js": "^3.6.4", "core-js": "^3.6.4",
"dayjs": "^1.10.5", "dayjs": "^1.10.5",
"glmap-jssdk": "^1.0.1",
"glsx-common": "^2.1.0", "glsx-common": "^2.1.0",
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"number-precision": "^1.6.0", "number-precision": "^1.6.0",
......
import md5 from './utils/md5' import GlMap from 'glmap-jssdk'
import qs from './utils/qs' export default new GlMap()
const key = 'F2HBZ-KH73F-7A2J2-JC4UR-WOHCO-UVFGZ'
const secret = 'YBmrM98E5pM4gYeknWiBPaWpFR4AISUl'
const domain = 'https://apis.map.qq.com'
class QQMap {
setLocaleCompare(params) {
params.key = key
let keys = []
let obj = {}
Object.keys(params).map(e => keys.push(e))
keys.sort((a, b) => a.localeCompare(b)).map(e => (obj[e] = params[e]))
return obj
}
getSign(params, methods) {
let obj = this.setLocaleCompare(params)
let sign = `${methods}?${decodeURIComponent(qs.stringify(obj))}${secret}`
return md5(sign)
}
request(method, data) {
data.output = 'jsonp'
// data.callback = 'test'
const sig = this.getSign(data, method)
let obj = {
...this.setLocaleCompare(data),
sig
},
params = []
Object.keys(obj).map(key => {
params.push(`${key}=${encodeURIComponent(obj[key])}`)
})
// window.fetch(`${domain}${method}?${params.join('&')}`, {
// method: 'GET',
// mode: 'no-cors',
// })
let script = document.createElement('script')
script.src = `${domain}${method}?${params.join('&')}`
script.type = 'text/javascript'
document.body.insertBefore(script, document.body.children[0])
return new Promise((resolve, reject) => {
window['QQmap'] = ({ status, result }) => {
console.log(result)
if (status == '0') resolve(result)
else reject()
document.body.removeChild(script)
}
})
}
/**计算距离 */
calculateDistance(from, to) {
from = from.join(',')
to = to.join(',')
return this.request('/ws/distance/v1/', {
from,
to,
mode: 'driving'
})
}
/** 批量距离计算(矩阵) */
calculateDistanceMatrix(from, toList) {
from = from.join(',')
let to = toList.join(';')
return this.request('/ws/distance/v1/matrix/', {
from,
to,
mode: 'driving'
})
}
/**地址解析(地址转坐标) */
geocoder(address) {
return this.request('/ws/geocoder/v1/', {
address
})
}
/**逆地址解析(坐标位置描述) location=lat<纬度>,lng<经度> */
detailedAdrress(location) {
location = location.join(',')
return this.request('/ws/geocoder/v1/', {
location
})
}
/**IP定位 */
getLocationByIp() {
return this.request('/ws/location/v1/ip')
}
/**坐标转换 */
translate(locations, type = 5) {
locations = locations.join(';') //格式:纬度前,经度后
return this.request('/ws/coord/v1/translate', {
locations,
type
})
}
}
export default new QQMap()
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!