地图问题修复

This commit is contained in:
aixianling
2021-12-21 16:40:02 +08:00
parent 2d81852c6f
commit 633d85de91
3 changed files with 295 additions and 364 deletions

View File

@@ -4,7 +4,7 @@
<img src="./img/model-icon.png" alt="" @click="toDetail"> 楼栋<br/>模型
</div>
<div class="map-content">
<AiTMap :areaId="areaId" :map.sync="map" :lib.sync="lib" :ops="ops" :libraries="['service', 'tools']"></AiTMap>
<AiTMap :areaId="user.areaId" :map.sync="map" :lib.sync="lib" :ops="ops" :libraries="['service', 'tools']"></AiTMap>
</div>
<div class="footer">
<div class="click" @click="isFlag=true">点击定位</div>
@@ -48,54 +48,62 @@
</template>
<script>
import { mapState } from 'vuex'
import {mapState} from 'vuex'
export default {
props: ['params'],
data() {
return {
areaId: '',
ops: {},
lib: '',
lib: null,
map: null,
markerLayer: '',
isFlag: false,
latLng: {lat: '', lng: ''},
retryTimes: 0
}
},
computed: { ...mapState(['user']) },
computed: {...mapState(['user'])},
mounted() {
this.areaId = this.params.areaId
this.initMap()
},
methods: {
initMap() { //初始化地图
this.$nextTick(() =>{
let {lib: TMap, map} = this
map.on("click", (evt) => {
if( this.markerLayer) {
this.markerLayer.setMap(null);
}
this.markerLayer = new TMap.MultiMarker({
id: 'marker-layer',
map: map
});
if(this.isFlag) {
this.markerLayer.add({
position: evt.latLng
});
this.latLng = {
lat: evt.latLng.lat,
lng: evt.latLng.lng
this.$nextTick(() => {
let {lib: TMap, map, retryTimes} = this
if (map) {
map.on("click", (evt) => {
if (this.markerLayer) {
this.markerLayer.setMap(null);
}
}
});
this.markerLayer = new TMap.MultiMarker({
id: 'marker-layer',
map: map
});
if (this.isFlag) {
this.markerLayer.add({
position: evt.latLng
});
this.latLng = {
lat: evt.latLng.lat,
lng: evt.latLng.lng
}
}
});
} else {
if (retryTimes < 5)
setTimeout(() => {
this.retryTimes++
this.initMap()
}, 1000)
}
})
},
confirm() {
if(!this.latLng.lat) {
if (!this.latLng.lat) {
return this.$u.toast(`未获取到定位信息,无法定位`)
}
@@ -122,22 +130,24 @@ export default {
params: this.params
})
}
}
}
</script>
<style lang="scss" scoped>
uni-page-body{
uni-page-body {
height: 100%;
}
.map {
height: 100%;
.build-btn{
.build-btn {
width: 80px;
height: 160px;
background: #FFF;
box-shadow: 0px 4px 8px 0px rgba(138, 138, 138, 0.5);
box-shadow: 0 4px 8px 0 rgba(138, 138, 138, 0.5);
border-radius: 8px;
position: fixed;
bottom: 136px;
@@ -150,17 +160,20 @@ uni-page-body{
font-weight: 500;
color: #666;
line-height: 30px;
img{
img {
width: 48px;
height: 48px;
margin-bottom: 8px;
}
}
.map-content{
.map-content {
width: 100%;
height: 100%;
}
.footer{
.footer {
width: 100%;
position: fixed;
bottom: 0;
@@ -173,16 +186,18 @@ uni-page-body{
height: 112px;
line-height: 112px;
text-align: center;
.click{
.click {
flex: 1;
color: #333;
background-color: #fff;
}
.btn{
.btn {
flex: 2;
background: #1365DD;
color: #FFF;
}
}
}
</style>
</style>