移动端或者pc端引入地图实例 vue-amap.js

16 篇文章 0 订阅

# 在src中新建一个utils文件夹 将 maps.js 引入到文件中

## 通过 npm install vue-amap.js --save

### 在全局main.js中引入地图方法

import maps from "./utils/maps";
Vue.prototype.$maps = maps;
import VueAMap from 'vue-amap';
Vue.use(VueAMap);

VueAMap.initAMapApiLoader({
  key: 'YOUR_KEY',//高德地图key值可在高德地图api官方文档申请
  plugin: ['AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType'],
  uiVersion: '1.0.11', // 版本号
  v: "1.4.4"

});
new Vue({
  router,VueAMap,
  el: "#app",
  render: h => h(App)
}); 

#### 在template模板中也就是当前页面中

  <div class="maps" id="map">
      <el-amap
        ref="map"
        vid="amapDemo"
        :amap-manager="amapManager"
        :center="center"
        :zoom="zoom"
        :plugin="plugin"
        :events="events"
        class="amap-demo"
      ></el-amap>
      <div class="toolbar">
        <button @click="callBack()"></button>
      </div>
    </div>

###### 在当前页面中引入包

import VueAMap from "vue-amap";
let amapManager = new VueAMap.AMapManager();

######## 在data中定义

amapManager,
      zoom: 12,
      center: [121.59996, 31.197646],
      events: {
        init: o => {
          console.log(o.getCenter());
          console.log(this.$refs.map.$$getInstance());
          o.getCity(result => {
            console.log(result);
          });
        },
        moveend: () => {},
        zoomchange: () => {},
        click: e => {
          alert("map clicked");
        }
      },
      plugin: [
        "ToolBar",
        {
          pName: "MapType",
          defaultType: 0,
          events: {
            init(o) {
              console.log(o);
            }
          }
        }
      ]

完成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值