This commit is contained in:
liuye
2022-02-10 17:44:26 +08:00
parent 37f4c3d8d4
commit bdc7307497
2 changed files with 46 additions and 21 deletions

View File

@@ -40,6 +40,7 @@ export default {
}
},
methods: {
...mapActions(['wxInvoke']),
injectLib(url, cb) {
const script = document.createElement('script')
script.type = 'text/javascript';
@@ -54,29 +55,49 @@ export default {
var latLng = {}
if(this.config.lat) { //通用版
latLng = this.config
this.mapLib = TMap
this.tmap = new TMap.Map(this.$refs.tmap, {
zoom: 11,
center: new TMap.LatLng(latLng.lat, latLng.lng),
...this.ops
})
this.$emit('loaded')
this.$emit('update:lib', TMap)
this.$emit('update:map', this.tmap)
this.areaId && this.getMapArea()
}else { //上架版
wx.getLocation({
type: 'gcj02', // 默认为wgs84的gps坐标如果要返回直接给openLocation用的火星坐标可传入'gcj02'
success: (res) => {
console.log(res)
latLng = {
lat: res.latitude,
lng: res.longitude
}
this.wxInvoke(['getLocation', {
}, (res) => {
latLng = {
lat: res.latitude,
lng: res.longitude
}
});
this.mapLib = TMap
this.tmap = new TMap.Map(this.$refs.tmap, {
zoom: 11,
center: new TMap.LatLng(latLng.lat, latLng.lng),
...this.ops
})
this.$emit('loaded')
this.$emit('update:lib', TMap)
this.$emit('update:map', this.tmap)
this.areaId && this.getMapArea()
}])
// wx.getLocation({
// type: 'gcj02', // 默认为wgs84的gps坐标如果要返回直接给openLocation用的火星坐标可传入'gcj02'
// success: (res) => {
// console.log(res)
// latLng = {
// lat: res.latitude,
// lng: res.longitude
// }
// }
// });
}
this.mapLib = TMap
this.tmap = new TMap.Map(this.$refs.tmap, {
zoom: 11,
center: new TMap.LatLng(latLng.lat, latLng.lng),
...this.ops
})
this.$emit('loaded')
this.$emit('update:lib', TMap)
this.$emit('update:map', this.tmap)
this.areaId && this.getMapArea()
},
fitBounds(latLngList, count = 0) {
// 由多边形顶点坐标数组计算能完整呈现该多边形的最小矩形范围