vue+elementui+百度地图

1.安装vue-baidu-map组件

cnpm -i --save vue-baidu-map

2.新建vue界面

需要自己获取秘钥
秘钥的获取方式,官网获取
获取成功以后,填写到ak位置上

<!--百度地图-->
<template>
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card shadow="never" class="mapBox1">
          <baidu-map :center="center" :zoom="zoom" @ready="handler" class="map">
            <el-button class="button" @click="setScreenfull" icon="el-icon-zoom-in" circle></el-button>
            <!-- 控件将定位到地图的右上角 -->
            <bm-scale anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-scale>
            <!-- 平移缩放组件 -->
            <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
            <!-- 缩略图 -->
            <bm-overview-map anchor="BMAP_ANCHOR_BOTTOM_RIGHT" :isOpen="true"></bm-overview-map>
            <!-- 定位 -->
            <bm-geolocation anchor="BMAP_ANCHOR_BOTTOM_LEFT" :showAddressBar="true"
                            :autoLocation="true"></bm-geolocation>
            <bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']"
                         anchor="BMAP_ANCHOR_TOP_LEFT"></bm-map-type>
            <!-- 示例位置 -->
          </baidu-map>
        </el-card>
      </el-col>
    </el-row>
</template>

<script>
  import screenfull from 'screenfull'
  import BaiduMap from 'vue-baidu-map'
  import Vue from 'vue'

  Vue.use(BaiduMap, {
    ak: '自己的钥匙'
    // 我自己申请的钥匙 ak 'QFgFQorrB84maOZh0pPGC8kUiP0mGIhx'
  })
  export default {
    data () {
      return {
        center: {
          lng: 0,
          lat: 0
        },
        zoom: 3
      }
    },
    methods: {
      setScreenfull () {
        const element = document.querySelector('.map')
        if (!screenfull.isEnabled) {
          // 如果不允许进入全屏,发出不允许提示
          this.$message({
            message: '暂不不支持全屏',
            type: 'warning'
          })
          return false
        }
        screenfull.toggle(element)
      },
      // 百度地图
      handler ({
        BMap,
        map
      }) {
        map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放
        this.pt = new BMap.Point(116.117, 39.909)
        // 中心点
        this.center.lng = 117.18
        this.center.lat = 34.27
        this.zoom = 11.5
      }
    }
  }
</script>

<style scoped>
  /* 深度作用选择器  */
  .el-card /deep/ .el-card__body {
    padding: 0px;
  }
  .mapBox1 {
    line-height: 550px;
  }
  .map {
    opacity: 0.9;
    margin-right: 10px;
    height: 550px;
  }
  .button {
    z-index: 2;
    position: absolute;
    top: 30%;
    left: 88%;
  }
</style>
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值