百度地图实用案例
1、創建一個js文件
export function BMPGL(ak) {return new Promise(function (resolve, reject) {window.init = function () {// eslint-disable-next-lineresolve(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 = rejectdocument.head.appendChild(script)}) }2、在組件中使用
const init = () => {BMPGL('ak值').then((BMapGL) => {let map = new BMapGL.Map('container')// 創建點坐標 axios => res 獲取的初始化定位坐標let point = new BMapGL.Point(116.404, 39.915)// 初始化地圖,設置中心點坐標和地圖級別map.centerAndZoom(point, 15);})}總結
- 上一篇: 股票代码前面有个r
- 下一篇: OpenStack精华问答 | Open