vue baiduMap

1、引入

/** 百度地图**/
import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: '秘钥'
})

2、Vue页面

    • 从父页面传入的经纬度参数,在地图页面直接展示坐标
<template>
	<baidu-map class="map" :center="{lng: action.longitude, lat: action.latitude}" :zoom="16">
        <bm-marker :position="{lng: action.longitude, lat: action.latitude}" @click="infoWindowOpen()">
        </bm-marker>
        <bm-info-window :show="windowShow" @close="closeClick" :position="{lng: action.longitude, lat: action.latitude}" style="width:100px;height:60px;">
            <div>
                {{'经度: ' + action.longitude }}
            </div>
            <div>
                {{'纬度: ' + action.latitude }} 
            </div>
        </bm-info-window>

        <!-- 控件将定位到地图的右上角 -->
        <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-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']"
                        anchor="BMAP_ANCHOR_TOP_LEFT"></bm-map-type>
        
    </baidu-map>
</template>
<script>
	 export default {
    name: 'JBaiduMap',
    components: {
      XrCreate,
    },

      props: {
        action:{}
    },
    data () {
      return {
        windowShow:true,
        titleMap:'地图',
      }
    },
    methods: {
        infoWindowOpen(){
            this.windowShow = true;
        },
        closeClick(){
          this.windowShow = false;
        },

        close() {
        this.$emit('close')
      },

      // 百度地图
    //   handler ({
    //     BMap,
    //     map
    //   }) {
    //       console.log(this.action)
    //     map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放
    //     // this.pt = new BMap.Point(116.117, 39.909)
    //     // 中心点
    //     this.center.lng = this.action.longitude
    //     this.center.lat = this.action.latitude
    //     this.zoom = 11.5
    //   }

    }
  }
</script>
<style scoped>

  .mapBox1 {
    line-height: 550px;
  }
  .map {
    opacity: 0.9;
    margin-right: 10px;
    height: 100%;
  }
  /* .button {
    z-index: 2;
    position: absolute;
    top: 30%;
    left: 88%;
  } */
</style>

3、效果
在这里插入图片描述
Vue BaiduMap 官方文档:https://dafrok.github.io/vue-baidu-map/#/zh/overlay/info-window

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值