需求:在vue项目中,实现用户选择地图绘点或者通过搜索关键字选点

<template>
<div id="home">
<h2>首页地图</h2>
<div>
<input type="text" v-model="city" class="city">
<input type="button" v-model="cityBtn" class="cityBtn" value="选定" @click="mapBtn">
</div>
<div id="allmap">
<baidu-map v-bind:style="mapStyle" class="bm-view" ak="GPO8jLk2SoDXF5nnaOdDudHxIsMVEK6V"
:center="center" :zoom="zoom" :scroll-wheel-zoom="true" @click="getClickInfo"
@moving="syncCenterAndZoom"
@moveend="syncCenterAndZoom"
@zoomend="syncCenterAndZoom">
<bm-view style="width: 100%; height:500px;"></bm-view>
<bm-marker :position="{lng: center.lng, lat: center.lat}" :dragging="true"
animation="BMAP_ANIMATION_BOUNCE"></bm-marker> <!-- 红点 -->
<bm-control :offset="{width: '10px', height: '10px'}">
<bm-auto-complete v-model="keyword" :sugStyle="{zIndex: 999999}">
<!-- <input type="text" placeholder="请输入搜索关键字" class="serachinput"> -->
</bm-auto-complete>
</bm-control>
<bm-local-search :keyword="keyword" :auto-viewport="true" style="width:0px;height:0px;overflow: hidden;"></bm-local-search>
</baidu-map>
</div>
</div>
</template>
<script>
import {BaiduMap, BmControl, BmView, BmAutoComplete, BmLocalSearch, BmMarker} from 'vue-baidu-map'
export default {
components: {
BaiduMap,
BmControl,
BmView,
BmAutoComplete,
BmLocalSearch,
BmMarker
},
data() {
return {
city:'',
cityBtn:'选定',
keyword: '',//填写选择的地址
mapStyle: {
width: '100%',
height: this.mapHeight + 'px'
},
center: {lng: 110, lat: 39.915},
zoom: 11
};
},
methods:{
getClickInfo(e){
// debugger
this.center.lng = e.point.lng
this.center.lat = e.point.lat
console.log(e.point.lng,e.point.lat)
},
syncCenterAndZoom (e) {
// debugger
const {lng, lat} = e.target.getCenter()//地图当前的经纬度
this.center.lng = lng
this.center.lat = lat
this.zoom = e.target.getZoom()//地图当前的缩放比例
},
mapBtn(){
this.keyword = this.city
}
}
};
</script>
<style>
.bm-view {
margin: 0 auto;
width: 800px;
height: 500px;
}
.city{
width: 150px;
height: 30px;
border: 1px solid #dddddd;
}
.cityBtn{
width: 50px;
height: 35px;
background-color:green;
color: #ffffff;
border:1px solid green;
vertical-align: top;
}
</style>

  

Vue Baidu Map局部注册实现和地图绘点的更多相关文章

  1. vue2.0之Vue Baidu Map 局部注册使用

    文档地址:https://dafrok.github.io/vue-baidu-map/#/zh/start/usage 局部注册 <template> <baidu-map id= ...

  2. vue Baidu Map --- vue百度地图插件

    vue Baidu Map 官网:https://dafrok.github.io/vue-baidu-map/#/zh/start/installation javascript 官网:http:/ ...

  3. Vue组件全局/局部注册

    全局注册 main.js中创建 Vue.component('button-counter', { data: function () { return { count: 0 } }, templat ...

  4. Vue Baidu Map 插件的使用

    最近在做一个项目,技术采用的是Vue.js套餐,有个百度地图的需求,当时,大脑宕机,立马去引入百度地图API,当时想到两种方法,一种是在index.html中全局引入js,此法吾不喜,就采用了第二种异 ...

  5. 使用Vue Baidu Map对百度地图实现输入框搜索定位

    前端时间需要在页面的输入框输入地址,搜索并在百度地图上获取选定结果的坐标,前端使用了Vue + Element-ui,地图方面直接使用了封装好的百度地图vue组件-vue-baidu-map     ...

  6. Vue 全局注册逐渐 和 局部注册组件

    //定义一个名为 button-counter 的新组件 Script: Vue.component('button-counter',{//button-counter 这个是组件的名字 data: ...

  7. vue 组件 全局注册和局部注册

    全局注册,注册的组件需要在初始化根实例之前注册了组件: 局部注册,通过使用组件实例选项注册,可以使组件仅在另一个组件或者实例的作用域中可用: 全局组件 js Vue.component('tab-ti ...

  8. vue全局注册与局部注册的写法

    vue全局注册是每个实例化的vue都可以使用,而局部则是实例化注册的那个可以用.举个例子,看看写法: <div id="app"> <p>页面载入时,inp ...

  9. 百度地图实现车辆轨迹移动播放(baidu map api)

    开发技术:jquery,js baidu map api,json,ajax QQ1310651206

随机推荐

  1. php中把美国时间转为北京时间的自定义

    我的服务器北京时间,php调用的时间: date.timezone ="America/Chicago" 这是美国这边的一个时间,有的时候跟北京相差13个小时,有的时候跟北京时间相 ...

  2. RTK与差分测量的区别

    差分GPS定位原理 它使用一台 GPS基准接收机(基准站)和一台用户接收机(移动站),利用实时或事后处理技术,就可以使用户测量时消去公共的误差源 —卫星轨道误差.卫星钟差.大气延时.多路径效应.特别提 ...

  3. 【C/C++】C++11 Move, Forward

    左值与右值 Lvalue:可以出现在 operator= 左边的 Rvalue:只能出现在operator= 右边的 ; int a = b; a = b; a = a + b; a + b = a; ...

  4. kafka 常用参数

    通常的讲:kafka 的参数分为 Broker Configs 和 Topic-Level Configs,以 min.insync.replicas 为例,可以在 broker 和 topic 级别 ...

  5. IPFS扫盲

    第二届深圳区块链技术与应用大会暨展览会,深圳区块链存储与IPFS技术应用大会暨展览会于2019年4月9日在深圳会展中心6号馆举行.那么这个IPFS是什么?和区块链有什么关系?有什么用?又怎么用呢?接下 ...

  6. 安装vue-cli时-4058报错的解决方法

    一.报错信息 安装vue-cli时-4058报错 二.解决办法 1.安装淘宝镜像 npm --registry https://registry.npm.taobao.org info undersc ...

  7. Apache Spark 3.0 将内置支持 GPU 调度

    如今大数据和机器学习已经有了很大的结合,在机器学习里面,因为计算迭代的时间可能会很长,开发人员一般会选择使用 GPU.FPGA 或 TPU 来加速计算.在 Apache Hadoop 3.1 版本里面 ...

  8. JAVA的入门代码

    public class HelloWord{ public static void main(String[] args){ System.out.println("你好,java&quo ...

  9. docfx chocolatey安装方法

    这两天在git下载的docfx.zip .在安装过程中总是闪退,而加入环境变量后,执行提示:config file  docfx.json does not exist.所以我选择chocolatey ...

  10. Java final类&所有构造方法均为private的类(类型说明符&访问控制符)

    1. final是类型说明符,表示关闭继承,即final类不能有子类: 但final类可能可以在类外创建对象(即final类的构造方法可以不是private型): 在同一包中时,可以在任何另外一个类中 ...