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 ...
随机推荐
- day_41_mysql
学习目标 学习目标 01. 数据库的介绍 02. 数据库的类型 关系型数据库(RDBMS) 非关系型数据库(NoSQL) 02.1 关系型数据库核心元素 03. MySQL的基本介绍 04. 常用入门 ...
- c++重要知识点
C++重要知识点精华总结 cin的使用: 1>cin>>a;键盘读入数据赋值给a; 1>程序的输入都建有一个缓冲区,即输入缓冲区.一次输入过程是这样的,当一次键盘输入结束时会将 ...
- Tensorflow(添加噪声的方式)
在去噪自编码器中,模型的输入是原始的输入经过某种形式的加噪过程后的衰弱的形式,所以加噪声一般分为:加高斯白噪声,掩模噪声,椒盐噪声. 1.加性高斯噪声 self.scale = tf,placehol ...
- python输入整数
#!/usr/bin/env python#ecoding=utf-8'''Created on 2017年11月2日 @author: James zhan''' def fun(n): if n= ...
- android控件基本布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...
- Python用起来极度舒适的强大背后
当你使用len(a)获取a的长度,使用obj[key]获取一个key的值时的畅快和舒适,在于Python庞大的设计思想(Pythonic). 而obj[key]背后其实是__getitem__方法,P ...
- [数]昨天欠下的一道立体几何题HDU-4741
并没有做到这道题,后来听学长说了题意,总之就是立体几何嗯 看了好几份题解,是的我知道是异面线段的距离了,可是看码完全不明orz. 这时候出现了一份清晰易懂甚至给出了公式来源的blog╰(*°▽°*)╯ ...
- angular-cli.json常见配置
{ "project": { "name": "ng-admin", //项目名称 "ejected": false / ...
- Class的 getSuperclass与getGenericSuperclass区别
一.getSuperclass 返回直接继承的父类(由于编译擦除,没有显示泛型参数) Class<? super T> getSuperclass() 返回表示此 ...
- Python 字典删除元素clear、pop、popitem
同其它python内建数据类型一样,字典dict也是有一些实用的操作方法.这里我们要说的是字典删除方法:clear().pop()和popitem(),这三种方法的作用不同,操作方法及返回值都不相同. ...