diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js
index f90e6de..82f4b54 100644
--- a/docs/.vuepress/config.js
+++ b/docs/.vuepress/config.js
@@ -47,7 +47,7 @@ module.exports = {
title: "指南",
collapsable: false,
sidebarDepth: 0,
- children: ["", "install", "quickstart", "changelog"]
+ children: ["", "install", "quickstart", "security", "changelog"]
},
{
title: "文档",
diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js
index 23e6012..e593737 100644
--- a/docs/.vuepress/enhanceApp.js
+++ b/docs/.vuepress/enhanceApp.js
@@ -2,9 +2,12 @@ import AMapJS from "amap-js";
const { pre, source } = require("./rootscope");
function render(template) {
- return eval(template.replace(pre.AMapKey, source.AMapKey));
+ template = template.replace(pre.AMapKey, source.AMapKey);
+ template = template.replace(pre.AMapSecurity, source.AMapSecurity);
+ return eval(template);
}
+
export default ({ Vue, options, router, siteData, isServer }) => {
if (!isServer) {
window.AMapJS = AMapJS;
diff --git a/docs/.vuepress/rootscope.js b/docs/.vuepress/rootscope.js
index 65f2059..7180404 100644
--- a/docs/.vuepress/rootscope.js
+++ b/docs/.vuepress/rootscope.js
@@ -1,4 +1,5 @@
const AMapKey = "您申请的Key值";
+const AMapSecurity = `{ serviceHost: '您的代理服务器域名或地址/_AMapService' }`;
const AMapVersion = "1.4.15";
const AMapUIVersion = "1.1";
const LocaVersion = "1.3.2";
@@ -8,7 +9,8 @@ const AMapLoader = `
new AMapJS.AMapLoader({
key: '${AMapKey}',
version: '${AMapVersion}',
- plugins: []
+ plugins: [],
+ security: ${AMapSecurity}
});
`.trim();
@@ -37,6 +39,7 @@ module.exports = {
AMapVersion,
AMapUIVersion,
AMapKey,
+ AMapSecurity,
AMapLoader,
AMapUILoader,
LocaLoader,
@@ -45,7 +48,8 @@ module.exports = {
source: {
AMapVersion,
AMapUIVersion,
- AMapKey: "494c7b315d60937fb6d3b7102a9cb4c3",
+ AMapKey: "22df707490e7631397c9fbb02e52544e",
+ AMapSecurity: `{ securityJsCode: "300bfebf024085e4360118bd1712473d" }`,
AMapLoader: "window.$AMapLoader",
AMapUILoader: "window.$AMapUILoader",
LocaLoader: "window.$LocaLoader",
diff --git a/docs/README.md b/docs/README.md
index db365de..c4df64a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -35,6 +35,7 @@ const loader = new AMapJS.AMapLoader({
key: '您申请的高德Key值',
version: '2.0',
plugins: [],
+ security: { serviceHost: '您的代理服务器域名或地址/_AMapService' }
});
// 调用 load 方法完成加载并调用执行回调。
diff --git a/docs/guide/amap-loader.md b/docs/guide/amap-loader.md
index 384b1f7..9b6e067 100644
--- a/docs/guide/amap-loader.md
+++ b/docs/guide/amap-loader.md
@@ -11,7 +11,7 @@ AMap JSAPI 加载器。
+
+```
diff --git a/packages/amap-js/package.json b/packages/amap-js/package.json
index 759c8cf..6034ff5 100644
--- a/packages/amap-js/package.json
+++ b/packages/amap-js/package.json
@@ -1,6 +1,6 @@
{
"name": "amap-js",
- "version": "2.3.0",
+ "version": "2.4.0",
"description": "AMap高德地图API加载器。",
"main": "lib/index.js",
"module": "es/index.js",
diff --git a/packages/amap-js/src/constants.js b/packages/amap-js/src/constants.js
index 601b001..29604ea 100644
--- a/packages/amap-js/src/constants.js
+++ b/packages/amap-js/src/constants.js
@@ -1 +1 @@
-export const version = "2.3.0";
+export const version = "2.4.0";
diff --git a/packages/amap-js/src/loaders/AMapLoader.js b/packages/amap-js/src/loaders/AMapLoader.js
index bcb0a8b..de66e70 100644
--- a/packages/amap-js/src/loaders/AMapLoader.js
+++ b/packages/amap-js/src/loaders/AMapLoader.js
@@ -5,9 +5,9 @@ import ScriptLoader from "./ScriptLoader";
const SymbolLoad = Symbol("Symbol.load");
/**
- * callback count
+ * API Callback Counter
*/
-let count = 0;
+let callbackCounter = 0;
/**
* AMapLoader 加载器
@@ -18,7 +18,12 @@ class AMapLoader extends Loader {
this.key = options.key || "";
this.version = options.version || "1.4.15";
this.plugins = options.plugins || [];
- this.callback = options.callback || "__onAMapLoaded" + count++;
+ this.callback = options.callback || "__onAMapLoaded" + callbackCounter++;
+ this.security = options.security ? options.security : false;
+ // this.security = {
+ // serviceHost: "您的代理服务器域名或地址/_AMapService"
+ // securityJsCode: "您申请的安全密钥"
+ // };
this.AMap = null;
this.readyState = this.CREATED;
this[SymbolLoad] = null;
@@ -44,6 +49,17 @@ class AMapLoader extends Loader {
const url = this.getUrl();
const callback = this.callback;
+ /**
+ * 自2021年12月02日升级,升级之后所申请的 key 必须配备安全密钥 jscode 一起使用
+ * 注意:此次升级不会影响之前已获得 key 的使用;升级之后的新增的key必须要配备安全密钥一起使用,
+ * 具体用法请您参看下文《JSAPI key和安全密钥设置和使用》(本次key升级新增安全密钥,是为了提升广大用户的对自己的key安全有效管理,降低明文传输被窃取的风险 。)
+ */
+ if (this.security) {
+ window._AMapSecurityConfig = this.security;
+ } else {
+ delete window._AMapSecurityConfig;
+ }
+
const script = new ScriptLoader(url);
const onScriptLoad = () => {
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index e59e9a3..b4ccef6 100644
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -13,7 +13,7 @@ cd amap-js
# Merge code
rm -rf *.html *.js *.css *.map assets guide
-rm -rf $AMapJSVersion/**
+rm -rf $AMapJSVersion
cp -rf ../../docs/.vuepress/dist/last/** .
mkdir $AMapJSVersion
cp -rf ../../docs/.vuepress/dist/$AMapJSVersion/** $AMapJSVersion/