vue使用百度地图
程序员文章站
2022-06-15 15:52:00
...
// 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);
});
下一篇: 关于原型继承的三种方法