vue baidu-map手机端点击事件无效

vue baidu-map手机端点击事件无效

解题思路

手机端 禁用地图拖拽 click事件就会被触发
触摸结束 --> 开启 禁止拖拽
触摸移动中 --> 开启 启用拖拽

我参考的解决办法

https://blog.csdn.net/Davis_Dxs/article/details/82425211
在vue baidu-map 实现


<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/element.css">
<title>地图</title>
<style>
.map {
height: 400px;
}

.searchMap {
max-height: 300px
}
</style>
</head>

<body>
<div id="main">
解决app端,点击地图无法生效
<div>
地址:
<el-input placeholder="请输入搜索地址" prefix-icon="el-icon-search" v-model="mapConfig.keyword"
class="input-with-select">
<el-button slot="append" icon="el-icon-search"></el-button>
</el-input>
</div>
<div>
地址:
<el-input placeholder="当前选中地址" prefix-icon="el-icon-location" v-model="mapConfig.chooseAddress"
class="input-with-select">
</el-input>
</div>
<baidu-map :center="mapConfig.center" :dragging="mapConfig.dragging" :scroll-wheel-zoom="true"
:zoom="mapConfig.zoom" @click="getPoint" @ready="onBaiduMapReady" @touchend="mapTouchend"
@touchmove="mapTouchmove" class="bm-view">
<bm-view class="map"></bm-view>
<bm-marker :dragging="true" :position="mapConfig.position" @dragend="getPoint">
<bm-info-window :show="mapConfig.showMark" style="font-size: 14px" v-on:close="infoWindowClose">
<p>地址:{{ mapConfig.markAddress }}</p>
</bm-info-window>
</bm-marker>
<bm-local-search :auto-viewport="true" :keyword="mapConfig.keyword" @infohtmlset="handelSearch"
class="searchMap"></bm-local-search>
</baidu-map>
</div>
<script src="../js/vue.js"></script>
<script src="../js/element.js"></script>

<script src="../js/baidu-map0.21.2.js"></script>

<script>
Vue.use(VueBaiduMap.default, {
ak: '你的ak'
})
var app = new Vue({
el: '#main',
data: {
mapConfig: {
zoom: 15,
dragging: false,
center: {}, //地图中心
position: {}, //定位
showMark: false,
markAddress: '', //点击地图获得的地址
loaction: '', //搜索的城市
keyword: '', //详细地址
chooseAddress: '' //详细地址
}

},
methods: {
//触摸移动时触发此事件
mapTouchmove(e) {
this.mapConfig.dragging = true
},
//触摸结束时触发此事件
mapTouchend(e) {
this.mapConfig.dragging = false
},
//点击地图
getPoint(e) {
let geocoder = new BMap.Geocoder() //创建地址解析器的实例
geocoder.getLocation(e.point, rs => {
//地址描述
this.mapConfig.position = e.point
this.mapConfig.chooseAddress = rs.address
this.mapConfig.markAddress = rs.address
})
this.mapConfig.showMark = true
},
//关闭mark层
infoWindowClose() {
this.mapConfig.showMark = false
},
//点击搜索的地区
handelSearch(e) {
this.mapConfig.chooseAddress = (e.province || '') + (e.city || '') + e.address
},
//地图初始化时,定位当前位置
onBaiduMapReady(e) {
const that = this
this.BMap = e.BMap
if (this.BMap) {
const geolocation = new this.BMap.Geolocation()
geolocation.getCurrentPosition(res => {
const { lng, lat } = res.point
this.mapConfig.center = res.point
this.mapConfig.position = res.point
const { province, city, district, street, street_number } = res.address
this.mapConfig.keyword = province + city
})
}
},
/*地图方法*/
}
})
</script>
</body>

</html>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值