Merge pull request #493 from antvis/fix_amap_loader

refactor(amap): 优化高德地图sdk 加载方式
This commit is contained in:
@thinkinggis 2020-08-28 11:34:37 +08:00 committed by GitHub
commit 1489e5cd6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8850 additions and 8108 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,16 +331,21 @@ 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(() => {
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) {
@ -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);
});
}
}

16916
yarn.lock

File diff suppressed because it is too large Load Diff