vue + BMap实现常用地图

实现功能:
缩放
自定义icon maker
多个覆盖点的点击事件
获取两点的距离
信息窗口的点击事件
<template>
<div id="allmap" ref="mymap"></div>
</template> <style scoped>
#allmap {
width: 100%;
height: calc(100vh - 50vw);
margin-bottom: 9.3333vw;
}
.map-wrap /deep/ .anchorBL{
display: none;
} </style> <script>
import BMap from 'BMap'
import loc from '../../assets/image/organization/location.png' export default {
mounted(){
this.initMap()
},
data () {
return {
center: {
lng: 113.284,
lat: 23.125
},
locationIcon: {
url: loc,
size: {width: 18, height: 18}
},
// 附近的人
aroundList: [
{
point: "113.264531|23.157003",
userName: "1",
atlas: loc,
userId: '0'
},
{
point: "113.330934|23.113401",
userName: "2",
atlas: loc,
userId: '1'
},
{
point: "113.310854|23.113605",
userName: "3",
atlas: loc,
userId: '2'
}
],
}
},
methods: {
initMap: function() {
this.createMap()
this.addMapControl()
this.addAround(this.aroundList)
},
// 创建地图
createMap: function() {
var map = new BMap.Map(this.$refs.mymap)
var point = new BMap.Point(this.center.lng,this.center.lat)
map.centerAndZoom(point,15)
window.map = map
},
// 添加控件
addMapControl(){
//向地图中添加缩放控件
var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,type:BMAP_NAVIGATION_CONTROL_LARGE});
map.addControl(ctrl_nav);
// 创建当前用户标注
var ctrl_marker = new BMap.Point(this.center.lng,this.center.lat)
var myIcon = new BMap.Icon(loc,new BMap.Size(40,49))
var marker_one = new BMap.Marker(ctrl_marker,{icon:myIcon})
map.addOverlay(marker_one)
// 创建一个圆
var circle = new BMap.Circle(ctrl_marker,500,{strokeColor:"#f3c6b1",fillColor:"#f3c6b1", strokeWeight:1, strokeOpacity:0.5})
map.addOverlay(circle);
},
// 添加一个位置标记点
addMarker: function(point){
var marker = new BMap.Marker(point)
map.addOverlay(marker,15)
},
// 加载附近的人信息
addAround: function(markerList) {
if(markerList.length>0){
for(var i=0;i<markerList.length;i++){
// 经度
var info1 = markerList[i].point.split('|')[0]
// 纬度
var info2 = markerList[i].point.split('|')[1]
// 绘制附近人点坐标
var pointA = new BMap.Point(this.center.lng,this.center.lat)
var point = new BMap.Point(info1,info2)
// 距离
var path = map.getDistance(pointA, point).toFixed(2)
var myIcon = new BMap.Icon(markerList[i].atlas,new BMap.Size(40,49))
var marker = new BMap.Marker(point,{icon:myIcon})
map.addOverlay(marker)
//悬浮提示信息
var content = {
userName:markerList[i].userName,
atlas: markerList[i].atlas,
userId: markerList[i].userId,
distance: path
}
map.addOverlay(marker)
this.addClickHandler(content,marker)
}
} else{
return
}
},
//点击提示信息
addClickHandler: function(content,marker){
var _this = this
var sContent = `<div id="ssst" style="display: flex;flex-direction: row;align-items: center;width: 50.3333vw;">
<img src="${content.atlas}" alt="" style="width: 12.5333vw;height: 12.5333vw;border-radius: 50%;margin-right: 2.2667vw;">
<div>
<p style="font-size: 4vw;">${content.userName}</p>
<p style="font-size: 3.2vw;color: #999;margin-top: 1.3333vw;">距你${content.distance}m</p>
</div>
</div>`
var userid = content.userId
var infoWindow = new BMap.InfoWindow(sContent)
marker.addEventListener("click",function(e){
e.preventDefault = true
e.stop
this.openInfoWindow(infoWindow)
setTimeout(() => {
e.preventDefault = true
e.stop
_this.chatWith(userid)
}, 0);
}) },
// 弹窗点击跳转事件
chatWith(userid){
var _this = this
var ssst = document.getElementById('ssst')
ssst.addEventListener('click',function() {
_this.$router.push({
path: '/home',
query: {
userId: userid
}
})
})
}
}
}
</script>
vue + BMap实现常用地图的更多相关文章
- Vue中使用百度地图——设置地图标注
知识点:创建Map实例,为指定的位置设置标注 参考博客:https://www.cnblogs.com/liuswi/p/3994757.html 1.效果图:初始化地图,设置指定经纬度为地图中心点坐 ...
- 基于vue实现百度离线地图
基于vue实现百度离线地图 1. 百度地图API文件获取 有网络 的情况下,需引入百度地图API文件.如下: <script type="text/javascript" s ...
- vue中引入百度地图
xxx.vue <template> <div> <el-input v-model="inputaddr"> </el-input> ...
- Vue.js之常用指令
vue常用指令 vue.js官方给自己的定义是数据模板引擎,并给出了一套渲染数据的指令.本文详细介绍vue.js的常用指令. 官网:点我 一.v-text.v-html v-text:用于绑定文本 v ...
- vue 中引用 百度地图
1.在 http://lbsyun.baidu.com/ 申请 秘钥 2.在index.html文件中引入 <script src="http://api.map.baidu.com/ ...
- 1.Vue.js的常用指令
Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得 ...
- vue封装一些常用组件loading、switch、progress
vue封装一些常用组件loading.switch.progress github文档https://github.com/zengjielin/vue-component-library loadi ...
- vue项目接入百度地图
方法一 :使用第三方工具 vue-baidu-map 安装命令: yarn add vue-baidu-map --save 文档地址:https://dafrok.github.io/vue-bai ...
- Vue专题-js常用指令
vue.js官方给自己的定为是数据模板引擎,并给出了一套渲染数据的指令.本文详细介绍了vue.js的常用指令. vue.js常用指令 Vue.js使用方式及文本插值 Vue.js 使用了基于 HTML ...
随机推荐
- day24_python_1124
1 复习 2 TCP-UDP协议 3 tcp协议的socket 4 复杂tcp协议的socket 5 带退出的聊天程序 6 时间练习demo 7 粘包现象 1.复习 # 网络编程概念# ...
- ES6 memo
一.热门问题 介绍redux,主要解决什么问题 是管理应用程序状态的库,解决数据管理和数据通信的问题 Promise.Async有什么区别 Async 更简洁,不需要用 then 连接 Promise ...
- git push后出错
参考链接: 1,https://blog.csdn.net/shiren1118/article/details/7761203 2,http://www.cnblogs.com/xwdreamer/ ...
- Python正则表达式的re库一些用法(上)
1.查找文本中的模式 search()函数取模式和要扫描的文本作为输入,找到这个模式时就返回一个match对象.如果没有找到模式,search()就返回None. 每个match对象包含有关匹配性质的 ...
- 【Java集合系列四】HashSet和LinkedHashSet解析
2017-07-29 16:58:13 一.简介 1.Set概念 Set可以理解为集合,非常类似数据概念中的集合,集合三大特征:1.确定性:2.互异性:3.无序性,因此Set实现类也有类似的特征. 2 ...
- IE浏览器下flex布局的bug
原文地址:gitub上的Flexbugs list,可以看到Flex布局在IE糟糕表现的详细描述. 2. Column flex items set to align-items:center ove ...
- tomcat中配置ssl的http协议
问题: IDEA配置tomcat后运行时报如下错误: Error running wis-client-web: SSL HTTP Connector node not found: set up o ...
- SQL中的with check option(转)
student表: 95001 李勇 男 20 CS 95002 刘晨 女 21 IS 95003 王敏 女 18 MA 95004 张力 男 19 IS 建立视图IS_STUDENT显示“IS”系所 ...
- java文件上传 关键代码
文件上传 ##前台: form表单submit提交,form增加样式 enctype="multipart/form-data" method="post"; ...
- HTTP请求协议
请求(Request)协议 * GET请求方式 * 请求行 * http协议的版本信息 1.1 * 请求地址 - URL?key=value&key=value * 请求方式 - GET * ...