vue baidu map之获取选中点的经纬度
需求:在vue项目中通过点击按钮,弹出百度地图的弹框,用户选择地图上的点或者通过搜索关键字选点,点击确认 关闭弹窗 得到经纬度
效果:
vue baidu map api链接 : https://dafrok.github.io/vue-baidu-map/#/zh/index
使用之前需要先申请百度服务密钥
由于要多次用到地图选点,故封装成一个简单的组件,在需要的地方进行引入,弹窗用的是iview的modal,本例中用的是局部引入vue baidu map
在需要的地方引入组件
eg: <mapComponent v-model="showMapComponent" v-on:cancel="cancelMap" v-on:map-confirm="confirmMap"></mapComponent>
confirmMap中得到回传数据,当然,可根据实际需要回传需要的数据,这里只回传了经纬度
附:源代码
<!-- 使用说明:v-on: map-confirm,参数为array数组,传递经纬度值v-on cancel 取消时发出事件 --> <template><div style="padding-top:50px; border:1px solid red"><Modal @on-cancel="cancel" v-model="showMapComponent" width="800" :closable="false" :mask-closable="false"><baidu-map v-bind:style="mapStyle" class="bm-view" ak="你的密钥":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 slot="footer" style="margin-top: 0px;"><Button @click="cancel" type="ghost"style="width: 60px;height: 36px;">取消</Button><Button type="primary" style="width: 60px;height: 36px;" @click="confirm">确定</Button></div></Modal></div> </template> <script>import {BaiduMap, BmControl, BmView, BmAutoComplete, BmLocalSearch, BmMarker} from 'vue-baidu-map'export default {components: {BaiduMap,BmControl,BmView,BmAutoComplete,BmLocalSearch,BmMarker},data: function () {return {showMapComponent: this.value,keyword: '',mapStyle: {width: '100%',height: this.mapHeight + 'px'},center: {lng: 116.404, lat: 39.915},zoom: 15}},watch: {value: function (currentValue) {this.showMapComponent = currentValueif (currentValue) {this.keyword = ''}}},props: {value: Boolean,mapHeight: {type: Number,default: 500}},methods: {/**** 地图点击事件。*/getClickInfo (e) {this.center.lng = e.point.lngthis.center.lat = e.point.lat},syncCenterAndZoom (e) {const {lng, lat} = e.target.getCenter()this.center.lng = lngthis.center.lat = latthis.zoom = e.target.getZoom()},/**** 确认*/confirm: function () {this.showMapComponent = falsethis.$emit('map-confirm', this.center)},/**** 取消*/cancel: function () {this.showMapComponent = falsethis.$emit('cancel', this.showMapComponent)}}} </script><style scoped> .serachinput{width: 300px;box-sizing: border-box;padding: 9px;border: 1px solid #dddee1;line-height: 20px;font-size: 16px;height: 38px;color: #333;position: relative;border-radius: 4px;-webkit-box-shadow: #666 0px 0px 10px;-moz-box-shadow: #666 0px 0px 10px;box-shadow: #666 0px 0px 10px; } </style>
转载于:https://www.cnblogs.com/moqq/p/8489299.html
vue baidu map之获取选中点的经纬度相关推荐
- Vue Baidu Map 实现Vue版本地图轨迹回放(App端)
Vue Baidu Map 地图轨迹回放 Vue Baidu Map 简介 Vue Baidu Map 安装 1.NPM 2.CDN Vue Baidu Map 引用 BmlLushu 引用 BmlL ...
- Vue中使用百度地图Vue Baidu Map(vue-baidu-map)
最近负责的一个vue项目中需要调用百度地图api做标记打点的需求,记录一下: vue-baidu-map 官方地址 一.插件的安装 1.npm 安装 $ npm install vue-baidu-m ...
- Vue Baidu Map组件: 点、线、多边形、圆形、撤销、返回
话不多说,直接上代码: 参考官网代码改编:https://dafrok.github.io/vue-baidu-map/#/zh/guide/painting 效果图 index.vue <te ...
- Vue中用 Vue Baidu Map 绘制地图
1.先贴上官网案例 https://dafrok.github.io/vue-baidu-map/#/zh/guide/painting 官网的东西,没有百度地图开放平台上面的东西齐全,考虑到vue ...
- VUE预览PDF文件并利用pdf.js获取鼠标选中的文字和搜索,在iframe中获取选中文字,监听鼠标事件,右键菜单
一.VUE预览PDF文件并利用pdf.js获取鼠标选中的文字和搜索 需求实现:vue实现预览pdf文件,获取到鼠标选中的文字数据.调用pdf.js自带的搜索方法实现搜索功能(后期可以调用该接口满足其他 ...
- vue使用百度地图获取位置信息
vue使用百度地图获取位置信息 最近再做H5页面,就一个单页面,进来的时候,要获取地理位置,上代码 1.使用srcipt不受同源策略的影响,来获取百度api 写在了一个bmap.js里面,onBMap ...
- html select 多选取值,下拉框多选实现 jquery-multiselect 并获取选中的值
首选引入js文件 Option 1 Option 2 Option 3 Option 4 Option 5 Option 6 Option 7 下拉列表 $(function(){ $("# ...
- treeselect只选了分支节点全选_vue Treeselect 树形下拉框:获取选中节点的ids和lables操作...
API: https://vue-treeselect.js.org/#events 1.ids: 即value 1.lable: 需要用到方法:@select(node,instanceId) 和 ...
- el-radio(自定义样式)获取选中label值 + 选中状态 + 拼接String + post提交 - 踩坑篇
疑问: vue中怎么获取radio的选中值 .选中状态? 效果图 · 截图: 注意点: 需要使用 label传值,后台接什么,你就传什么 (这个需要和后台事先确定好) 使用@change事件,监听鼠标 ...
最新文章
- 学习:erlang开源项目。
- Mybatis中的jdbcType的作用
- 异常org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 11; 注释中不允许出现字符串 --。的原因...
- python区块链开发_Fabric区块链Python开发详解
- 面试题-ASP 与 ASP.Net的区别?
- IDEA 插件开发入门教程 1
- JAVA中.jsp模板文件AJAX异步请求 - 数据渲染问题
- UE4 AnimMontage
- python爬虫需要学哪些知识_Python爬虫需要学习那些东西?
- Linuxbt下载工具-Transmission-支持命令行!!!
- rebase和merge区别
- 2022-4-21 适用于Orange Pi(香橙派) Zero/Zero2的kali 操作系统分享
- WPF中使用Winform控件
- 【论文精读】基于周期编码深度自编码器的心肺音盲单耳声源分离
- linux系统能看抖音吗,用电脑如何刷抖音?电脑刷抖音方法你知多少
- HDU 1236 排名(Microsoft_zzt)
- 意念机Umind及其控制无人机
- L*MM 文件管理器小结
- 中科大文献管理笔记——文献调研起步
- 一个完整的新闻发布系统
热门文章
- 前端开发中的调试技巧
- GNU C内嵌汇编学习笔记
- php数组转化js数组格式化,php数组转换成js数组
- 【Flink】Flink AM container is launched, waiting for AM container to Register with RM
- 【Spring 】Synchronized锁在Spring事务管理下,为啥还线程不安全?
- windows下curl
- IDEA多Module的Language Level的问题
- 《spring-boot学习》-05-spring boot中redis应用
- jmx监控之Dubbo
- Dubbo(RPC原理、Dubbo架构负载均衡配置方式)(2)