diff --git a/lib/components/amap/map/index.d.ts b/lib/components/amap/map/index.d.ts index e854d62af..284ac4f66 100644 --- a/lib/components/amap/map/index.d.ts +++ b/lib/components/amap/map/index.d.ts @@ -26,6 +26,8 @@ export interface AMapProps extends APILoaderProps { useAMapUI?: boolean; uiVersion?: string; uiCallback?: (status: 'success' | 'fail', result?: any) => void; + securityJsCode?: string; + serviceHost?: string; } declare const memo: (props: AMapProps) => JSX.Element; export default memo; diff --git a/lib/components/amap/map/index.js b/lib/components/amap/map/index.js index 6b76e8fe4..e77c099ca 100644 --- a/lib/components/amap/map/index.js +++ b/lib/components/amap/map/index.js @@ -8,8 +8,23 @@ var classnames_1 = tslib_1.__importDefault(require("classnames")); require("./index.less"); ; var memo = function (props) { - var akey = props.akey, version = props.version, className = props.className, style = props.style, children = props.children, _a = props.mapProps, mapProps = _a === void 0 ? {} : _a, mapRef = props.mapRef, useAMapUI = props.useAMapUI, _b = props.uiVersion, uiVersion = _b === void 0 ? '1.1' : _b, uiCallback = props.uiCallback; + var akey = props.akey, securityJsCode = props.securityJsCode, serviceHost = props.serviceHost, version = props.version, className = props.className, style = props.style, children = props.children, _a = props.mapProps, mapProps = _a === void 0 ? {} : _a, mapRef = props.mapRef, useAMapUI = props.useAMapUI, _b = props.uiVersion, uiVersion = _b === void 0 ? '1.1' : _b, uiCallback = props.uiCallback; var prefixCls = 'oak'; + (0, react_1.useEffect)(function () { + // 对安全密钥的支持 + if (serviceHost || securityJsCode) { + if (serviceHost) { + window._AMapSecurityConfig = { + serviceHost: "".concat(serviceHost, "/_AMapService"), + }; + } + else { + window._AMapSecurityConfig = { + securityJsCode: securityJsCode, + }; + } + } + }, []); (0, react_1.useEffect)(function () { if (!useAMapUI) { return;