mapInit.js
1.14 KB
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "@/constant";
export const mapInit = params => {
return new Promise((resolve,reject) => {
let options = params || {};
// let plugins = options.plugins|| CONSTANT.MAP_PLUGINS;
// let version = options.version || '2.0';
if(window.AMap){
resolve(window.AMap)
return false;
}
let mapConfig ={...options};
mapConfig.key = CONSTANT.MAP_KEY; // 申请好的Web端开发者Key,首次调用 load 时必填
mapConfig.version = options.version || '2.0';; // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
mapConfig.plugins = options.plugins|| CONSTANT.MAP_PLUGINS;// 需要使用的的插件列表,如比例尺'AMap.Scale'等
if(options.AMapUI){
mapConfig.AMapUI = options.AMapUI;
}
AMapLoader.reset();
AMapLoader.load(mapConfig).then((AMap) => {
window.AMap = AMap;
resolve(AMap);
})
.catch((error) => {
console.log(error);
reject(error);
});
})
}