vue & 百度地图:使用百度地图
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=xxxxxxxxxxxxxxxxxxxxxxx"></script>
<title>voidvue_map</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
ak填的是你自己申请的密钥。
百度地图的开发者平台上有详细的说明。
mymap.vue
<template>
<div class="hello">
<div style="margin-bottom:10px">
<button @click="clickStart('jinting')">设定坐标</button>
<button @click="clickEnd">退出设定</button>
</div>
<!-- map start -->
<div style="" id="dituContent" class="ditu-content"></div>
<!-- map end -->
</div>
</template> <script>
export default {
name: 'mymap',
data () {
return {
polygons: [],
clickCity: '',
polyline: null,
marker: null,
cityName: '',
status: 'none',
centerPoint: [],
savePointsArray: [],
savePointsString: '',
jinting: '', mapObj:null
}
},
mounted () {
this.initMap()
},
methods:{
clickEnd(){
console.log('======================== CLICK END ======================')
this.clickCity = ''
this.status = 'none'
},
initMap () {
this.createMap() ; //创建地图 },
createMap(){
let self = this
let m = new BMap.Map("dituContent")
let point = new BMap.Point(120.49,31.15)
m.centerAndZoom(point,12)
m.setCurrentCity("苏州")
this.setMapEvent(m)
},
setMapEvent(m){
m.enableDragging();//启用地图拖拽事件,默认启用(可不写)
m.enableScrollWheelZoom();//启用地图滚轮放大缩小
m.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
m.enableKeyboard();//启用键盘上下左右键移动地图 this.addMapControl(m);//向地图添加控件
},
addMapControl(m){
//向地图中添加缩放控件
let ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
m.addControl(ctrl_nav);
//向地图中添加缩略图控件
let ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
m.addControl(ctrl_ove);
//向地图中添加比例尺控件
let ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
m.addControl(ctrl_sca); this.mapObj = m
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.ditu-content{
width:70%;
height:600px;
border:#ccc solid 1px;
margin:0 auto;
}
.pointwords{
word-wrap: break-word;
text-align: center;
padding: 0 20px;
}
.button{
height: 100px;
}
</style>
关于BMap地图对象:
原本我打算把它作为参数传到别的函数里,但发现这样在使用上还是不太方便,所以还是把它放到了vue页面实例的data中了。
参考:
https://blog.csdn.net/qq_38903950/article/details/78022174?locationNum=7&fps=1
vue & 百度地图:使用百度地图的更多相关文章
- 百度地图api根据地图缩放等级显示不同的marker点,功能二
功能一里面有marker点后台的代码 根据地图的缩放等级显示不同marker点的坐标JSP代码 <%@ page language="java" contentType=&q ...
- GPS定位为什么要转换处理?高德地图和百度地图坐标处理有什么不一样?
GPS定位为什么要转换处理?高德地图和百度地图坐标处理有什么不一样? 先了解一下 高德地图 采用: GCJ-02 (不可逆) 百度百科: http://baike.baidu.com/link?url ...
- iOS打开百度地图、高德地图导航
1.判断手机里是否已经安装了百度地图或者高德地图: BOOL hasBaiduMap = NO; BOOL hasGaodeMap = NO; if ([[UIApplication sharedAp ...
- 百度地图API自定义地图
http://api.map.baidu.com/lbsapi/creatmap/index.html http://developer.baidu.com/map/index.php?title=w ...
- js调用百度地图API创建地图,搜索位置
实现代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <met ...
- iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/
http://zanderzhang.gitcafe.io/2015/09/19/iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/ 百度外卖选择送货地址: 饿了么选择送货地 ...
- 关于百度地图API的地图坐标转换问题
原文:关于百度地图API的地图坐标转换问题 我在之前的文章利用html5获取经纬度并且在百度地图中显示位置中使用了百度地图的API来显示html5获取的地理位置,在文中我说过这样的话,我说百度地图的准 ...
- iOS 百度地图监听地图状态
百度地图提供了地图状态的对象BMKMapStatus ///此类表示地图状态信息 @interface BMKMapStatus : NSObject { float _fLevel; // 缩放比例 ...
- 网页嵌入百度地图和使用百度地图api自定义地图的详细步骤
在网页中插入百度地图 如果想在自己的网页上面加入百度地图的话,可以用百度地图的api.具体使用方法如下: 第一步:进入百度创建地图的网站http://api.map.baidu.com/lbsapi/ ...
- Android百度地图之显示地图
添加地图显示 一.在百度官网下载相关的SDK (网址:http://developer.baidu.com/map/sdkandev-download.htm) 解压下载好的BaiduMap_Andr ...
随机推荐
- 富文本插件tinymce初始化配置参数说明
{ language: _this.language, // 显示语种 selector: #${_this.tinymceId}, // 容器的id height: _this.height, // ...
- nuget 包是如何还原包的
nuget 是如何还原包的 Intro 一直以来从来都是用 nuget 包,最近想折腾一个东西,需要自己搞一个 nuget 包的解析,用户指定 nuget 包的名称和版本,然后去解析对应的 nuget ...
- python中列表,元组,字符串 互相转换
#-*-coding:utf-8-*- #1.字典dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 's ...
- 入门大数据---Elasticsearch搭建与应用
项目版本 构建需要: JDK1.7 Elasticsearch2.2.1 junit4.10 log4j1.2.17 spring-context3.2.0.RELEASE spring-core3. ...
- 为什么 group by后面 必须跟selecte 后面的除了聚集函数外的所有字段
如:SELECT store_name, SUM(Sales) FROM Store_Information GROUP BY store_name 可以而SELECT store_name, add ...
- 如何用HMS Nearby Service给自己的APP开发一个名片交换功能?
在工作和生活中,遇见新的同事或者合作伙伴,交换名片是一个常见的用户需求,纸质名片常忘带.易丢失,是客户的一个痛点.因此,市场上出现了很多交换电子名片的APP和小程序.那么,如何给自己的APP开发一 ...
- Python之浅谈深浅拷贝
目录 深浅拷贝 拷贝 浅拷贝 深拷贝 深浅拷贝 拷贝 s=['tim','age'] s2=s #这里的s2列表指向与s相同的id 当s2为s的拷贝对象时,s内的可变类型变化,s2变化;s内的不可变类 ...
- IntelliJ IDEA快速实现Docker镜像部署
一.Docker开启远程访问 [root@izwz9eftauv7x69f5jvi96z docker]# vim /usr/lib/systemd/system/docker.service #修改 ...
- 在 XUnit 中使用依赖注入
在 XUnit 中使用依赖注入 Intro 之前写过一篇 xunit 的依赖注入相关的文章,但是实际使用起来不是那么方便 今天介绍一个基于xunit和微软依赖注入框架的"真正"的依 ...
- JAVA的8种基本数据类型分析
基本数据类型(8个) 1.整数类型(4个) 字节个数 取值范围 byte(字节) 1(8位) -2^7~2^7-1 short(短整型) 2(16位) -2^15~2^15-1 int(整形) 4 ...