赞
踩
安装:npm i vue-baidu-map
使用:
在main.js文件中
import BaiduMap from ‘vue-baidu-map’
Vue.use(BaiduMap, {
ak: 'xx //项目组在百度地图官网申请ak
})
代码如下:
<template> <div> <baidu-map @click="mapClick" @moving="syncCenterAndZoom" id="map" @ready="handler" :center="center" :zoom="10" > <bm-marker :position="center"> <bm-label content="当前位置" :labelStyle="{ color: 'blue', fontSize: '14px' }" :offset="{ width: -30, height: 30 }" /> </bm-marker> <template v-for="(marker, index) in points"> <bm-marker :key="index" :icon="{ url: require('../../assets/logo.png'), size: { width: 15, height: 15 }, opts: { imageSize: { width: 15, height: 15, }, }, }" :position="{ lng: marker.lng, lat: marker.lat }" @click="lookDetail(marker)" > </bm-marker> </template> <bm-info-window :position="{ lng: infoWindow.info.lng, lat: infoWindow.info.lat }" :show="isShowFlag" > <p class="names"> <span class="fontNames">名称:</span>{{ infoWindow.info.name }} </p> <p class="adds"> <span class="fontNames">地址:</span>{{ infoWindow.info.address }} </p> </bm-info-window> </baidu-map> </div> </template> <script> export default({ name:"maps", data() { return { checklist: [], isShowMap: false, center: { lng: 0, lat: 0, }, zoom: 0, isWindowshow: false, points: [], showWindowName: '', infoWindow: { info: {}, }, isShowFlag: false, }; }, methods: { //点击地图上的某个坐标 mapClick(e) { this.center.lng = e.point.lng; this.center.lat = e.point.lat; }, //移动地图上的某个坐标 syncCenterAndZoom(e) { const { lng, lat } = e.target.getCenter(); this.center.lng = String(lng); this.center.lat = String(lat); this.zoom = e.target.getZoom(); }, //显示地图 showMaps() { this.isShowMap = true; }, //查看全量点详情 lookDetail(marker) { marker.showFlag = true; this.isShowFlag = true; this.infoWindow.info = marker; }, //打开地图当前点的弹窗信息 infoWindowOpen(val) { this.showWindowName = val.custName; this.isWindowshow = true; }, //关闭地图当前点的弹窗信息 infoWindowClose() { this.isWindowshow = false; }, //添加全量点 addPoints() { this.points = [ { lng: 114.3159, lat: 22.7859, name: '深圳公司', address: '深圳', showFlag: false, //flag放在每一条数据里 }, { lng: 114.3975, lat: 22.7258, name: '广州市华利鑫业贸易有限公司', address: '广州市福田区车公庙泰然九路盛唐商务大厦东座14层1406(公限办公)', showFlag: false, }, { lng: 114.1179, lat: 22.5856, name: '东莞公司', address: '东莞', showFlag: false, }, { lng: 114.1499, lat: 22.7023, name: '香港公司', address: '香港', showFlag: false, }, { lng: 114.1368, lat: 22.6385, name: '澳门公司', address: '澳门', showFlag: false, }, { lng: 114.0881, lat: 22.6474, name: '惠州公司', address: '惠州', showFlag: false, }, { lng: 113.8823, lat: 22.5965, name: '珠海公司', address: '珠海', showFlag: false, }, { lng: 114.0298, lat: 22.6232, name: '上海公司', address: '上海', showFlag: false, }, { lng: 114.0542, lat: 22.7293, name: '北京公司', address: '北京', showFlag: false, }, { lng: 114.1137, lat: 22.6912, name: '厦门公司', showFlag: false, }, ]; }, //地图初始化加载 handler() { let that = this; that.zoom = 15; that.center.lat = '22.54845664'; that.center.lng = '114.06455184'; }, }, created() { this.addPoints(); }, }) </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。