refactor(amap): 优化高德地图sdk 加载方式

This commit is contained in:
thinkinggis 2020-08-27 16:31:03 +08:00
parent 50d5612f6e
commit 7f8bcbbbb7
4 changed files with 3673 additions and 474 deletions

View File

@ -7,7 +7,7 @@
},
"devDependencies": {
"@antv/g2": "^3.5.9",
"@antv/gatsby-theme-antv": "^0.10.59",
"@antv/gatsby-theme-antv": "^0.11.5",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-decorators": "^7.6.0",

View File

@ -26,6 +26,7 @@
"author": "xiaoiver",
"license": "ISC",
"dependencies": {
"@amap/amap-jsapi-loader": "^0.0.3",
"@antv/l7-core": "2.2.32",
"@antv/l7-map": "2.2.32",
"@antv/l7-utils": "2.2.32",

View File

@ -1,6 +1,7 @@
/**
* AMapService
*/
import AMapLoader from '@amap/amap-jsapi-loader';
import {
Bounds,
CoordinateSystem,
@ -330,17 +331,22 @@ export default class AMapService
}
amapLoaded = true;
plugin.push('Map3D');
this.loadAMapScript(
`https://webapi.amap.com/maps?v=${AMAP_VERSION}&key=${token}&plugin=${plugin.join(
',',
)}`,
).then(() => {
resolveMap();
if (pendingResolveQueue.length) {
pendingResolveQueue.forEach((r) => r());
pendingResolveQueue = [];
}
});
AMapLoader.load({
key: token, // 申请好的Web端开发者Key首次调用 load 时必填
version: AMAP_VERSION, // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: plugin, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
})
.then((AMap) => {
resolveMap();
if (pendingResolveQueue.length) {
pendingResolveQueue.forEach((r) => r());
pendingResolveQueue = [];
}
})
.catch((e) => {
throw new Error(e);
});
} else {
if ((amapLoaded && window.AMap) || mapInstance) {
resolveMap();
@ -451,15 +457,4 @@ export default class AMapService
$wrapper.appendChild($amapdiv);
return $amapdiv;
}
private loadAMapScript(src: string) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.onload = () => {
resolve();
};
script.onerror = reject;
document.head.appendChild(script);
});
}
}

4105
yarn.lock

File diff suppressed because it is too large Load Diff