高德地图-----加载地图

准备工作

  1. 在public中的index.html中初始化地图
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
  1. 在 .eslintrc.js 中配置AMap和AMapUI
globals: {
    "AMap": "true",
    "AMapUI":"true",
  }
  1. 创建一个公共组件map

  2. 在组件的mounted生命周期中加载地图

map组件内容

html

<template>
  <div class="m-map">
    <div id="js-container" class="map">正在加载数据 ...</div>
  </div>
</template>

js

export default {
  name: 'mapIndex',
  props: ['lat', 'lng'],
  data () {
    return {
      AMap: null,
      map: null,
    }
  },
  mounted () {
    this.initMap()
  },
  methods: {
    // 实例化地图
    initMap () {
      this.map = new AMap.Map('js-container', {
        zoom: 10, // 设置地图显示的缩放级别
        center: [this.lng, this.lat] // 设置地图中心点坐标
      })
    }
  }

}

css

.m-map{ min-width: 500px; min-height: 300px; position: relative; }
.m-map .map{ width: 100%; height: 100%; }

调用

<scottMap lat="31.86" lng="117.27" style="margin-left:11vw;width:90vw;height:90vh"></scottMap>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值