mapInit.js
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import AMapLoader from "@amap/amap-jsapi-loader";
export const MAP_KEY = "75116f653f3b2e4568116dad8cd9b899";
export const MAP_SERVICE_KEY = "d22348363c34c266f772ae9b635eef2a";
// 地图插件
export const MAP_PLUGINS = [
"AMap.PolyEditor",
"AMap.CircleEditor",
"AMap.DistrictSearch",
"AMap.Autocomplete",
"AMap.MarkerClusterer",
"AMap.MouseTool",
"AMap.Text",
"AMap.RangingTool",
"AMap.Geolocation",
"AMap.PolygonEditor",
"AMap.PolylineEditor",
"AMap.Scale",
];
// 加载地图
export const mapInit = (params) => {
return new Promise((resolve, reject) => {
let plugins = params.plugins || MAP_PLUGINS;
let version = params.version || "2.0";
if(window.AMap){
resolve(window.AMap)
return false;
}
AMapLoader.reset();
AMapLoader.load({
key: MAP_KEY, // 申请好的Web端开发者Key,首次调用 load 时必填
version: version, // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: plugins, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
})
.then((AMap) => {
window.AMap = AMap;
resolve(AMap);
})
.catch((error) => {
console.log(error);
reject(error);
});
});
};