项目列表和分包单位以及迁移人员
This commit is contained in:
4
node_modules/@amap/amap-jsapi-loader/.vscode/settings.json
generated
vendored
Normal file
4
node_modules/@amap/amap-jsapi-loader/.vscode/settings.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"editor.tabSize": 4,
|
||||
"prettier.tabWidth": 4
|
||||
}
|
111
node_modules/@amap/amap-jsapi-loader/README.md
generated
vendored
Normal file
111
node_modules/@amap/amap-jsapi-loader/README.md
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
# amap-jsapi-loader
|
||||
amap-jsapi-loader 是高德开放平台官网提供的地图 JSAPI 的加载器,可帮助开发者快速定位、有效避免加载引用地图 JSAPI 各种错误用法。
|
||||
|
||||
|
||||
该加载器具有以下特性:
|
||||
* 支持以 普通JS 和 npm包 两种方式使用;
|
||||
* 有效避免错误异步加载导致的 JSAPI 资源加载不完整问题;
|
||||
* 对于加载混用多个版本 JSAPI 的错误用法给予报错处理;
|
||||
* 对于不合法加载引用 JSAPI 给予报错处理;
|
||||
* 支持指定 JSAPI 版本;
|
||||
* 支持插件加载;
|
||||
* 允许多次执行加载操作,网络资源不会重复请求,便于大型工程模块管理;
|
||||
|
||||
|
||||
# USAGE
|
||||
|
||||
## AMapLoader.load方法参数说明
|
||||
```js
|
||||
AMapLoader.load({
|
||||
"key": "", // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||
"version": "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
||||
"plugins": [] // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
||||
"AMapUI": { // 是否加载 AMapUI,缺省不加载
|
||||
"version": '1.1', // AMapUI 缺省 1.1
|
||||
"plugins":[], // 需要加载的 AMapUI ui插件
|
||||
},
|
||||
"Loca":{ // 是否加载 Loca, 缺省不加载
|
||||
"version": '1.3.2' // Loca 版本,缺省 1.3.2
|
||||
},
|
||||
}).then(()=>{
|
||||
window.AMap.xx;
|
||||
window.AMapUI.xx;
|
||||
window.Loca.xx
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
## AMapUI
|
||||
|
||||
AMapUI 用法和官网有一点点区别。通过 AMapUI.xx 来获取组件
|
||||
```js
|
||||
AMapLoader.load({
|
||||
key: '',//首次load必填
|
||||
version: '2.0',
|
||||
AMapUI: {
|
||||
version: '1.1',
|
||||
plugins: ['overlay/SimpleMarker'],
|
||||
}
|
||||
}).then((AMap) => {
|
||||
map = new AMap.Map('container');
|
||||
|
||||
// !!! 通过 AMap.SimpleMarker 获取组件
|
||||
new AMapUI.SimpleMarker({
|
||||
//前景文字
|
||||
iconLabel: 'A',
|
||||
//图标主题
|
||||
iconTheme: 'default',
|
||||
//背景图标样式
|
||||
iconStyle: 'red',
|
||||
map: map,
|
||||
position: map.getCenter()
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
# 使用
|
||||
#### 以普通 JS 方式使用 Loader
|
||||
尚未发布在线Loader,可将 dist/index.js 复制到项目下
|
||||
```
|
||||
<script src="../dist/index.js"></script>
|
||||
<script>
|
||||
AMapLoader.load({
|
||||
key:'',//首次load必填
|
||||
version:'2.0',
|
||||
plugins:['AMap.Scale']
|
||||
}).then((AMap)=>{
|
||||
map = new AMap.Map('container');
|
||||
map.addControl(new AMap.Scale())
|
||||
}).catch((e)=>{
|
||||
console.error(e);
|
||||
});
|
||||
</script>
|
||||
```
|
||||
#### 以 NPM 包方式使用 Loader
|
||||
安装
|
||||
```
|
||||
tnpm i @alife/amap-jsapi-loader --save-dev
|
||||
```
|
||||
使用
|
||||
```
|
||||
import AMapLoader from '@alife/amap-jsapi-loader';
|
||||
|
||||
AMapLoader.load().then((AMap)=>{
|
||||
map = new AMap.Map('container');
|
||||
}).catch(e=>{
|
||||
console.log(e);
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
# 相关链接:
|
||||
地 图 JSAPI: [示例中心](https://lbs.amap.com/demo-center/js-api) [教程](https://lbs.amap.com/api/javascript-api/summary) [参考手册](https://lbs.amap.com/api/javascript-api/reference/map)
|
||||
|
||||
|
||||
|
||||
数据可视化 JSAPI: [示例中心](https://lbs.amap.com/demo-center/loca-api) [教程](https://lbs.amap.com/api/loca-api/prod_intro) [参考手册](https://lbs.amap.com/api/loca-api/guide/baselayer)
|
||||
|
||||
|
11
node_modules/@amap/amap-jsapi-loader/dist/index.js
generated
vendored
Normal file
11
node_modules/@amap/amap-jsapi-loader/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';(function(m,p){"object"===typeof exports&&"undefined"!==typeof module?module.exports=p():"function"===typeof define&&define.amd?define(p):(m=m||self,m.AMapLoader=p())})(this,function(){function m(a){var b=[];a.AMapUI&&b.push(p(a.AMapUI));a.Loca&&b.push(r(a.Loca));return Promise.all(b)}function p(a){return new Promise(function(h,c){var f=[];if(a.plugins)for(var e=0;e<a.plugins.length;e+=1)-1==d.AMapUI.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(g.AMapUI===b.failed)c("\u524d\u6b21\u8bf7\u6c42 AMapUI \u5931\u8d25");
|
||||
else if(g.AMapUI===b.notload){g.AMapUI=b.loading;d.AMapUI.version=a.version||d.AMapUI.version;e=d.AMapUI.version;var l=document.body||document.head,k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/ui/"+e+"/main.js";k.onerror=function(a){g.AMapUI=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25")};k.onload=function(){g.AMapUI=b.loaded;if(f.length)window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=
|
||||
arguments[a]}for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]()});else for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]()};l.appendChild(k)}else g.AMapUI===b.loaded?a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a]}h()}):h():a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):
|
||||
n.AMapUI.push(function(a){a?c(a):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a]}h()}):h()})})}function r(a){return new Promise(function(h,c){if(g.Loca===b.failed)c("\u524d\u6b21\u8bf7\u6c42 Loca \u5931\u8d25");else if(g.Loca===b.notload){g.Loca=b.loading;d.Loca.version=a.version||d.Loca.version;var f=d.Loca.version,e=d.AMap.version.startsWith("2"),l=f.startsWith("2");if(e&&!l||!e&&l)c("JSAPI \u4e0e Loca \u7248\u672c\u4e0d\u5bf9\u5e94\uff01\uff01");
|
||||
else{e=d.key;l=document.body||document.head;var k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/loca?v="+f+"&key="+e;k.onerror=function(a){g.Loca=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25")};k.onload=function(){g.Loca=b.loaded;for(h();n.Loca.length;)n.Loca.splice(0,1)[0]()};l.appendChild(k)}}else g.Loca===b.loaded?a.version&&a.version!==d.Loca.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):h():a.version&&a.version!==d.Loca.version?
|
||||
c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):n.Loca.push(function(a){a?c(a):c()})})}if(!window)throw Error("AMap JSAPI can only be used in Browser.");var b;(function(a){a.notload="notload";a.loading="loading";a.loaded="loaded";a.failed="failed"})(b||(b={}));var d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}},g={AMap:b.notload,AMapUI:b.notload,Loca:b.notload},n={AMap:[],AMapUI:[],Loca:[]},q=[],t=function(a){"function"==typeof a&&
|
||||
(g.AMap===b.loaded?a(window.AMap):q.push(a))};return{load:function(a){return new Promise(function(h,c){if(g.AMap==b.failed)c("");else if(g.AMap==b.notload){var f=a.key,e=a.version,l=a.plugins;f?(window.AMap&&"lbs.amap.com"!==location.host&&c("\u7981\u6b62\u591a\u79cdAPI\u52a0\u8f7d\u65b9\u5f0f\u6df7\u7528"),d.key=f,d.AMap.version=e||d.AMap.version,d.AMap.plugins=l||d.AMap.plugins,g.AMap=b.loading,e=document.body||document.head,window.___onAPILoaded=function(d){delete window.___onAPILoaded;if(d)g.AMap=
|
||||
b.failed,c(d);else for(g.AMap=b.loaded,m(a).then(function(){h(window.AMap)})["catch"](c);q.length;)q.splice(0,1)[0]()},l=document.createElement("script"),l.type="text/javascript",l.src="https://webapi.amap.com/maps?callback=___onAPILoaded&v="+d.AMap.version+"&key="+f+"&plugin="+d.AMap.plugins.join(","),l.onerror=function(a){g.AMap=b.failed;c(a)},e.appendChild(l)):c("\u8bf7\u586b\u5199key")}else if(g.AMap==b.loaded)if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&
|
||||
a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");else{f=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(f.length)window.AMap.plugin(f,function(){m(a).then(function(){h(window.AMap)})["catch"](c)});else m(a).then(function(){h(window.AMap)})["catch"](c)}else if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");
|
||||
else{var k=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&k.push(a.plugins[e]);t(function(){if(k.length)window.AMap.plugin(k,function(){m(a).then(function(){h(window.AMap)})["catch"](c)});else m(a).then(function(){h(window.AMap)})["catch"](c)})}})},reset:function(){delete window.AMap;delete window.AMapUI;delete window.Loca;d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}};g={AMap:b.notload,AMapUI:b.notload,
|
||||
Loca:b.notload};n={AMap:[],AMapUI:[],Loca:[]}}}})
|
69
node_modules/@amap/amap-jsapi-loader/example/AMapUI.html
generated
vendored
Normal file
69
node_modules/@amap/amap-jsapi-loader/example/AMapUI.html
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>JSAPI Loader</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container" tabindex="0"></div>
|
||||
|
||||
<script src="../dist/index.js"></script>
|
||||
<script>
|
||||
AMapLoader.load({
|
||||
key: '',//首次load必填
|
||||
version: '2.0Beta',
|
||||
plugins: ['AMap.Scale'],
|
||||
AMapUI: {
|
||||
plugins: ['overlay/SimpleMarker'],
|
||||
}
|
||||
}).then((AMap) => {
|
||||
map = new AMap.Map('container');
|
||||
map.addControl(new AMap.Scale());
|
||||
new AMapUI.SimpleMarker({
|
||||
|
||||
//前景文字
|
||||
iconLabel: 'A',
|
||||
|
||||
//图标主题
|
||||
iconTheme: 'default',
|
||||
|
||||
//背景图标样式
|
||||
iconStyle: 'red',
|
||||
|
||||
//...其他Marker选项...,不包括content
|
||||
map: map,
|
||||
position: map.getCenter()
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
setTimeout(function () {
|
||||
AMapLoader.load({
|
||||
plugins: ['AMap.MapType']
|
||||
}).then((AMap) => {
|
||||
map.addControl(new AMap.MapType())
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
76
node_modules/@amap/amap-jsapi-loader/example/Loca.html
generated
vendored
Normal file
76
node_modules/@amap/amap-jsapi-loader/example/Loca.html
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>JSAPI Loader</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container" tabindex="0"></div>
|
||||
<script src="https://a.amap.com/Loca/static/mock/districts.js"></script>
|
||||
<script src="../dist/index.js"></script>
|
||||
<script>
|
||||
AMapLoader.load({
|
||||
key: 'd3c5511c8a102496b1fdb985e6ca1cd7',//首次load必填
|
||||
// version: '2.0',
|
||||
Loca: {
|
||||
version: '2.0.0beta'
|
||||
}
|
||||
}).then((AMap) => {
|
||||
var map = new AMap.Map('container', {
|
||||
zoom: 4,
|
||||
center: [107.4976, 32.1697],
|
||||
features: ['bg', 'road'],
|
||||
// Loca 自 1.2.0 起 viewMode 模式默认为 3D,如需 2D 模式,请显示配置。
|
||||
// viewMode: '3D'
|
||||
});
|
||||
|
||||
var layer = new Loca.PointLayer({
|
||||
map: map
|
||||
});
|
||||
|
||||
layer.setData(districts, {
|
||||
// 指定经纬度所在字段
|
||||
lnglat: 'center'
|
||||
});
|
||||
|
||||
layer.setOptions({
|
||||
style: {
|
||||
// 圆形半径,单位像素
|
||||
radius: 5,
|
||||
// 填充颜色
|
||||
color: '#07E8E4',
|
||||
// 描边颜色
|
||||
borderColor: '#5DFBF9',
|
||||
// 描边宽度,单位像素
|
||||
borderWidth: 1,
|
||||
// 透明度 [0-1]
|
||||
opacity: 0.9,
|
||||
}
|
||||
});
|
||||
|
||||
layer.render();
|
||||
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
94
node_modules/@amap/amap-jsapi-loader/example/Multi.html
generated
vendored
Normal file
94
node_modules/@amap/amap-jsapi-loader/example/Multi.html
generated
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>JSAPI Loader</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container" tabindex="0"></div>
|
||||
<script src="https://a.amap.com/Loca/static/mock/districts.js"></script>
|
||||
<script src="../dist/index.js"></script>
|
||||
<script>
|
||||
AMapLoader.load({
|
||||
key: '',//首次load必填
|
||||
version: '1.4.15',
|
||||
AMapUI: {
|
||||
plugins: ['overlay/SimpleMarker'],
|
||||
},
|
||||
Loca: {
|
||||
version: '1.3.2'
|
||||
}
|
||||
}).then((AMap) => {
|
||||
var map = new AMap.Map('container', {
|
||||
zoom: 4,
|
||||
center: [107.4976, 32.1697],
|
||||
features: ['bg', 'road'],
|
||||
// Loca 自 1.2.0 起 viewMode 模式默认为 3D,如需 2D 模式,请显示配置。
|
||||
// viewMode: '3D'
|
||||
});
|
||||
|
||||
new AMapUI.SimpleMarker({
|
||||
|
||||
//前景文字
|
||||
iconLabel: 'A',
|
||||
|
||||
//图标主题
|
||||
iconTheme: 'default',
|
||||
|
||||
//背景图标样式
|
||||
iconStyle: 'red',
|
||||
|
||||
//...其他Marker选项...,不包括content
|
||||
map: map,
|
||||
position: map.getCenter()
|
||||
});
|
||||
var layer = new Loca.PointLayer({
|
||||
map: map
|
||||
});
|
||||
|
||||
layer.setData(districts, {
|
||||
// 指定经纬度所在字段
|
||||
lnglat: 'center'
|
||||
});
|
||||
|
||||
layer.setOptions({
|
||||
style: {
|
||||
// 圆形半径,单位像素
|
||||
radius: 5,
|
||||
// 填充颜色
|
||||
color: '#07E8E4',
|
||||
// 描边颜色
|
||||
borderColor: '#5DFBF9',
|
||||
// 描边宽度,单位像素
|
||||
borderWidth: 1,
|
||||
// 透明度 [0-1]
|
||||
opacity: 0.9,
|
||||
}
|
||||
});
|
||||
|
||||
layer.render();
|
||||
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
36
node_modules/@amap/amap-jsapi-loader/example/example-es6.html
generated
vendored
Normal file
36
node_modules/@amap/amap-jsapi-loader/example/example-es6.html
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>JSAPI Loader - ES6</title>
|
||||
<style>
|
||||
html, body, #container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container" tabindex="0"></div>
|
||||
<script type="module">
|
||||
import AMapLoader from '../src/index.js';
|
||||
AMapLoader.load({
|
||||
key:'',//必填
|
||||
version:'2.0',
|
||||
plugins:['AMap.Scale']
|
||||
}).then((AMap)=>{
|
||||
debugger
|
||||
var map = new AMap.Map('container');
|
||||
map.addControl(new AMap.Scale())
|
||||
}).catch((e)=>{
|
||||
console.error(e);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
46
node_modules/@amap/amap-jsapi-loader/example/example.html
generated
vendored
Normal file
46
node_modules/@amap/amap-jsapi-loader/example/example.html
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>AMap JSAPI Loader</title>
|
||||
<style>
|
||||
html, body, #container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container" tabindex="0"></div>
|
||||
|
||||
<script src="https://webapi.amap.com/loader.js"></script>
|
||||
<script>
|
||||
AMapLoader.load({ //首次调用 load
|
||||
key:'你申请的高德开放平台 Web 端 key',//首次load key为必填
|
||||
version:'2.0',
|
||||
plugins:['AMap.Scale','AMap.ToolBar']
|
||||
}).then((AMap)=>{
|
||||
map = new AMap.Map('container');
|
||||
map.addControl(new AMap.Scale())
|
||||
map.addControl(new AMap.ToolBar())
|
||||
map.add(new AMap.Marker({
|
||||
position:map.getCenter()
|
||||
}));
|
||||
}).catch((e)=>{
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
AMapLoader.load({ //可多次调用load
|
||||
plugins:['AMap.MapType']
|
||||
}).then((AMap)=>{
|
||||
map.addControl(new AMap.MapType())
|
||||
}).catch((e)=>{
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
2
node_modules/@amap/amap-jsapi-loader/example/libs/chai.min.js
generated
vendored
Normal file
2
node_modules/@amap/amap-jsapi-loader/example/libs/chai.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/@amap/amap-jsapi-loader/example/libs/mocha.min.css
generated
vendored
Normal file
1
node_modules/@amap/amap-jsapi-loader/example/libs/mocha.min.css
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
@charset "utf-8";body{margin:0}#mocha{font:20px/1.5 "Helvetica Neue",Helvetica,Arial,sans-serif;margin:60px 50px}#mocha li,#mocha ul{margin:0;padding:0}#mocha ul{list-style:none}#mocha h1,#mocha h2{margin:0}#mocha h1{margin-top:15px;font-size:1em;font-weight:200}#mocha h1 a{text-decoration:none;color:inherit}#mocha h1 a:hover{text-decoration:underline}#mocha .suite .suite h1{margin-top:0;font-size:.8em}#mocha .hidden{display:none}#mocha h2{font-size:12px;font-weight:400;cursor:pointer}#mocha .suite{margin-left:15px}#mocha .test{margin-left:15px;overflow:hidden}#mocha .test.pending:hover h2::after{content:'(pending)';font-family:arial,sans-serif}#mocha .test.pass.medium .duration{background:#c09853}#mocha .test.pass.slow .duration{background:#b94a48}#mocha .test.pass::before{content:'✓';font-size:12px;display:block;float:left;margin-right:5px;color:#00d6b2}#mocha .test.pass .duration{font-size:9px;margin-left:5px;padding:2px 5px;color:#fff;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.2);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,.2);box-shadow:inset 0 1px 1px rgba(0,0,0,.2);-webkit-border-radius:5px;-moz-border-radius:5px;-ms-border-radius:5px;-o-border-radius:5px;border-radius:5px}#mocha .test.pass.fast .duration{display:none}#mocha .test.pending{color:#0b97c4}#mocha .test.pending::before{content:'◦';color:#0b97c4}#mocha .test.fail{color:#c00}#mocha .test.fail pre{color:#000}#mocha .test.fail::before{content:'✖';font-size:12px;display:block;float:left;margin-right:5px;color:#c00}#mocha .test pre.error{color:#c00;max-height:300px;overflow:auto}#mocha .test pre{display:block;float:left;clear:left;font:12px/1.5 monaco,monospace;margin:5px;padding:15px;border:1px solid #eee;max-width:85%;max-width:calc(100% - 42px);word-wrap:break-word;border-bottom-color:#ddd;-webkit-border-radius:3px;-webkit-box-shadow:0 1px 3px #eee;-moz-border-radius:3px;-moz-box-shadow:0 1px 3px #eee;border-radius:3px}#mocha .test h2{position:relative}#mocha .test a.replay{position:absolute;top:3px;right:0;text-decoration:none;vertical-align:middle;display:block;width:15px;height:15px;line-height:15px;text-align:center;background:#eee;font-size:15px;-moz-border-radius:15px;border-radius:15px;-webkit-transition:opacity 200ms;-moz-transition:opacity 200ms;transition:opacity 200ms;opacity:.3;color:#888}#mocha .test:hover a.replay{opacity:1}#mocha-report.fail .test.pass,#mocha-report.pass .test.fail,#mocha-report.pending .test.fail,#mocha-report.pending .test.pass{display:none}#mocha-report.pending .test.pass.pending{display:block}#mocha-error{color:#c00;font-size:1.5em;font-weight:100;letter-spacing:1px}#mocha-stats{position:fixed;top:15px;right:10px;font-size:12px;margin:0;color:#888;z-index:1}#mocha-stats .progress{float:right;padding-top:0}#mocha-stats em{color:#000}#mocha-stats a{text-decoration:none;color:inherit}#mocha-stats a:hover{border-bottom:1px solid #eee}#mocha-stats li{display:inline-block;margin:0 5px;list-style:none;padding-top:11px}#mocha-stats canvas{width:40px;height:40px}#mocha code .comment{color:#ddd}#mocha code .init{color:#2f6fad}#mocha code .string{color:#5890ad}#mocha code .keyword{color:#8a6343}#mocha code .number{color:#2f6fad}@media screen and (max-device-width:480px){#mocha{margin:60px 0}#mocha #stats{position:absolute}}
|
2
node_modules/@amap/amap-jsapi-loader/example/libs/mocha.min.js
generated
vendored
Normal file
2
node_modules/@amap/amap-jsapi-loader/example/libs/mocha.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
287
node_modules/@amap/amap-jsapi-loader/example/test.html
generated
vendored
Normal file
287
node_modules/@amap/amap-jsapi-loader/example/test.html
generated
vendored
Normal file
@ -0,0 +1,287 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<title>JSAPI Loader</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
|
||||
<link rel="stylesheet" href="./libs/mocha.min.css" />
|
||||
<script src="./libs/chai.min.js"></script>
|
||||
<script src="./libs/mocha.min.js"></script>
|
||||
|
||||
<script>
|
||||
mocha.setup('bdd');
|
||||
mocha.traceIgnores = ['mocha.min.js', 'chai.min.js'];
|
||||
expect = chai.expect;
|
||||
</script>
|
||||
<div id="container" tabindex="0"></div>
|
||||
|
||||
<script src="../dist/index.js"></script>
|
||||
<script>
|
||||
// 请把 key 写在这里
|
||||
const JSAPIKey = '';
|
||||
const chai = window.chai;
|
||||
const mocha = window.mocha;
|
||||
mocha.setup({
|
||||
timeout: '5000',
|
||||
ui: 'bdd',
|
||||
});
|
||||
const expect = chai.expect;
|
||||
describe('JSAPI', () => {
|
||||
beforeEach(function () {
|
||||
AMapLoader.reset()
|
||||
});
|
||||
|
||||
it('Simple', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '2.0',
|
||||
plugins: ['AMap.Scale'],
|
||||
AMapUI: {
|
||||
plugins: ['overlay/SimpleMarker']
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.AMapUI)).eq(true)
|
||||
expect(Boolean(window.AMapUI.SimpleMarker)).eq(true)
|
||||
expect(Boolean(window.Loca)).eq(false)
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
it('Request with AMapUI Loca', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
plugins: ['AMap.Scale'],
|
||||
AMapUI: {
|
||||
plugins: ['overlay/SimpleMarker']
|
||||
},
|
||||
Loca: {
|
||||
version: '1.3.2'
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.AMapUI)).eq(true)
|
||||
expect(Boolean(window.AMapUI.SimpleMarker)).eq(true)
|
||||
|
||||
expect(Boolean(window.Loca)).eq(true)
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
it('fail with multi version', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '2.0',
|
||||
}).then(() => {
|
||||
done()
|
||||
});
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
}).then(() => {
|
||||
done(Error('should not here'))
|
||||
})
|
||||
.catch(err => {
|
||||
try {
|
||||
expect(err).eq('不允许多个版本 JSAPI 混用')
|
||||
|
||||
} catch (error) {
|
||||
done(error)
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
it('fail with multi key', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '2.0',
|
||||
}).then(() => {
|
||||
done()
|
||||
});
|
||||
AMapLoader.load({
|
||||
key: 'asdfas',//首次load必填
|
||||
}).then(() => {
|
||||
done(Error('should not here'))
|
||||
})
|
||||
.catch(err => {
|
||||
try {
|
||||
expect(err).eq('多个不一致的 key')
|
||||
|
||||
} catch (error) {
|
||||
done(error)
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
describe('AMapUI', () => {
|
||||
beforeEach(function () {
|
||||
AMapLoader.reset()
|
||||
});
|
||||
|
||||
it('version', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
AMapUI: {
|
||||
version: '1.1',
|
||||
plugins: ['misc/PathSimplifier']
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.AMapUI)).eq(true)
|
||||
expect(Boolean(window.AMapUI.PathSimplifier)).eq(true)
|
||||
expect(Boolean(window.AMapUI.version.startsWith('1.1'))).eq(true)
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('async', (done) => {
|
||||
console.log(window.AMap);
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
AMapUI: {
|
||||
version: '1.0',
|
||||
plugins: ['overlay/SimpleMarker']
|
||||
}
|
||||
}).then(() => {
|
||||
AMapLoader.load({
|
||||
AMapUI: {
|
||||
plugins: ['overlay/SimpleInfoWindow']
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.AMapUI.version.startsWith('1.0'))).eq(true)
|
||||
expect(Boolean(window.AMapUI.SimpleMarker)).eq(true)
|
||||
expect(Boolean(window.AMapUI.SimpleInfoWindow)).eq(true)
|
||||
done()
|
||||
});
|
||||
}).catch(done);
|
||||
})
|
||||
});
|
||||
|
||||
describe('Loca', () => {
|
||||
beforeEach(function () {
|
||||
AMapLoader.reset()
|
||||
});
|
||||
|
||||
it('version', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
Loca: {
|
||||
version: '1.3.1'
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.Loca)).eq(true)
|
||||
expect(window.Loca.version).eq('1.3.1')
|
||||
done()
|
||||
}).catch(done);
|
||||
});
|
||||
it('fail with jsapi2.0', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '2.0',
|
||||
Loca: {
|
||||
version: '1.3.1'
|
||||
}
|
||||
}).then(() => {
|
||||
done(Error('should not here'))
|
||||
}).catch(err => {
|
||||
try {
|
||||
expect(err).eq("Loca 暂不适配 JSAPI 2.0,请使用 1.4.15")
|
||||
done()
|
||||
} catch (error) {
|
||||
done(error)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('async', (done) => {
|
||||
AMapLoader.load({
|
||||
key: JSAPIKey,//首次load必填
|
||||
version: '1.4.15',
|
||||
Loca: {
|
||||
version: '1.2.1'
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.Loca)).eq(true)
|
||||
expect(window.Loca.version).eq('1.2.1')
|
||||
AMapLoader.load({
|
||||
Loca: {
|
||||
version: '1.2.1'
|
||||
}
|
||||
}).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true)
|
||||
expect(Boolean(window.Loca)).eq(true)
|
||||
expect(window.Loca.version).eq('1.2.1')
|
||||
done()
|
||||
}).catch(done);
|
||||
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
describe('Advance', () => {
|
||||
beforeEach(function () {
|
||||
AMapLoader.reset()
|
||||
});
|
||||
it('Multi', (done) => {
|
||||
AMapLoader.load({ key: JSAPIKey, version: '1.4.15' }).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true);
|
||||
expect(window.AMap.v).eq('1.4.15');
|
||||
|
||||
expect(Boolean(window.AMapUI)).eq(false);
|
||||
expect(Boolean(window.Loca)).eq(false);
|
||||
AMapLoader.load({ AMapUI: {} }).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true);
|
||||
expect(window.AMap.v).eq('1.4.15');
|
||||
|
||||
expect(Boolean(window.AMapUI)).eq(true);
|
||||
expect(window.AMapUI.version.startsWith('1.1')).eq(true);
|
||||
expect(Boolean(window.Loca)).eq(false);
|
||||
AMapLoader.load({ Loca: {} }).then(() => {
|
||||
expect(Boolean(window.AMap)).eq(true);
|
||||
expect(window.AMap.v).eq('1.4.15');
|
||||
expect(Boolean(window.AMapUI)).eq(true);
|
||||
expect(window.AMapUI.version.startsWith('1.1')).eq(true);
|
||||
expect(Boolean(window.Loca)).eq(true);
|
||||
expect(window.Loca.version).eq('1.3.2');
|
||||
done()
|
||||
})
|
||||
})
|
||||
}).catch(done)
|
||||
})
|
||||
})
|
||||
mocha.run()
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
15
node_modules/@amap/amap-jsapi-loader/index.d.ts
generated
vendored
Normal file
15
node_modules/@amap/amap-jsapi-loader/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
declare var load: (options: {
|
||||
key: string; // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||
version: string; // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
||||
plugins?: string[]; //插件列表
|
||||
// 是否加载 AMapUI,缺省不加载
|
||||
AMapUI?: {
|
||||
version?: string; // AMapUI 缺省 1.1
|
||||
plugins?: string[]; // 需要加载的 AMapUI ui插件
|
||||
};
|
||||
// 是否加载 Loca, 缺省不加载
|
||||
Loca?: {
|
||||
version?: string; // Loca 版本,缺省 1.3.2
|
||||
};
|
||||
}) => Promise<any>;
|
||||
export { load };
|
37
node_modules/@amap/amap-jsapi-loader/package.json
generated
vendored
Normal file
37
node_modules/@amap/amap-jsapi-loader/package.json
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@amap/amap-jsapi-loader",
|
||||
"version": "1.0.1",
|
||||
"description": "高德官网提供的地图JSAPI加载器,可以避免多种异步加载API的错误用法",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.d.ts",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c rollup.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@gitlab.alibaba-inc.com:amap-web/amap-jsapi-loader.git"
|
||||
},
|
||||
"keywords": [
|
||||
"amap",
|
||||
"jsapi",
|
||||
"sdk",
|
||||
"loader",
|
||||
"地图",
|
||||
"高德"
|
||||
],
|
||||
"author": "mengmeng.du@alibaba-inc.com",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@ampproject/rollup-plugin-closure-compiler": "^0.23.0",
|
||||
"@babel/core": "^7.8.7",
|
||||
"@babel/preset-env": "^7.8.7",
|
||||
"rollup": "^1.32.0",
|
||||
"rollup-plugin-babel": "^4.3.3",
|
||||
"rollup-plugin-server": "^0.7.0",
|
||||
"rollup-plugin-typescript2": "^0.27.1",
|
||||
"typescript": "^3.9.7"
|
||||
}
|
||||
}
|
25
node_modules/@amap/amap-jsapi-loader/rollup.config.js
generated
vendored
Normal file
25
node_modules/@amap/amap-jsapi-loader/rollup.config.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
import server from "rollup-plugin-server";
|
||||
import babel from "rollup-plugin-babel";
|
||||
import compiler from "@ampproject/rollup-plugin-closure-compiler";
|
||||
import rollupTypescript from 'rollup-plugin-typescript2';
|
||||
|
||||
export default {
|
||||
input: "src/index.ts",
|
||||
output: {
|
||||
file: "dist/index.js",
|
||||
format: "umd",
|
||||
name: "AMapLoader",
|
||||
},
|
||||
plugins: [
|
||||
rollupTypescript(),
|
||||
babel({
|
||||
presets: [["@babel/env", { targets: { ie: 9 } }]],
|
||||
}),
|
||||
compiler(),
|
||||
server({
|
||||
contentBase: "./",
|
||||
host: "127.0.0.1",
|
||||
port: 3601,
|
||||
}),
|
||||
],
|
||||
};
|
5
node_modules/@amap/amap-jsapi-loader/src/global.d.ts
generated
vendored
Normal file
5
node_modules/@amap/amap-jsapi-loader/src/global.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
declare var AMap: any;
|
||||
declare var AMapUI: any;
|
||||
declare var Loca: any;
|
||||
|
||||
declare var ___onAPILoaded: any;
|
367
node_modules/@amap/amap-jsapi-loader/src/index.ts
generated
vendored
Normal file
367
node_modules/@amap/amap-jsapi-loader/src/index.ts
generated
vendored
Normal file
@ -0,0 +1,367 @@
|
||||
if (!window) {
|
||||
throw Error("AMap JSAPI can only be used in Browser.");
|
||||
}
|
||||
enum LoadStatus {
|
||||
notload = "notload",
|
||||
loading = "loading",
|
||||
loaded = "loaded",
|
||||
failed = "failed",
|
||||
}
|
||||
let config = {
|
||||
key: "",
|
||||
AMap: {
|
||||
version: "1.4.15",
|
||||
plugins: [],
|
||||
},
|
||||
AMapUI: {
|
||||
version: "1.1",
|
||||
plugins: [],
|
||||
},
|
||||
Loca: {
|
||||
version: "1.3.2",
|
||||
},
|
||||
};
|
||||
|
||||
let Status = {
|
||||
AMap: LoadStatus.notload,
|
||||
AMapUI: LoadStatus.notload,
|
||||
Loca: LoadStatus.notload,
|
||||
};
|
||||
let Callback = {
|
||||
AMap: [],
|
||||
AMapUI: [],
|
||||
Loca: [],
|
||||
};
|
||||
|
||||
let onloadCBKs = [];
|
||||
const onload = function (callback) {
|
||||
if (typeof callback == "function") {
|
||||
if (Status.AMap === LoadStatus.loaded) {
|
||||
callback(window.AMap);
|
||||
return;
|
||||
}
|
||||
onloadCBKs.push(callback);
|
||||
}
|
||||
};
|
||||
|
||||
interface LoadOption {
|
||||
key: string;
|
||||
version?: string;
|
||||
plugins?: string[];
|
||||
AMapUI?: {
|
||||
version?: string;
|
||||
plugins?: string[];
|
||||
};
|
||||
Loca?: {
|
||||
version?: string;
|
||||
};
|
||||
}
|
||||
function appendOther(option: LoadOption): Promise<any> {
|
||||
let pros: Promise<void>[] = [];
|
||||
if (option.AMapUI) {
|
||||
pros.push(loadAMapUI(option.AMapUI));
|
||||
}
|
||||
if (option.Loca) {
|
||||
pros.push(loadLoca(option.Loca));
|
||||
}
|
||||
return Promise.all(pros);
|
||||
}
|
||||
function loadAMapUI(params: { version?: string; plugins?: string[] }): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
const newPlugins: string[] = [];
|
||||
if (params.plugins) {
|
||||
for (var i = 0; i < params.plugins.length; i += 1) {
|
||||
if (config.AMapUI.plugins.indexOf(params.plugins[i]) == -1) {
|
||||
newPlugins.push(params.plugins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Status.AMapUI === LoadStatus.failed) {
|
||||
rej("前次请求 AMapUI 失败");
|
||||
} else if (Status.AMapUI === LoadStatus.notload) {
|
||||
Status.AMapUI = LoadStatus.loading;
|
||||
config.AMapUI.version = params.version || config.AMapUI.version;
|
||||
const version = config.AMapUI.version;
|
||||
const parentNode = document.body || document.head;
|
||||
const script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = `https://webapi.amap.com/ui/${version}/main.js`;
|
||||
|
||||
script.onerror = (e) => {
|
||||
Status.AMapUI = LoadStatus.failed;
|
||||
rej("请求 AMapUI 失败");
|
||||
};
|
||||
script.onload = () => {
|
||||
Status.AMapUI = LoadStatus.loaded;
|
||||
if (newPlugins.length) {
|
||||
window.AMapUI.loadUI(newPlugins, function () {
|
||||
for (let i = 0, len = newPlugins.length; i < len; i++) {
|
||||
const path = newPlugins[i];
|
||||
const name = path.split("/").slice(-1)[0];
|
||||
window.AMapUI[name] = arguments[i];
|
||||
}
|
||||
res();
|
||||
while (Callback.AMapUI.length) {
|
||||
Callback.AMapUI.splice(0, 1)[0]();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res();
|
||||
while (Callback.AMapUI.length) {
|
||||
Callback.AMapUI.splice(0, 1)[0]();
|
||||
}
|
||||
}
|
||||
};
|
||||
parentNode.appendChild(script);
|
||||
} else if (Status.AMapUI === LoadStatus.loaded) {
|
||||
if (params.version && params.version !== config.AMapUI.version) {
|
||||
rej("不允许多个版本 AMapUI 混用");
|
||||
} else {
|
||||
if (newPlugins.length) {
|
||||
window.AMapUI.loadUI(newPlugins, function () {
|
||||
for (let i = 0, len = newPlugins.length; i < len; i++) {
|
||||
const path = newPlugins[i];
|
||||
const name = path.split("/").slice(-1)[0];
|
||||
window.AMapUI[name] = arguments[i];
|
||||
}
|
||||
res();
|
||||
});
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (params.version && params.version !== config.AMapUI.version) {
|
||||
rej("不允许多个版本 AMapUI 混用");
|
||||
} else {
|
||||
Callback.AMapUI.push((err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
} else {
|
||||
if (newPlugins.length) {
|
||||
window.AMapUI.loadUI(newPlugins, function () {
|
||||
for (let i = 0, len = newPlugins.length; i < len; i++) {
|
||||
const path = newPlugins[i];
|
||||
const name = path.split("/").slice(-1)[0];
|
||||
window.AMapUI[name] = arguments[i];
|
||||
}
|
||||
res();
|
||||
});
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadLoca(params: { version?: string }): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
if (Status.Loca === LoadStatus.failed) {
|
||||
rej("前次请求 Loca 失败");
|
||||
} else if (Status.Loca === LoadStatus.notload) {
|
||||
Status.Loca = LoadStatus.loading;
|
||||
config.Loca.version = params.version || config.Loca.version;
|
||||
const version = config.Loca.version;
|
||||
const isApiV2 = config.AMap.version.startsWith("2");
|
||||
const isLocaV2 = version.startsWith("2");
|
||||
if ((isApiV2 && !isLocaV2) || (!isApiV2 && isLocaV2)) {
|
||||
rej("JSAPI 与 Loca 版本不对应!!");
|
||||
return;
|
||||
}
|
||||
const key = config.key;
|
||||
const parentNode = document.body || document.head;
|
||||
const script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = `https://webapi.amap.com/loca?v=${version}&key=${key}`;
|
||||
|
||||
script.onerror = (e) => {
|
||||
Status.Loca = LoadStatus.failed;
|
||||
rej("请求 AMapUI 失败");
|
||||
};
|
||||
script.onload = () => {
|
||||
Status.Loca = LoadStatus.loaded;
|
||||
res();
|
||||
while (Callback.Loca.length) {
|
||||
Callback.Loca.splice(0, 1)[0]();
|
||||
}
|
||||
};
|
||||
parentNode.appendChild(script);
|
||||
} else if (Status.Loca === LoadStatus.loaded) {
|
||||
if (params.version && params.version !== config.Loca.version) {
|
||||
rej("不允许多个版本 Loca 混用");
|
||||
} else {
|
||||
res();
|
||||
}
|
||||
} else {
|
||||
if (params.version && params.version !== config.Loca.version) {
|
||||
rej("不允许多个版本 Loca 混用");
|
||||
} else {
|
||||
Callback.Loca.push((err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
} else {
|
||||
rej();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const load = function (options: LoadOption) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Status.AMap == LoadStatus.failed) {
|
||||
reject("");
|
||||
} else if (Status.AMap == LoadStatus.notload) {
|
||||
//初次加载
|
||||
let { key, version, plugins } = options;
|
||||
if (!key) {
|
||||
reject("请填写key");
|
||||
return;
|
||||
}
|
||||
if (window.AMap && location.host !== "lbs.amap.com") {
|
||||
reject("禁止多种API加载方式混用");
|
||||
}
|
||||
config.key = key;
|
||||
config.AMap.version = version || config.AMap.version;
|
||||
config.AMap.plugins = plugins || config.AMap.plugins;
|
||||
Status.AMap = LoadStatus.loading;
|
||||
|
||||
const parentNode = document.body || document.head;
|
||||
|
||||
window.___onAPILoaded = function (err) {
|
||||
delete window.___onAPILoaded;
|
||||
if (err) {
|
||||
Status.AMap = LoadStatus.failed;
|
||||
reject(err);
|
||||
} else {
|
||||
Status.AMap = LoadStatus.loaded;
|
||||
appendOther(options)
|
||||
.then(() => {
|
||||
resolve(window.AMap);
|
||||
})
|
||||
.catch(reject);
|
||||
while (onloadCBKs.length) {
|
||||
onloadCBKs.splice(0, 1)[0]();
|
||||
}
|
||||
}
|
||||
};
|
||||
const script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
|
||||
script.src =
|
||||
"https://webapi.amap.com/maps?callback=___onAPILoaded&v=" +
|
||||
config.AMap.version +
|
||||
"&key=" +
|
||||
key +
|
||||
"&plugin=" +
|
||||
config.AMap.plugins.join(",");
|
||||
script.onerror = (e) => {
|
||||
Status.AMap = LoadStatus.failed;
|
||||
reject(e);
|
||||
};
|
||||
parentNode.appendChild(script);
|
||||
} else if (Status.AMap == LoadStatus.loaded) {
|
||||
//deal multi load
|
||||
if (options.key && options.key !== config.key) {
|
||||
reject("多个不一致的 key");
|
||||
return;
|
||||
}
|
||||
if (options.version && options.version !== config.AMap.version) {
|
||||
reject("不允许多个版本 JSAPI 混用");
|
||||
return;
|
||||
}
|
||||
const newPlugins = [];
|
||||
if (options.plugins) {
|
||||
for (var i = 0; i < options.plugins.length; i += 1) {
|
||||
if (config.AMap.plugins.indexOf(options.plugins[i]) == -1) {
|
||||
newPlugins.push(options.plugins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newPlugins.length) {
|
||||
window.AMap.plugin(newPlugins, () => {
|
||||
appendOther(options)
|
||||
.then(() => {
|
||||
resolve(window.AMap);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
} else {
|
||||
appendOther(options)
|
||||
.then(() => {
|
||||
resolve(window.AMap);
|
||||
})
|
||||
.catch(reject);
|
||||
}
|
||||
} else {
|
||||
// loading
|
||||
if (options.key && options.key !== config.key) {
|
||||
reject("多个不一致的 key");
|
||||
return;
|
||||
}
|
||||
if (options.version && options.version !== config.AMap.version) {
|
||||
reject("不允许多个版本 JSAPI 混用");
|
||||
return;
|
||||
}
|
||||
const newPlugins = [];
|
||||
if (options.plugins) {
|
||||
for (var i = 0; i < options.plugins.length; i += 1) {
|
||||
if (config.AMap.plugins.indexOf(options.plugins[i]) == -1) {
|
||||
newPlugins.push(options.plugins[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
onload(() => {
|
||||
if (newPlugins.length) {
|
||||
window.AMap.plugin(newPlugins, () => {
|
||||
appendOther(options)
|
||||
.then(() => {
|
||||
resolve(window.AMap);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
} else {
|
||||
appendOther(options)
|
||||
.then(() => {
|
||||
resolve(window.AMap);
|
||||
})
|
||||
.catch(reject);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
function reset() {
|
||||
delete window.AMap;
|
||||
delete window.AMapUI;
|
||||
delete window.Loca;
|
||||
config = {
|
||||
key: "",
|
||||
AMap: {
|
||||
version: "1.4.15",
|
||||
plugins: [],
|
||||
},
|
||||
AMapUI: {
|
||||
version: "1.1",
|
||||
plugins: [],
|
||||
},
|
||||
Loca: {
|
||||
version: "1.3.2",
|
||||
},
|
||||
};
|
||||
Status = {
|
||||
AMap: LoadStatus.notload,
|
||||
AMapUI: LoadStatus.notload,
|
||||
Loca: LoadStatus.notload,
|
||||
};
|
||||
Callback = {
|
||||
AMap: [],
|
||||
AMapUI: [],
|
||||
Loca: [],
|
||||
};
|
||||
}
|
||||
export default { load, reset };
|
17
node_modules/@amap/amap-jsapi-loader/test/demo.ts
generated
vendored
Normal file
17
node_modules/@amap/amap-jsapi-loader/test/demo.ts
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import AMapLoader from "../";
|
||||
// import { } from "@ali/test-amap-jsapi";
|
||||
|
||||
AMapLoader.load({
|
||||
key: "test",
|
||||
version: "2.0"
|
||||
}).then(() => {
|
||||
new AMap.Circle({})
|
||||
const map = new AMap.Map("div");
|
||||
map.on("complete", () => {
|
||||
const circle = new AMap.Circle({
|
||||
center: [135, 45],
|
||||
radius: 40
|
||||
});
|
||||
map.add(circle);
|
||||
});
|
||||
});
|
7
node_modules/@amap/amap-jsapi-loader/test/test.ts
generated
vendored
Normal file
7
node_modules/@amap/amap-jsapi-loader/test/test.ts
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import AMapLoader from "../";
|
||||
import "@amap/amap-jsapi-loader";
|
||||
|
||||
AMapLoader.load({
|
||||
key: "test",
|
||||
version: "2.0"
|
||||
}).then(() => {});
|
Reference in New Issue
Block a user