vue-百度地图-maker文字标签显示隐藏

html:

<div id="allmap" class="map"></div>

 
script:
 
mounted() {
this.ready()
},
methods: {
ready: function() {
let sContent ='<div>'+
'信息窗体自定义内容'
'</div>'
let map = new BMap.Map("allmap");
let point = new BMap.Point(116.417854,39.921988)
map.centerAndZoom(point, 14)
map.addControl(new BMap.MapTypeControl())
map.enableScrollWheelZoom(true)
map.enableDoubleClickZoom(true)
let marker = new BMap.Marker(point)// 创建标注
map.addOverlay(marker) // 将标注添加到地图中
map.centerAndZoom(point, 15)
let myLabel = new BMap.Label('<span style="margin-right:20px">皖AT1234</span><span>张三</span>',{offset:new BMap.Size(20,-10)})
myLabel.setStyle({
color: "red",
fontSize: "12px",
height: "20px",
lineHeight: "20px",
fontFamily: "微软雅黑",
opacity: 0.8
});
 
let opts = {
width : 400, // 信息窗口宽度
height: 200, // 信息窗口高度
title : "王府井北" , // 信息窗口标题
enableMessage: true ,// 设置允许信息窗发送短息
}
let infoWindow = new BMap.InfoWindow(sContent, opts) // 创建信息窗口对象
marker.addEventListener("click", function() {
map.openInfoWindow(infoWindow,point) // 开启信息窗口
})
marker.addEventListener("mouseover", function() {
marker.setLabel(myLabel) //鼠标移入maker显示文字标签
})
marker.addEventListener("mouseout", function (e) {
map.removeOverlay(marker.getLabel()) //鼠标移除maker隐藏文字标签
})
}

转载于:https://www.cnblogs.com/yuwen1995/p/9230797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值