Skip to content

Commit

Permalink
修复使用的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
徐海涛 committed Oct 12, 2020
1 parent 1a42955 commit 3111009
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/react-bf-amap.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as AMapLoader from '@amap/amap-jsapi-loader'; // export interface BF_AM
// plugins: string[];
// }

var Index = function Index(props) {
var BFAMap = function BFAMap(props) {
// 参数,plugins:[], id 需要在全局配置
var AMapUI = props.AMapUI,
loca = props.loca,
Expand All @@ -33,14 +33,12 @@ var Index = function Index(props) {
};

if (AMapUI) {
// @ts-ignore
option = _objectSpread(_objectSpread({}, option), {}, {
AMapUI: AMapUI
});
}

if (loca) {
// @ts-ignore
option = _objectSpread(_objectSpread({}, option), {}, {
Loca: {
version: '1.3.2'
Expand Down Expand Up @@ -73,7 +71,7 @@ var Index = function Index(props) {
});
};

export default Index; // AMapUI: { // 是否加载 AMapUI,缺省不加载
export { BFAMap }; // AMapUI: { // 是否加载 AMapUI,缺省不加载
// version: '1.1', // AMapUI 缺省 1.1
// plugins: [], // 需要加载的 AMapUI ui插件
// },
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "react-bf-amap",
"version": "0.1.0",
"version": "0.9.0",
"main": "dist/index.js",
"module": "dist/index.js",
"license": "MIT",
"files": [
"dist",
"README.md"
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Index from "./lib";
// import BFAMap from "./lib/index";
import BFAMap from "./lib/index2";

ReactDOM.render(
<div style={{ width: '600px', height: '600px' }}>
{/* eslint-disable-next-line react/jsx-pascal-case */}
<Index
<BFAMap
id="a_map"
map_key={window.AMAP_KEY}
options={{
Expand Down
6 changes: 2 additions & 4 deletions src/lib/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as AMapLoader from '@amap/amap-jsapi-loader';
// plugins: string[];
// }

const Index = (props) => {
const BFAMap = (props) => {

// 参数,plugins:[], id 需要在全局配置
const { AMapUI, loca, plugins, setMap, options, id, map_key } = props;
Expand All @@ -26,11 +26,9 @@ const Index = (props) => {
plugins: plugins?.map(im => `AMap.${im}`) || [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
};
if (AMapUI) {
// @ts-ignore
option = { ...option, AMapUI: AMapUI };
}
if (loca) {
// @ts-ignore
option = { ...option, Loca: { version: '1.3.2' } };
}
AMapLoader.load({ ...option }).then((AMap) => {
Expand Down Expand Up @@ -58,7 +56,7 @@ const Index = (props) => {
);
};

export default Index;
export { BFAMap };

// AMapUI: { // 是否加载 AMapUI,缺省不加载
// version: '1.1', // AMapUI 缺省 1.1
Expand Down
80 changes: 80 additions & 0 deletions src/lib/index2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import React, { useEffect, useRef } from 'react';
import * as AMapLoader from '@amap/amap-jsapi-loader'; // export interface BF_AMapProps {
// AMapUI: any;
// loca: boolean;
// key: string;
// id: string;
// options: any;
// setMap: Function;
// plugins: string[];
// }

var BFAMap = function(props) {
// 参数,plugins:[], id 需要在全局配置
var AMapUI = props.AMapUI,
loca = props.loca,
plugins = props.plugins,
setMap = props.setMap,
options = props.options,
id = props.id,
map_key = props.map_key;
console.log(map_key);
var map = useRef();

var initMap = function initMap() {
var option = {
key: map_key,
version: '2.0',
plugins: (plugins === null || plugins === void 0 ? void 0 : plugins.map(function (im) {
return "AMap.".concat(im);
})) || [] // 需要使用的的插件列表,如比例尺'AMap.Scale'等

};

if (AMapUI) {
option = _objectSpread(_objectSpread({}, option), {}, {
AMapUI: AMapUI
});
}

if (loca) {
option = _objectSpread(_objectSpread({}, option), {}, {
Loca: {
version: '1.3.2'
}
});
}

AMapLoader.load(_objectSpread({}, option)).then(function (AMap) {
var _map = new AMap.Map(id, _objectSpread({}, options));

setMap(_map, AMap);
});
};

useEffect(function () {
if (map.current) {
// @ts-ignore
map.current.style.width = '100%'; // @ts-ignore

map.current.style.height = '100%';
initMap();
}
}, [map]);
if (!setMap || typeof setMap !== 'function') return null;
if (!id) console.error('没有传入唯一ID!,There is no id!');
if (!map_key) console.error('没有传入key!,There is no map key!');
return /*#__PURE__*/React.createElement("div", {
ref: map,
id: id
});
};

export default BFAMap; // AMapUI: { // 是否加载 AMapUI,缺省不加载
// version: '1.1', // AMapUI 缺省 1.1
// plugins: [], // 需要加载的 AMapUI ui插件
// },
// Loca: { // 是否加载 Loca, 缺省不加载
// version: '1.3.2' // Loca 版本,缺省 1.3.2
// },

0 comments on commit 3111009

Please sign in to comment.