需求:在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. 思科模拟器PacketTracer7--利用一台交换机将两台pc划分到不同vlan下

    实验2—3 实验内容:将同一交换机下的两台pc划分到不同vlan中 实验工具:思科模拟器PacketTracer7 使用设备:一台交换机,两台PC 实验步骤: 一.配置网络拓扑图 注:1.连线可选择闪 ...

  2. jQuery的版本兼容问题

    之前在做头像上传的时候,使用的jQuery是1.8.2的版本,然后头像上传做完后,发现项目用的jQuery版本是3.3.1的.由于两个版本的差距太大了.所以兼容很差. 3.3.1不支持剪切头像的某些函 ...

  3. gcc/g++编译器的安装与说明

    gcc/g++编译器的安装与说明 1.gcc/g++编译器的安装 gcc yum install gcc g++ yum install gcc-c++ 2.gcc/g++的作用 将c/c++源代码编 ...

  4. vue2.0项目 calendar.js(日历组件封装)

    最近一直闲来无事,便寻思着做一下自己的个人项目,也想说能使用现在比较流行的一些mvvm框架来做,于是就选用了这样的一个技术栈vue2.0+vue-router+vuex+webpack来做,做得也是多 ...

  5. SQL Server 主键及自增长列的修改

    一.对主键的修改 主键值都会带有主键约束,当执行update操作或是其他操作的时候就会受到限制无法修改,解决的方法是:取消主键约束->删掉主键列->插入修改后的主键值. (1)取消主键约束 ...

  6. webpack中 resolve.alias 配置,@import相关踩坑

    1.在使用webpack打包项目时,可以在配置文件中配置resolve.alias来定义一些绝对路径,方便在项目中灵活使用路径,举例如下: resolve: { extensions: [‘.js‘, ...

  7. week6

    面向对象编程 class类(新式类:class xx(obj):,经典类 class xx:) 构造函数 __init__(self,ret1,ret2...) 在实例化时做一些类的初始化工作 析构函 ...

  8. css3动画怎样能从下往上慢慢升上去

    <!DOCTYPE html><html><head> <style> div { width:100px; height:100px; backgro ...

  9. LCT模板(无讲解)

    怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了. // luogu-judger-enable-o2 #include<bits/stdc++.h> using na ...

  10. Java Integer常量池——IntegerCache内部类

    个人理解,不喜勿喷,欢迎指正. 首先看下面这段代码,猜一下输出结果是什么 Integer a = 10; Integer b = 10; System.out.println(a == b); a = ...