创建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=1.0&type=webgl&ak=${ak}&callback=init
script.src = “https://api.map.baidu.com/api?type=webgl&v=1.0&ak=“申请的key”&callback=init”
script.onerror = reject
document.head.appendChild(script)
}) }
引入bmpgl.js文件
**import { BMPGL } from "./bmpgl.js"**
uni.getLocation({
type: "wgs84",
geocode: true,
altitude: true,
isHighAccuracy: true,
scale: 16,
success(res) {
BMPGL().then((BMapGL) => {
//可以操作BMapGL等其方法,例如:
const pointBak = new BMapGL.Point(res.longitude, res.latitude);
const convertor = new BMapGL.Convertor();
}
}
})
CSDN看到的一篇,找不到了,无法提供原创链接,原创抱歉了,仅在此记录一下
本文介绍如何通过创建和引入bmpgl.js文件来加载百度WebGL地图。利用Promise实现异步加载地图API,并通过获取地理位置信息后初始化地图。



9207

被折叠的 条评论
为什么被折叠?



