百度地图组件: https://dafrok.github.io/vue-baidu-map/#/zh/start/usage
<!-- 地图弹出框 -->
<el-dialog
:visible.sync="mapDialogVisible"
:show-close="true"
width="50%"
height="650px"
>
<div class="map-search-line">
<el-input
v-model="mapKeyword"
style="width: 100%; margin-right: 20px"
placeholder="请输入地点"
/>
<!-- <el-button type="primary">搜索</el-button> -->
</div>
<div class="map-container-box">
<baidu-map
v-if="mapDialogVisible"
class="map-container"
:center="{ lng: mapSiteObj.longitude, lat: mapSiteObj.latitude }"
:zoom="16"
@moving="syncCenterAndZoom"
@moveend="syncCenterAndZoom"
@zoomend="syncCenterAndZoom"
>
<bm-local-search
:keyword="mapKeyword"
:auto-viewport="false"
@infohtmlset="infoSelectHanlder"
@markersset="showSuggestion"
></bm-local-search>
<bm-marker
:position="{ lng: mapSiteObj.longitude, lat: mapSiteObj.latitude }"
:dragging="true"
@dragend="markerDragOver"
>
<!-- <bm-info-window
:show="show"
@close="infoWindowClose"
@open="infoWindowOpen"
style="font-size: 13px"
></bm-info-window> -->
</bm-marker>
</baidu-map>
</div>
<div class="map-buttons-container">
<el-button
v-show="showFooterButtons"
type="primary"
@click="mapSaveAndClose"
>保存并返回</el-button
>
<el-button v-show="showFooterButtons" @click="mapCancelAndClose"
>取消</el-button
>
</div>
</el-dialog>
//打开地图弹出框
openMap() {
const { longitude, latitude } = this.siteForms;
if (!longitude || !latitude) {
this.mapSiteObj.longitude = 114.079646;
this.mapSiteObj.latitude = 22.714196;
} else {
this.mapSiteObj.longitude = this.siteForms.longitude;
this.mapSiteObj.latitude = this.siteForms.latitude;
}
this.mapDialogVisible = true;
},
mapCancelAndClose() {
this.mapDialogVisible = false;
},
mapSaveAndClose() {
this.siteForms.longitude = this.mapSiteObj.longitude;
this.siteForms.latitude = this.mapSiteObj.latitude;
this.mapDialogVisible = false;
this.$refs.siteForm.validate();
},
syncCenterAndZoom(e) {
const { lng, lat } = e.target.getCenter();
this.mapSiteObj.longitude = lng;
this.mapSiteObj.latitude = lat;
},
markerDragOver(e) {
const { lng, lat } = e.point;
this.mapSiteObj.longitude = lng;
this.mapSiteObj.latitude = lat;
},
handlerMap({ BMap, map }) {
console.log(BMap, map);
this.mapSiteObj.longitude = 116.404;
this.mapSiteObj.latitude = 39.915;
},