BUG 27449

This commit is contained in:
aixianling
2022-03-15 18:54:01 +08:00
parent a228eededc
commit 80552a458e

View File

@@ -8,8 +8,7 @@
当前<br>位置 当前<br>位置
</div> --> </div> -->
<div class="map-content"> <div class="map-content">
<AiTMap v-if="user.areaId" :areaId="user.areaId" :map.sync="map" :lib.sync="lib" :ops="ops" <AiTMap :map.sync="map" :lib.sync="lib" :ops="ops" :libraries="['service', 'tools']"/>
:libraries="['service', 'tools']"/>
</div> </div>
<div class="footer"> <div class="footer">
<div class="btn" @click="confirm">确认定位</div> <div class="btn" @click="confirm">确认定位</div>
@@ -63,10 +62,9 @@ export default {
markerLayer: '', markerLayer: '',
isFlag: false, isFlag: false,
latLng: {lat: '', lng: ''}, latLng: {lat: '', lng: ''},
retryTimes: 0
} }
}, },
computed: {...mapState(['user',])}, computed: {...mapState(['user'])},
mounted() { mounted() {
this.initMap() this.initMap()
}, },
@@ -74,36 +72,33 @@ export default {
document.title = "楼栋定位" document.title = "楼栋定位"
}, },
methods: { methods: {
initMap() { //初始化地图 initMap(retryTimes = 0) { //初始化地图
this.$nextTick(() => { this.$nextTick(() => {
let {map, retryTimes} = this let {map} = this
if (map) { if (map) {
map.setZoom(15) map.setZoom(15)
map.on("click", (evt) => { map.on("click", (evt) => {
this.handleMapClick(evt) this.handleMapClick(evt)
}); });
} else { } else {
if (retryTimes < 5) if (retryTimes < 10)
setTimeout(() => { setTimeout(() => {
this.retryTimes++ this.initMap(++retryTimes)
this.initMap() }, 500)
}, 1000) else console.error("地图渲染失败")
} }
}) })
}, },
getLocale() { getLocale() {
wx.getLocation({ wx.getLocation({
type: 'gcj02', type: 'gcj02',
success: res => { success: res => {
console.log(res)
let {latitude: lat, longitude: lng} = res let {latitude: lat, longitude: lng} = res
this.handleMapClick({latlng: {lat, lng}}) this.handleMapClick({latlng: {lat, lng}})
} }
}) })
}, },
handleMapClick(evt) { handleMapClick(evt) {
console.log(evt.latLng)
let {lib: TMap, map} = this let {lib: TMap, map} = this
if (this.markerLayer) { if (this.markerLayer) {
this.markerLayer.setMap(null); this.markerLayer.setMap(null);