windsome.feng пре 7 година
родитељ
комит
6b6896db22
11 измењених фајлова са 2430 додато и 45 уклоњено
  1. 115 0
      lib/APILoader.js
  2. 167 0
      lib/Map.js
  3. 147 0
      lib/Marker.js
  4. 124 0
      lib/MassMarks.js
  5. 124 0
      lib/Polygon.js
  6. 124 0
      lib/Polyline.js
  7. 561 0
      lib/api.js
  8. 50 0
      lib/loadScript.js
  9. 398 0
      lib/webservice.js
  10. 36 5
      package.json
  11. 584 40
      yarn.lock

+ 115 - 0
lib/APILoader.js

@@ -0,0 +1,115 @@
+var DEFAULT_CONFIG = {
+  v: '1.4.0',
+  hostAndPath: 'webapi.amap.com/maps',
+  key: 'f97efc35164149d0c0f299e7a8adb3d2',
+  callback: '__amap_init_callback',
+  useAMapUI: false
+};
+
+var mainPromise = null;
+var amapuiPromise = null;
+var amapuiInited = false;
+
+var APILoader = function () {
+  function APILoader(_ref) {
+    var key = _ref.key,
+        useAMapUI = _ref.useAMapUI,
+        version = _ref.version,
+        protocol = _ref.protocol;
+    babelHelpers.classCallCheck(this, APILoader);
+
+    this.config = babelHelpers.extends({}, DEFAULT_CONFIG, { useAMapUI: useAMapUI, protocol: protocol });
+    if (typeof window !== 'undefined') {
+      if (key) {
+        this.config.key = key;
+      } else if ('amapkey' in window) {
+        this.config.key = window.amapkey;
+      }
+    }
+    if (version) {
+      this.config.v = version;
+    }
+    this.protocol = protocol || window.location.protocol;
+    if (this.protocol.indexOf(':') === -1) {
+      this.protocol += ':';
+    }
+  }
+
+  babelHelpers.createClass(APILoader, [{
+    key: 'getScriptSrc',
+    value: function getScriptSrc(cfg) {
+      return this.protocol + '//' + cfg.hostAndPath + '?v=' + cfg.v + '&key=' + cfg.key + '&callback=' + cfg.callback;
+    }
+  }, {
+    key: 'buildScriptTag',
+    value: function buildScriptTag(src) {
+      var script = document.createElement('script');
+      script.type = 'text/javascript';
+      script.async = true;
+      script.defer = true;
+      script.src = src;
+      return script;
+    }
+  }, {
+    key: 'getAmapuiPromise',
+    value: function getAmapuiPromise() {
+      var script = this.buildScriptTag(this.protocol + '//webapi.amap.com/ui/1.0/main-async.js');
+      var p = new Promise(function (resolve) {
+        script.onload = function () {
+          resolve();
+        };
+      });
+      document.body.appendChild(script);
+      return p;
+    }
+  }, {
+    key: 'getMainPromise',
+    value: function getMainPromise() {
+      var _this = this;
+
+      var script = this.buildScriptTag(this.getScriptSrc(this.config));
+      var p = new Promise(function (resolve) {
+        window[_this.config.callback] = function () {
+          resolve();
+          delete window[_this.config.callback];
+        };
+      });
+      document.body.appendChild(script);
+      return p;
+    }
+  }, {
+    key: 'load',
+    value: function load() {
+      if (typeof window === 'undefined') {
+        return null;
+      }
+      var useAMapUI = this.config.useAMapUI;
+
+      mainPromise = mainPromise || this.getMainPromise();
+      if (useAMapUI) {
+        amapuiPromise = amapuiPromise || this.getAmapuiPromise();
+      }
+      return new Promise(function (resolve) {
+        mainPromise.then(function () {
+          if (useAMapUI && amapuiPromise) {
+            amapuiPromise.then(function () {
+              if (window.initAMapUI && !amapuiInited) {
+                window.initAMapUI();
+                if (typeof useAMapUI === 'function') {
+                  useAMapUI();
+                }
+                amapuiInited = true;
+              }
+              resolve();
+            });
+          } else {
+            resolve();
+          }
+        });
+      });
+    }
+  }]);
+  return APILoader;
+}();
+
+export default APILoader;

+ 167 - 0
lib/Map.js

@@ -0,0 +1,167 @@
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { loadMap, createMap, updateMap } from './api';
+
+var __com__ = 'Map';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Map = function (_Component) {
+  babelHelpers.inherits(Map, _Component);
+
+  function Map() {
+    babelHelpers.classCallCheck(this, Map);
+
+    var _this = babelHelpers.possibleConstructorReturn(this, (Map.__proto__ || Object.getPrototypeOf(Map)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'component constructor', _this.refElement, _this._entity);
+    return _this;
+  }
+
+  babelHelpers.createClass(Map, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this.refElement, this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this.refElement, this._entity);
+      var _props = this.props,
+          AMap = _props.AMap,
+          options = _props.options,
+          events = _props.events;
+
+      this._entity = createMap(AMap, this.refElement, options, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+        this.setState({ __map__: this._entity });
+      }
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this.refElement, this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this.refElement, this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this.refElement, this._entity);
+      var _props2 = this.props,
+          AMap = _props2.AMap,
+          options = _props2.options,
+          events = _props2.events;
+
+      if (!this._entity) {
+        this._entity = createMap(AMap, this.refElement, options, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+          this.setState({ __map__: this._entity });
+        }
+        return;
+      }
+      // need check props changes, then update.
+      //updateMap(this._entity, this.props, prevProps);
+      updateMap(this._entity, options, events, prevProps.options, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this.refElement, this._entity);
+      if (this._entity) {
+        var refer = this.props.refer;
+        //   this._entity.clearMap();
+
+        this._entity.destroy();
+        //   delete this._entity;
+        this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'renderChildren',
+    value: function renderChildren(children, __map__) {
+      return React.Children.map(children, function (child) {
+        if (child) {
+          var cType = child.type;
+          /* 针对下面两种组件不注入地图相关属性
+           * 1. 明确声明不需要注入的
+           * 2. DOM 元素
+           */
+          if (cType.preventAmap || typeof cType === 'string') {
+            debug(__com__, 'component renderChildren orig');
+            return child;
+          }
+          debug(__com__, 'component renderChildren add __map__');
+          return React.cloneElement(child, {
+            __map__: __map__
+          });
+        }
+        debug(__com__, 'component renderChildren null');
+        return child;
+      });
+    }
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this.refElement, this._entity);
+    //   let { AMap: oldAMap, refer: oldRefer, options: oldOptions, events: oldEvents } = this.props;
+    //   let { AMap: newAMap, refer: newRefer, options: newOptions, events: newEvents } = nextProps;
+    //   if (oldAMap === newAMap && oldRefer === newRefer && oldOptions === newOptions && oldEvents === newEvents) {
+    //     debug(__com__, 'shouldComponentUpdate', false);
+    //     return false;
+    //   }
+    //   debug(__com__, 'shouldComponentUpdate', true);
+    //   return true;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      var _this2 = this;
+
+      debug(__com__, 'component render', this._entity);
+      var _props3 = this.props,
+          AMap = _props3.AMap,
+          options = _props3.options,
+          events = _props3.events,
+          match = _props3.match,
+          location = _props3.location,
+          history = _props3.history,
+          children = _props3.children,
+          staticContext = _props3.staticContext,
+          rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'children', 'staticContext']);
+
+      return React.createElement(
+        'div',
+        babelHelpers.extends({
+          ref: function ref(ele) {
+            _this2.refElement = ele;
+          }
+        }, rest),
+        this.renderChildren(children, this._entity)
+      );
+    }
+  }]);
+  return Map;
+}(Component);
+
+Map.propTypes = {
+  AMap: PropTypes.object,
+  refer: PropTypes.func, // 类似ref的函数形式,可以让父组件调用_entity
+  options: PropTypes.object,
+  events: PropTypes.object
+  //   zoom: PropTypes.number, // 10, //设置地图显示的缩放级别
+  //   center: PropTypes.array, // [116.397428, 39.90923],//设置地图中心点坐标
+  //   layers: PropTypes.array, // [new AMap.TileLayer.Satellite()],  //设置图层,可设置成包含一个或多个图层的数组
+  //   mapStyle: PropTypes.string, // 'amap://styles/whitesmoke',  //设置地图的显示样式
+  //   viewMode: PropTypes.string, // '2D',  //设置地图模式
+  //   lang: PropTypes.string, // 'zh_cn',  //设置地图语言类型
+  //   events: PropTypes.object, // {'click': function}, // 事件map
+};
+export default Map;

+ 147 - 0
lib/Marker.js

@@ -0,0 +1,147 @@
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createMarker, updateMarker } from './api';
+var __com__ = 'Marker';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Marker = function (_Component) {
+  babelHelpers.inherits(Marker, _Component);
+
+  function Marker() {
+    babelHelpers.classCallCheck(this, Marker);
+
+    var _this = babelHelpers.possibleConstructorReturn(this, (Marker.__proto__ || Object.getPrototypeOf(Marker)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  babelHelpers.createClass(Marker, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this.props.children, this._entity);
+      var _props = this.props,
+          AMap = _props.AMap,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      this._entity = createMarker(AMap, opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
+      var _props2 = this.props,
+          AMap = _props2.AMap,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createMarker(AMap, opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
+        map: prevProps.__map__,
+        content: prevProps.children
+      });
+      updateMarker(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
+      if (this._entity) {
+        //   this._entity.clearMap();
+        this._entity.stopMove();
+        this._entity.setMap(null);
+        delete this._entity;
+        //   delete this._entity;
+        this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   let { AMap: oldAMap, refer: oldRefer, options: oldOptions, events: oldEvents } = this.props;
+    //   let { AMap: newAMap, refer: newRefer, options: newOptions, events: newEvents } = nextProps;
+    //   if (oldAMap === newAMap && oldRefer === newRefer && oldOptions === newOptions && oldEvents === newEvents) {
+    //     debug(__com__, 'shouldComponentUpdate', false);
+    //     return false;
+    //   }
+    //   debug(__com__, 'shouldComponentUpdate', true);
+    //   return true;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this.props.children, this._entity);
+      var _props3 = this.props,
+          AMap = _props3.AMap,
+          options = _props3.options,
+          events = _props3.events,
+          match = _props3.match,
+          location = _props3.location,
+          history = _props3.history,
+          staticContext = _props3.staticContext,
+          rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
+
+      return null;
+      // return (
+      //   <React.Fragment>
+      //   </React.Fragment>
+      // )
+    }
+  }]);
+  return Marker;
+}(Component);
+
+Marker.propTypes = {
+  AMap: PropTypes.object,
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+  //   zoom: PropTypes.number, // 10, //设置地图显示的缩放级别
+  //   center: PropTypes.array, // [116.397428, 39.90923],//设置地图中心点坐标
+  //   layers: PropTypes.array, // [new AMap.TileLayer.Satellite()],  //设置图层,可设置成包含一个或多个图层的数组
+  //   mapStyle: PropTypes.string, // 'amap://styles/whitesmoke',  //设置地图的显示样式
+  //   viewMode: PropTypes.string, // '2D',  //设置地图模式
+  //   lang: PropTypes.string, // 'zh_cn',  //设置地图语言类型
+  //   events: PropTypes.object, // {'click': function}, // 事件map
+};
+export default Marker;

+ 124 - 0
lib/MassMarks.js

@@ -0,0 +1,124 @@
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createMassMarks, updateMassMarks } from './api';
+var __com__ = 'MassMarks';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var MassMarks = function (_Component) {
+  babelHelpers.inherits(MassMarks, _Component);
+
+  function MassMarks() {
+    babelHelpers.classCallCheck(this, MassMarks);
+
+    var _this = babelHelpers.possibleConstructorReturn(this, (MassMarks.__proto__ || Object.getPrototypeOf(MassMarks)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  babelHelpers.createClass(MassMarks, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this.props.children, this._entity);
+      var _props = this.props,
+          AMap = _props.AMap,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      this._entity = createMassMarks(AMap, opts, events);
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
+      var _props2 = this.props,
+          AMap = _props2.AMap,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createMassMarks(AMap, opts, events);
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updateMassMarks(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
+      if (this._entity) {
+        //   this._entity.clearMap();
+        this._entity.setMap(null);
+        delete this._entity;
+        //   delete this._entity;
+        this._entity = null;
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   return false;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this.props.children, this._entity);
+      var _props3 = this.props,
+          AMap = _props3.AMap,
+          options = _props3.options,
+          events = _props3.events,
+          match = _props3.match,
+          location = _props3.location,
+          history = _props3.history,
+          staticContext = _props3.staticContext,
+          rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
+
+      return null;
+      // return (
+      //   <React.Fragment>
+      //   </React.Fragment>
+      // )
+    }
+  }]);
+  return MassMarks;
+}(Component);
+
+MassMarks.propTypes = {
+  AMap: PropTypes.object,
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default MassMarks;

+ 124 - 0
lib/Polygon.js

@@ -0,0 +1,124 @@
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createPolygon, updatePolygon } from './api';
+var __com__ = 'Polygon';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Polygon = function (_Component) {
+  babelHelpers.inherits(Polygon, _Component);
+
+  function Polygon() {
+    babelHelpers.classCallCheck(this, Polygon);
+
+    var _this = babelHelpers.possibleConstructorReturn(this, (Polygon.__proto__ || Object.getPrototypeOf(Polygon)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  babelHelpers.createClass(Polygon, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this._entity);
+      var _props = this.props,
+          AMap = _props.AMap,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      this._entity = createPolygon(AMap, opts, events);
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this._entity);
+      var _props2 = this.props,
+          AMap = _props2.AMap,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createPolygon(AMap, opts, events);
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updatePolygon(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this._entity);
+      if (this._entity) {
+        //   this._entity.clearMap();
+        this._entity.setMap(null);
+        delete this._entity;
+        //   delete this._entity;
+        this._entity = null;
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   return false;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this._entity);
+      var _props3 = this.props,
+          AMap = _props3.AMap,
+          options = _props3.options,
+          events = _props3.events,
+          match = _props3.match,
+          location = _props3.location,
+          history = _props3.history,
+          staticContext = _props3.staticContext,
+          rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
+
+      return null;
+      // return (
+      //   <React.Fragment>
+      //   </React.Fragment>
+      // )
+    }
+  }]);
+  return Polygon;
+}(Component);
+
+Polygon.propTypes = {
+  AMap: PropTypes.object,
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default Polygon;

+ 124 - 0
lib/Polyline.js

@@ -0,0 +1,124 @@
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createPolyline, updatePolyline } from './api';
+var __com__ = 'Polyline';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Polyline = function (_Component) {
+  babelHelpers.inherits(Polyline, _Component);
+
+  function Polyline() {
+    babelHelpers.classCallCheck(this, Polyline);
+
+    var _this = babelHelpers.possibleConstructorReturn(this, (Polyline.__proto__ || Object.getPrototypeOf(Polyline)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  babelHelpers.createClass(Polyline, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this.props.children, this._entity);
+      var _props = this.props,
+          AMap = _props.AMap,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      this._entity = createPolyline(AMap, opts, events);
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
+      var _props2 = this.props,
+          AMap = _props2.AMap,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createPolyline(AMap, opts, events);
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updatePolyline(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
+      if (this._entity) {
+        //   this._entity.clearMap();
+        this._entity.setMap(null);
+        delete this._entity;
+        //   delete this._entity;
+        this._entity = null;
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   return false;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this.props.children, this._entity);
+      var _props3 = this.props,
+          AMap = _props3.AMap,
+          options = _props3.options,
+          events = _props3.events,
+          match = _props3.match,
+          location = _props3.location,
+          history = _props3.history,
+          staticContext = _props3.staticContext,
+          rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
+
+      return null;
+      // return (
+      //   <React.Fragment>
+      //   </React.Fragment>
+      // )
+    }
+  }]);
+  return Polyline;
+}(Component);
+
+Polyline.propTypes = {
+  AMap: PropTypes.object,
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default Polyline;

+ 561 - 0
lib/api.js

@@ -0,0 +1,561 @@
+import forOwn from 'lodash/forOwn';
+import isEqual from 'lodash/isEqual';
+import isNil from 'lodash/isNil';
+//import loadjscssfile from './loadScript';
+import APILoader from './APILoader';
+
+export var loadApi = function loadApi() {
+  var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0325e3d6d69cd56de4980b4f28906fd8';
+
+  return new APILoader({
+    key: key,
+    useAMapUI: false,
+    version: '1.4.7',
+    protocol: 'https'
+  }).load();
+};
+export var loadMap = function loadMap(key) {
+  return new Promise(function (resolve, reject) {
+    if (window.AMap) {
+      resolve(window.AMap);
+    }
+    loadApi(key).then(function (ret) {
+      if (window.AMap) {
+        resolve(window.AMap);
+      } else {
+        reject(new Error('window.AMap不存在!'));
+      }
+    }).catch(function (error) {
+      reject(new Error('加载地图错误!' + error.message));
+    });
+  });
+};
+
+// export const loadApiV1 = async (key = '0325e3d6d69cd56de4980b4f28906fd8') => {
+//   return await loadjscssfile(
+//     'https://webapi.amap.com/maps?v=1.4.7&key=' + key,
+//     'js'
+//   );
+// };
+
+// export const loadMapV1 = key => {
+//   return new Promise((resolve, reject) => {
+//     if (window.AMap) {
+//       resolve(window.AMap);
+//     }
+//     loadApi(key)
+//       .then(ret => {
+//         if (window.AMap) {
+//           resolve(window.AMap);
+//         } else {
+//           reject(new Error('window.AMap不存在!'));
+//         }
+//       })
+//       .catch(error => {
+//         reject(new Error('加载地图错误!' + error.message));
+//       });
+//   });
+// };
+
+/**
+ * [加载插件](https://lbs.amap.com/api/javascript-api/guide/abc/plugins)
+ * 加载完成后,可以调用:
+ *  var toolbar = new AMap.ToolBar();
+ *  map.addControl(toolbar);
+ * @param {string} name 插件名或插件数组,如:AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
+ */
+export var loadPlugin = function loadPlugin(name) {
+  return new Promise(function (resolve, reject) {
+    if (window.AMap) {
+      window.AMap.plugin(name, function () {
+        resolve(true);
+      });
+      //是否有加载失败的情况,如果加载失败,怎么reject?
+    } else {
+      reject(new Error('地图还未加载!'));
+    }
+  });
+};
+
+////////////////////////////////////////////////////////////
+// Map
+////////////////////////////////////////////////////////////
+export var createMap = function createMap(AMap, dom, options, events) {
+  var __func__ = 'createMap';
+  if (!AMap) {
+    console.log(__func__, 'fail! no AMap!');
+    return null;
+  }
+  if (!dom) {
+    console.log(__func__, 'fail! no dom!');
+    return null;
+  }
+  var map = new AMap.Map(dom, babelHelpers.extends({}, options || {}));
+  forOwn(events, function (value, key) {
+    console.log(__func__, 'event on ' + key);
+    map.on(key, value);
+  });
+  console.log(__func__, 'ok!');
+  return map;
+};
+
+export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
+  var __func__ = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'commonUpdate';
+
+  // const __func__ = 'commonUpdate';
+  if (!entity) {
+    console.log(__func__, 'fail! no entity!');
+    return false;
+  }
+
+  // 找到改变的属性集合,包含添加,删除及修改的属性,删除的置为null
+  var props = {};
+  if (newOptions != oldOptions) {
+    oldOptions && forOwn(oldOptions, function (value, key) {
+      // 找到改变的旧属性,用新属性取代
+      var newValue = newOptions && newOptions[key];
+      if (!isEqual(newValue, value)) {
+        if (!(isNil(newValue) && isNil(value))) props[key] = newValue;
+      }
+    });
+    newOptions && forOwn(newOptions, function (value, key) {
+      // 找到新加的属性,添加进去
+      var oldValue = oldOptions && oldOptions[key];
+      if (isNil(oldValue) && !isNil(value)) {
+        props[key] = value;
+      }
+    });
+  }
+  // 找到改变的事件集合,包含添加,删除及修改的事件处理函数,删除的置为null
+  var events = {};
+  if (newEvents != oldEvents) {
+    oldEvents && forOwn(oldEvents, function (value, key) {
+      // 找到改变的旧属性,用新属性取代
+      var newValue = newEvents && newEvents[key];
+      if (!isEqual(newValue, value)) {
+        if (!(isNil(newValue) && isNil(value))) events[key] = newValue;
+      }
+    });
+    newEvents && forOwn(newEvents, function (value, key) {
+      // 找到新加的属性,添加进去
+      var oldValue = oldEvents && oldEvents[key];
+      if (isNil(oldValue) && !isNil(value)) {
+        events[key] = value;
+      }
+    });
+  }
+
+  // let operators = {
+  //   map: v => entity.setMap(v),
+  //   position: v => entity.setPosition(v),
+  //   offset: v => entity.setOffset(v),
+  //   icon: v => entity.setIcon(v),
+  //   content: v => entity.setContent(v),
+  //   topWhenClick: null,
+  //   bubble: null,
+  //   draggable: v => entity.setDraggable(v),
+  //   raiseOnDrag: null,
+  //   cursor: v => entity.setCursor(v),
+  //   visible: null,
+  //   zIndex: v => entity.setzIndex(v),
+  //   angle: v => entity.setAngle(v),
+  //   autoRotation: null,
+  //   animation: v => entity.setAnimation(v),
+  //   shadow: v => entity.setShadow(v),
+  //   title: v => entity.setTitle(v),
+  //   clickable: v => entity.setClickable(v),
+  //   shape: v => entity.setShape(v),
+  //   extData: v => entity.setExtData(v),
+  //   label: v => entity.setLabel(v)
+  // };
+
+  forOwn(props, function (value, key) {
+    if (value) {
+      var func = operators[key];
+      if (func) {
+        func(value);
+      } else {
+        // ignore properties can not set.
+        console.log(__func__, 'warning! no setter! can not update ' + key);
+      }
+    } else {
+      // key removed, not support!
+      console.log(__func__, 'warning! remove prop not support! key=' + key);
+    }
+  });
+  forOwn(events, function (value, key) {
+    var oldFunc = oldEvents && oldEvents[key];
+    if (oldFunc) {
+      entity.off(key, oldFunc);
+    }
+    if (value) {
+      entity.on(key, value);
+    }
+  });
+  console.log(__func__, 'update:', props, events
+  // newOptions,
+  // newEvents,
+  // oldOptions,
+  // oldEvents
+  );
+  return true;
+};
+
+export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    view: null,
+    layers: function layers(v) {
+      return map.setLayers(v);
+    },
+    zoom: function zoom(v) {
+      return map.setZoom(v);
+    },
+    center: function center(v) {
+      return map.setCenter(v);
+    },
+    labelzIndex: function labelzIndex(v) {
+      return map.setlabelzIndex(v);
+    },
+    zooms: null,
+    lang: function lang(v) {
+      return map.setLang(v);
+    },
+    defaultCursor: function defaultCursor(v) {
+      return map.setDefaultCursor(v);
+    },
+    crs: null,
+    animateEnable: null,
+    isHotspot: function isHotspot(v) {
+      return map.setStatus({ isHotspot: v });
+    },
+    defaultLayer: function defaultLayer(v) {
+      return map.setDefaultLayer(v);
+    },
+    rotateEnable: null,
+    resizeEnable: null,
+    showIndoorMap: null,
+    indoorMap: null,
+    expandZoomRange: null,
+    dragEnable: function dragEnable(v) {
+      return map.setStatus({ dragEnable: v });
+    },
+    zoomEnable: null,
+    doubleClickZoom: function doubleClickZoom(v) {
+      return map.setStatus({ doubleClickZoom: v });
+    },
+    keyboardEnable: function keyboardEnable(v) {
+      return map.setStatus({ keyboardEnable: v });
+    },
+    jogEnable: null,
+    scrollWheel: null,
+    touchZoom: null,
+    touchZoomCenter: null,
+    mapStyle: function mapStyle(v) {
+      return map.setMapStyle(v);
+    },
+    features: function features(v) {
+      return map.setFeatures(v);
+    },
+    showBuildingBlock: null,
+    viewMode: null,
+    pitch: function pitch(v) {
+      return map.setPitch(v);
+    },
+    pitchEnable: null,
+    buildAnimation: null,
+    skyColor: null,
+    preloadMode: null
+  };
+  return commonUpdate(map, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMap');
+};
+
+////////////////////////////////////////////////////////////
+// Marker
+////////////////////////////////////////////////////////////
+/**
+ *
+ * @param {*} AMap
+ * @param {*} map
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
+ * @param {*} events
+ */
+export var createMarker = function createMarker(AMap, options, events) {
+  var __func__ = 'createMarker';
+  if (!AMap) {
+    console.log(__func__, 'fail! no AMap!');
+    return null;
+  }
+  if (!options) {
+    console.log(__func__, 'fail! no options!');
+    return null;
+  }
+  if (!options.map) {
+    console.log(__func__, 'fail! no options.map!');
+    return null;
+  }
+  // let marker = new AMap.Marker({
+  //   icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
+  //   position: [116.405467, 39.907761]
+  // });
+  // marker.setMap(map);
+  var entity = new AMap.Marker(options);
+  forOwn(events, function (value, key) {
+    entity.on(key, value);
+  });
+  console.log(__func__, 'ok!');
+  return entity;
+};
+
+export var updateMarker = function updateMarker(entity, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    map: function map(v) {
+      return entity.setMap(v);
+    },
+    position: function position(v) {
+      return entity.setPosition(v);
+    },
+    offset: function offset(v) {
+      return entity.setOffset(v);
+    },
+    icon: function icon(v) {
+      return entity.setIcon(v);
+    },
+    content: function content(v) {
+      return entity.setContent(v);
+    },
+    topWhenClick: null,
+    bubble: null,
+    draggable: function draggable(v) {
+      return entity.setDraggable(v);
+    },
+    raiseOnDrag: null,
+    cursor: function cursor(v) {
+      return entity.setCursor(v);
+    },
+    visible: null,
+    zIndex: function zIndex(v) {
+      return entity.setzIndex(v);
+    },
+    angle: function angle(v) {
+      return entity.setAngle(v);
+    },
+    autoRotation: null,
+    animation: function animation(v) {
+      return entity.setAnimation(v);
+    },
+    shadow: function shadow(v) {
+      return entity.setShadow(v);
+    },
+    title: function title(v) {
+      return entity.setTitle(v);
+    },
+    clickable: function clickable(v) {
+      return entity.setClickable(v);
+    },
+    shape: function shape(v) {
+      return entity.setShape(v);
+    },
+    extData: function extData(v) {
+      return entity.setExtData(v);
+    },
+    label: function label(v) {
+      return entity.setLabel(v);
+    }
+  };
+
+  return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMarker');
+};
+
+////////////////////////////////////////////////////////////
+// MassMarks, warning! is a layer!
+////////////////////////////////////////////////////////////
+/**
+ *
+ * @param {*} AMap
+ * @param {*} map
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
+ * @param {*} events
+ */
+var createMassMarks = function createMassMarks(AMap, options, events) {
+  var __func__ = 'createMassMarks';
+  if (!AMap) {
+    console.log(__func__, 'fail! no AMap!');
+    return null;
+  }
+  if (!options) {
+    console.log(__func__, 'fail! no options!');
+    return null;
+  }
+  var map = options.map,
+      data = options.data,
+      restOpts = babelHelpers.objectWithoutProperties(options, ['map', 'data']);
+
+  var entity = new AMap.MassMarks(data, restOpts);
+  forOwn(events, function (value, key) {
+    entity.on(key, value);
+  });
+  if (map) {
+    entity.setMap(map);
+  }
+  console.log(__func__, 'ok!');
+  return entity;
+};
+
+export { createMassMarks };
+export var updateMassMarks = function updateMassMarks(entity, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    zIndex: function zIndex(v) {
+      return entity.setzIndex(v);
+    },
+    opacity: null,
+    zooms: null,
+    cursor: function cursor(v) {
+      return entity.setCursor(v);
+    },
+    alwaysRender: null,
+    style: function style(v) {
+      return entity.setStyle(v);
+    },
+    map: function map(v) {
+      return entity.setMap(v);
+    },
+    data: function data(v) {
+      return entity.setData(v);
+    }
+  };
+
+  return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMassMarks');
+};
+
+////////////////////////////////////////////////////////////
+// Polygon
+////////////////////////////////////////////////////////////
+/**
+ *
+ * @param {*} AMap
+ * @param {*} map
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
+ * @param {*} events
+ */
+export var createPolygon = function createPolygon(AMap, options, events) {
+  var __func__ = 'createPolygon';
+  if (!AMap) {
+    console.log(__func__, 'fail! no AMap!');
+    return null;
+  }
+  if (!options) {
+    console.log(__func__, 'fail! no options!');
+    return null;
+  }
+  if (!options.map) {
+    console.log(__func__, 'fail! no options.map!');
+    return null;
+  }
+  var entity = new AMap.Polygon(options);
+  forOwn(events, function (value, key) {
+    entity.on(key, value);
+  });
+  console.log(__func__, 'ok!');
+  return entity;
+};
+
+export var updatePolygon = function updatePolygon(entity, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    map: function map(v) {
+      return entity.setMap(v);
+    },
+    zIndex: function zIndex(v) {
+      return entity.setzIndex(v);
+    },
+    path: function path(v) {
+      return entity.setPath(v);
+    },
+    bubble: null,
+    cursor: null,
+    strokeColor: null,
+    strokeOpacity: null,
+    strokeWeight: null,
+    fillColor: null,
+    fillOpacity: null,
+    draggable: null,
+    extData: function extData(v) {
+      return entity.setExtData(v);
+    },
+    strokeStyle: null,
+    strokeDasharray: null,
+    options: function options(v) {
+      return entity.setOptions(v);
+    }
+  };
+
+  return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolygon');
+};
+
+////////////////////////////////////////////////////////////
+// Polyline
+////////////////////////////////////////////////////////////
+/**
+ *
+ * @param {*} AMap
+ * @param {*} map
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
+ * @param {*} events
+ */
+export var createPolyline = function createPolyline(AMap, options, events) {
+  var __func__ = 'createPolyline';
+  if (!AMap) {
+    console.log(__func__, 'fail! no AMap!');
+    return null;
+  }
+  if (!options) {
+    console.log(__func__, 'fail! no options!');
+    return null;
+  }
+  if (!options.map) {
+    console.log(__func__, 'fail! no options.map!');
+    return null;
+  }
+  var entity = new AMap.Polyline(options);
+  forOwn(events, function (value, key) {
+    entity.on(key, value);
+  });
+  console.log(__func__, 'ok!');
+  return entity;
+};
+
+export var updatePolyline = function updatePolyline(entity, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    map: function map(v) {
+      return entity.setMap(v);
+    },
+    zIndex: function zIndex(v) {
+      return entity.setzIndex(v);
+    },
+    bubble: null,
+    cursor: null,
+    gedodesic: null,
+    isOutline: null,
+    borderWeight: null,
+    outlineColor: null,
+    path: function path(v) {
+      return entity.setPath(v);
+    },
+    strokeColor: null,
+    strokeOpacity: null,
+    strokeWeight: null,
+    strokeStyle: null,
+    strokeDasharray: null,
+    lineJoin: null,
+    lineCap: null,
+    draggable: null,
+    extData: function extData(v) {
+      return entity.setExtData(v);
+    },
+    showDir: null,
+    options: function options(v) {
+      return entity.setOptions(v);
+    }
+  };
+
+  return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolyline');
+};

+ 50 - 0
lib/loadScript.js

@@ -0,0 +1,50 @@
+/**
+ * see: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
+ */
+import indexOf from 'lodash/indexOf';
+
+var gFileList = []; //list of files already added
+var loadjscssfile = function loadjscssfile(filename, filetype) {
+  return new Promise(function (resolve, reject) {
+    if (indexOf(gFileList, filename) >= 0) {
+      console.log('loadScript: already load! ' + filename);
+      resolve(true);
+      return;
+    }
+    var fileref = null;
+    if (filetype == 'js') {
+      //if filename is a external JavaScript file
+      fileref = document.createElement('script');
+      fileref.setAttribute('type', 'text/javascript');
+      fileref.setAttribute('src', filename);
+    } else if (filetype == 'css') {
+      //if filename is an external CSS file
+      fileref = document.createElement('link');
+      fileref.setAttribute('rel', 'stylesheet');
+      fileref.setAttribute('type', 'text/css');
+      fileref.setAttribute('href', filename);
+    } else {
+      reject(new Error('not support![' + filetype + '] ' + filename));
+    }
+    if (typeof fileref == 'undefined' || fileref == null) {
+      reject(new Error('error! fileref=' + fileref));
+    }
+
+    fileref.onload = function (res) {
+      console.log('loadScript: onload:', res);
+      gFileList.push(filename); //List of files added in the form "[filename1],[filename2],etc"
+      resolve(true);
+    };
+    fileref.onerror = function (error) {
+      console.log('loadScript: onerror:', error);
+      reject(new Error('load fail! ' + filename));
+    };
+    fileref.onabort = function (error) {
+      console.log('loadScript: onerror:', error);
+      reject(new Error('load abort! ' + filename));
+    };
+    document.getElementsByTagName('head')[0].appendChild(fileref);
+  });
+};
+
+export default loadjscssfile;

+ 398 - 0
lib/webservice.js

@@ -0,0 +1,398 @@
+import forOwn from 'lodash/forOwn';
+import isEqual from 'lodash/isEqual';
+import isNil from 'lodash/isNil';
+import isUndefined from 'lodash/isUndefined';
+
+// M: Mandatory,必选
+// api调用限流说明: https://lbs.amap.com/api/webservice/guide/tools/flowlevel
+
+export var services = {
+  // 地理/逆地理编码: https://lbs.amap.com/api/webservice/guide/api/georegeo
+  geocode_geo: {
+    name: '地理编码',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/geocode/geo',
+    parameters: {
+      key: undefined, // M
+      address: undefined, // M
+      city: undefined, // M
+      batch: false,
+      sig: undefined,
+      output: 'JSON',
+      callback: null
+    }
+  },
+  geocode_regeo: {
+    name: '逆地理编码',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/geocode/regeo',
+    parameters: {
+      key: undefined, // M
+      location: undefined, // M
+      poitype: undefined,
+      radius: 1000,
+      extensions: 'base',
+      batch: false,
+      roadlevel: undefined,
+      sig: undefined,
+      output: 'JSON',
+      callback: null,
+      homeorcorp: 0
+    }
+  },
+  // 路径规划: https://lbs.amap.com/api/webservice/guide/api/direction
+  direction_walking: {
+    name: '步行路径规划',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/direction/walking',
+    parameters: {
+      key: undefined, // M
+      origin: undefined, // M
+      destination: undefined, // M
+      sig: undefined,
+      output: 'JSON',
+      callback: null
+    }
+  },
+  direction_transit_integrated: {
+    name: '公交路径规划',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/direction/transit/integrated',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  direction_driving: {
+    name: '驾车路径规划',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/direction/driving',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  direction_bicycling: {
+    name: '骑行路径规划',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v4/direction/bicycling',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  direction_truck: {
+    name: '货车路径规划',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v4/direction/truck',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  distance: {
+    name: '距离测量',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/distance',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  // 行政区域查询: https://lbs.amap.com/api/webservice/guide/api/district
+  config_district: {
+    name: '行政区域查询',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/config/district',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 搜索POI: https://lbs.amap.com/api/webservice/guide/api/search
+  place_text: {
+    name: '关键字搜索',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/place/text',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  place_around: {
+    name: '周边搜索',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/place/around',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  place_polygon: {
+    name: '多边形搜索',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/place/polygon',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  place_detail: {
+    name: 'ID查询',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/place/detail',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // IP定位: https://lbs.amap.com/api/webservice/guide/api/ipconfig
+  ip: {
+    name: 'IP定位',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/ip',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 抓路服务: https://lbs.amap.com/api/webservice/guide/api/autograsp
+  autograsp: {
+    name: '抓路服务',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/autograsp',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 批量请求接口: https://lbs.amap.com/api/webservice/guide/api/batchrequest
+  batch: {
+    name: '批量请求接口',
+    method: 'POST',
+    url: 'https://restapi.amap.com/v3/batch',
+    parameters: {
+      key: undefined // M
+    },
+    body: {
+      "ops": [{
+        "url": "/v3/place/around?offset=10&page=1&key=<您的key>&location=116.50394379585519,39.278209477408794&output=json&radius=100000&types=080000"
+      }, {
+        "url": "/v3/place/around?offset=10&page=1&key=<您的key>&location=118.50394379585519,39.278209477408794&output=json&radius=100000&types=080000"
+      }]
+    }
+  },
+
+  // 静态地图: https://lbs.amap.com/api/webservice/guide/api/staticmaps
+  staticmap: {
+    name: '静态地图',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/staticmap',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 坐标转换: https://lbs.amap.com/api/webservice/guide/api/convert
+  assistant_coordinate_convert: {
+    name: '坐标转换',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/assistant/coordinate/convert',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 天气查询: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
+  weather_weatherInfo: {
+    name: '天气查询',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/weather/weatherInfo',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 输入提示: https://lbs.amap.com/api/webservice/guide/api/inputtips
+  assistant_inputtips: {
+    name: '输入提示',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/assistant/inputtips',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 交通态势: https://lbs.amap.com/api/webservice/guide/api/trafficstatus
+  traffic_status_rectangle: {
+    name: '矩形区域交通态势',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/traffic/status/rectangle',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  traffic_status_circle: {
+    name: '圆形区域交通态势',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/traffic/status/circle',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  traffic_status_road: {
+    name: '指定线路交通态势',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v3/traffic/status/road',
+    parameters: {
+      key: undefined // M
+    }
+  },
+
+  // 地理围栏: https://lbs.amap.com/api/webservice/guide/api/geofence_service
+  geofence_meta_post: {
+    name: '创建围栏',
+    method: 'POST',
+    url: 'https://restapi.amap.com/v4/geofence/meta',
+    parameters: {
+      key: undefined // M
+    },
+    body: {
+      name: undefined //M
+    }
+  },
+  geofence_meta_get: {
+    name: '查询围栏',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v4/geofence/meta',
+    parameters: {
+      key: undefined // M
+    }
+  },
+  geofence_meta_patch: {
+    name: '更新围栏',
+    method: 'POST ', // PATCH
+    url: 'https://restapi.amap.com/v4/geofence/meta',
+    parameters: {
+      key: undefined, // M
+      gid: undefined, // M
+      method: undefined // 'patch'
+    },
+    body: {
+      name: undefined //M
+    }
+  },
+  geofence_meta_patch2: {
+    name: '围栏启动&停止',
+    method: 'POST ', // PATCH
+    url: 'https://restapi.amap.com/v4/geofence/meta',
+    parameters: {
+      key: undefined, // M
+      gid: undefined, //M
+      method: undefined //'patch'
+    },
+    body: {
+      name: undefined //M
+    }
+  },
+  geofence_meta_delete: {
+    name: '删除围栏',
+    method: 'DELETE ', // POST
+    url: 'https://restapi.amap.com/v4/geofence/meta',
+    parameters: {
+      key: undefined, // M
+      gid: undefined, //M
+      method: undefined //'delete'
+    },
+    body: {
+      name: undefined //M
+    }
+  },
+  geofence_status: {
+    name: '围栏设备监控',
+    method: 'GET',
+    url: 'https://restapi.amap.com/v4/geofence/status',
+    parameters: {
+      key: undefined, // M
+      diu: undefined, // M
+      uid: undefined,
+      locations: undefined, // M
+      sig: undefined
+    }
+  },
+
+  // 轨迹纠偏: https://lbs.amap.com/api/webservice/guide/api/grasproad
+  grasproad_driving: {
+    name: '轨迹纠偏',
+    method: 'POST',
+    url: 'https://restapi.amap.com/v4/grasproad/driving',
+    parameters: {
+      key: undefined // M
+    },
+    body: {
+      x: undefined, // M
+      y: undefined, // M
+      ag: undefined, // M
+      tm: undefined, // M
+      sp: undefined // M
+    }
+  }
+
+};
+
+export var infocode = {
+  "10000": {
+    info: 'OK',
+    desc: '请求正常',
+    suggest: '请求正常'
+  },
+  "10001": {
+    info: 'INVALID_USER_KEY',
+    desc: 'key不正确或过期',
+    suggest: '开发者发起请求时,传入的key不正确或者过期 '
+  },
+  "10002": {
+    info: 'SERVICE_NOT_AVAILABLE',
+    desc: '没有权限使用相应的服务或者请求接口的路径拼写错误',
+    suggest: '1.开发者没有权限使用相应的服务,例如:开发者申请了WEB定位功能的key,却使用该key访问逆地理编码功能时,就会返回该错误。反之亦然。2.开发者请求接口的路径拼写错误。例如:正确的https://restapi.amap.com/v3/ip在程序中被拼装写了https://restapi.amap.com/vv3/ip"'
+  }
+};
+
+export var getRequest = function getRequest(service, parameters, body) {
+  if (!service) return null;
+
+  var option = {};
+  var name = service.name,
+      url = service.url,
+      method = service.method,
+      dfParameters = service.parameters,
+      dfBody = service.body;
+
+  var destParameters = babelHelpers.extends({}, dfParameters || {}, parameters || {});
+
+  // 组建url中参数
+  var paramArr = [];
+  forOwn(destParameters, function (value, key) {
+    if (!isNil(value)) {
+      paramArr.push(key + '=' + value);
+    }
+  });
+  if (paramArr.length > 0) {
+    url += '?' + paramArr.join('&');
+  }
+  // 组建option
+  if (method === 'GET') {
+    option = {
+      credentials: 'include',
+      method: method,
+      headers: { 'Content-Type': 'application/json' }
+    };
+  } else if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
+    var destBody = babelHelpers.extends({}, dfBody || {}, body || {});
+    option = {
+      credentials: 'include',
+      method: method,
+      headers: { 'Content-Type': 'application/json' },
+      body: destBody
+    };
+  } else {
+    console.log('error! not support method=' + method + ' of ' + name);
+  }
+
+  return {
+    url: url,
+    option: option
+  };
+};

+ 36 - 5
package.json

@@ -11,6 +11,13 @@
   ],
   "homepage": "https://github.com/windsome/react-amap-next",
   "author": "windsome.feng <36081189@qq.com> (https://github.com/windsome/)",
+  "scripts": {
+    "build:umd": "cross-env BABEL_ENV=umd babel src/lib --out-dir lib",
+    "start": "react-scripts start",
+    "build": "react-scripts build",
+    "test": "react-scripts test --env=jsdom",
+    "eject": "react-scripts eject"
+  },
   "dependencies": {
     "classnames": "^2.2.6",
     "lodash": "^4.17.10",
@@ -18,10 +25,34 @@
     "react-dom": "^16.4.1",
     "react-scripts": "1.1.4"
   },
-  "scripts": {
-    "start": "react-scripts start",
-    "build": "react-scripts build",
-    "test": "react-scripts test --env=jsdom",
-    "eject": "react-scripts eject"
+  "devDependencies": {
+    "babel-cli": "6.14.0",
+    "babel-plugin-external-helpers": "^6.22.0",
+    "babel-plugin-transform-class-properties": "^6.24.1",
+    "babel-plugin-transform-object-rest-spread": "^6.26.0",
+    "babel-preset-env": "^1.6.1",
+    "babel-preset-react": "^6.24.1",
+    "cross-env": "^5.1.4",
+    "prop-types": "^15.6.0"
+  },
+  "babel": {
+    "env": {
+      "umd": {
+        "presets": [
+          [
+            "env",
+            {
+              "modules": false
+            }
+          ],
+          "react"
+        ],
+        "plugins": [
+          "transform-object-rest-spread",
+          "transform-class-properties",
+          "external-helpers"
+        ]
+      }
+    }
   }
 }

Разлика између датотеке није приказан због своје велике величине
+ 584 - 40
yarn.lock


Неке датотеке нису приказане због велике количине промена