vue中调用百度地图实现信息窗口展示并搜索功能
<template><div class="container" id="container"></div></template>mounted(){baiduMap(){let map = new BMap.Map('container'); //创建地图实例let point = new BMap.Point(thi...
·
<template>
<div class="container" id="container">
</div>
</template>
mounted(){
baiduMap(){
let map = new BMap.Map('container'); //创建地图实例
let point = new BMap.Point(this.content.longitude, this.content.dimension); //创建点坐标
map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true); // 滚轮缩放
let marker = new BMap.Marker(point) // 创建标注 点
map.addOverlay(marker) // 将标注添加到地图中
map.addControl(new BMap.NavigationControl(BMAP_ANCHOR_TOP_LEFT)); //控件左上角
//信息窗口内容
let content = `<div style="margin:0;line-height:20px;padding:2px;"><img src="${this.content.imgUrl}" alt="" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>
地址:${this.content.address}<br/>电话:${this.content.phone}<br/>简介:${this.content.introduction}
</div>
`;
//信息窗口标题
let title = {
title : this.content.title, //标题
width : 290, //宽度
height : 105, //高度
panel : "panel", //检索结果面板
enableAutoPan : true, //自动平移
searchTypes:[
BMAPLIB_TAB_FROM_HERE, //从这里出发
BMAPLIB_TAB_SEARCH, //周边检索
BMAPLIB_TAB_TO_HERE, //到这里去
]
}
//创建一个信息窗口实例
let searchInfoWindow = new BMapLib.SearchInfoWindow(map,content, title);
searchInfoWindow.open(marker);
//点击红点弹出信息窗口
marker.addEventListener("click", function(e){
searchInfoWindow.open(marker);
})
// console.log(BMap)
}
}
实现的结果展示为
更多推荐
已为社区贡献18条内容
所有评论(0)