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": { "devDependencies": {
"@antv/g2": "^3.5.9", "@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/cli": "^7.6.4",
"@babel/core": "^7.6.4", "@babel/core": "^7.6.4",
"@babel/plugin-proposal-decorators": "^7.6.0", "@babel/plugin-proposal-decorators": "^7.6.0",

View File

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

View File

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