前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >地图功能的实现

地图功能的实现

作者头像
不爱吃糖的程序媛
发布2024-01-18 20:56:42
1080
发布2024-01-18 20:56:42
举报
效果实现:
在这里插入图片描述
在这里插入图片描述
源代码:

百度地图组件: https://dafrok.github.io/vue-baidu-map/#/zh/start/usage

代码语言:javascript
复制
<!-- 地图弹出框 -->
    <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>
代码语言:javascript
复制
 //打开地图弹出框
    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;
    },
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-01-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果实现:
  • 源代码:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档