其他分享
首页 > 其他分享> > vue使用百度地图

vue使用百度地图

作者:互联网

// bmpgl.js
export function BMPGL(ak) {
    return new Promise(function(resolve, reject) {
      window.init = function() {
        // eslint-disable-next-line
        resolve(BMapGL)
      }
      const script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = `http://api.map.baidu.com/api?v=3.0&type=webgl&ak=${ak}&callback=init`
      script.onerror = reject
      document.head.appendChild(script)
    })
  }
import { BMPGL } from "@/utils/bmpgl.js";
 BMPGL(this.ak).then((BMapGL) => {
          let map = new BMapGL.Map("container");
          let point = new BMapGL.Point(centerLat, centerRat);
          map.centerAndZoom(new BMapGL.Point(centerLat, centerRat), 15);
          //开启鼠标滚轮缩放
          map.enableScrollWheelZoom(true);
          })
        .catch((err) => {
          console.log(err);
        });

标签:map,vue,script,ak,地图,BMapGL,BMPGL,new,百度
来源: https://blog.csdn.net/qq_38847914/article/details/116938644