vue中调用百度地图实现信息窗口展示并搜索功能

<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)
	}
}

实现的结果展示为在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值