Browse Source

replace AMap with window.AMap, not to pass AMap from outside.
find a bug in Map->options->layers.

windsome.feng 7 years ago
parent
commit
d99bbf0d2f
16 changed files with 404 additions and 469 deletions
  1. 3 0
      README.md
  2. 21 32
      lib/Map.js
  3. 3 25
      lib/Marker.js
  4. 19 35
      lib/MassMarks.js
  5. 10 25
      lib/Polygon.js
  6. 11 26
      lib/Polyline.js
  7. 118 80
      lib/api.js
  8. 1 1
      package.json
  9. 60 34
      src/App.js
  10. 12 21
      src/lib/InfoWindow.js
  11. 21 30
      src/lib/Map.js
  12. 5 22
      src/lib/Marker.js
  13. 20 30
      src/lib/MassMarks.js
  14. 13 23
      src/lib/Polygon.js
  15. 13 23
      src/lib/Polyline.js
  16. 74 62
      src/lib/api.js

+ 3 - 0
README.md

@@ -50,6 +50,9 @@ npm start
 1. `loadScript.js`是用来加载js和css的,希望能确保加载文件的唯一性,可以参考requirejs的实现机制改掉.
 2. 与`react-amap`的不同之处,加载高德地图js与`Map`,`Marker`等组件是分离的.
 
+## 已知问题
+1. 有时海量点图层(`MassMarks`层)不显示,见此版本例子中的`App.js`,首先点击MarkerTest,然后再打开MassMarksTest,会发现海量点图层有时不显示.原因为:MassMarks层是属于Map的其中一个层,如果Map的layers属性后于海量点图层加载,则海量点图层会被layers属性替代. 建议以后将所有图层均做成组件,并且Map组件不再支持layers属性.
+
 ## 反馈
 We are always open to [your feedback](https://github.com/windsome/react-amap-next/issues).
 

+ 21 - 32
lib/Map.js

@@ -2,8 +2,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
 
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
-function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
-
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -12,7 +10,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
 
 import React, { Component, PureComponent } from 'react';
 import PropTypes from 'prop-types';
-import { loadMap, createMap, updateMap } from './api';
+import { createMap, updateMap } from './api';
 
 var __com__ = 'Map';
 //const debug = console.log;
@@ -28,25 +26,24 @@ export var Map = function (_Component) {
 
     _this.refElement = null;
     _this._entity = null;
-    debug(__com__, 'component constructor', _this.refElement, _this._entity);
+    debug(__com__, 'component constructor', _this._entity);
     return _this;
   }
 
   _createClass(Map, [{
     key: 'componentWillMount',
     value: function componentWillMount() {
-      debug(__com__, 'componentWillMount', this.refElement, this._entity);
+      debug(__com__, 'componentWillMount', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
     }
   }, {
     key: 'componentDidMount',
     value: function componentDidMount() {
-      debug(__com__, 'componentDidMount', this.refElement, this._entity);
+      debug(__com__, 'componentDidMount', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
       var _props = this.props,
-          AMap = _props.AMap,
           options = _props.options,
           events = _props.events;
 
-      this._entity = createMap(AMap, this.refElement, options, events);
+      this._entity = createMap(this.refElement, options, events);
       if (this._entity) {
         if (this.props.refer) this.props.refer(this._entity);
         this.setState({ __map__: this._entity });
@@ -55,24 +52,23 @@ export var Map = function (_Component) {
   }, {
     key: 'componentWillReceiveProps',
     value: function componentWillReceiveProps(nextProps) {
-      debug(__com__, 'componentWillReceiveProps', this.refElement, this._entity);
+      debug(__com__, 'componentWillReceiveProps', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
     }
   }, {
     key: 'componentWillUpdate',
     value: function componentWillUpdate() {
-      debug(__com__, 'componentWillUpdate', this.refElement, this._entity);
+      debug(__com__, 'componentWillUpdate', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
     }
   }, {
     key: 'componentDidUpdate',
     value: function componentDidUpdate(prevProps) {
-      debug(__com__, 'componentDidUpdate', this.refElement, this._entity);
+      debug(__com__, 'componentDidUpdate', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
       var _props2 = this.props,
-          AMap = _props2.AMap,
           options = _props2.options,
           events = _props2.events;
 
       if (!this._entity) {
-        this._entity = createMap(AMap, this.refElement, options, events);
+        this._entity = createMap(this.refElement, options, events);
         if (this._entity) {
           if (this.props.refer) this.props.refer(this._entity);
           this.setState({ __map__: this._entity });
@@ -86,15 +82,13 @@ export var Map = function (_Component) {
   }, {
     key: 'componentWillUnmount',
     value: function componentWillUnmount() {
-      debug(__com__, 'componentWillUnmount', this.refElement, this._entity);
+      debug(__com__, 'componentWillUnmount', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
       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);
+        if (this.props.refer) this.props.refer(this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
       }
     }
   }, {
@@ -121,7 +115,7 @@ export var Map = function (_Component) {
       });
     }
     // shouldComponentUpdate(nextProps, nextState) {
-    //   debug(__com__, 'shouldComponentUpdate', this.refElement, this._entity);
+    //   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) {
@@ -137,19 +131,15 @@ export var Map = function (_Component) {
     value: function render() {
       var _this2 = this;
 
-      debug(__com__, 'component render', this._entity);
-
+      debug(__com__, 'render', this._entity, 'layerCount:' + (this._entity && this._entity.getLayers().length));
       var _props3 = this.props,
-          AMap = _props3.AMap,
-          refer = _props3.refer,
-          options = _props3.options,
-          events = _props3.events,
-          match = _props3.match,
-          location = _props3.location,
-          history = _props3.history,
-          children = _props3.children,
-          staticContext = _props3.staticContext,
-          rest = _objectWithoutProperties(_props3, ['AMap', 'refer', 'options', 'events', 'match', 'location', 'history', 'children', 'staticContext']);
+          className = _props3.className,
+          style = _props3.style,
+          children = _props3.children;
+
+      var restProps = {};
+      if (className) restProps = _extends({}, restProps, { className: className });
+      if (style) restProps = _extends({}, restProps, { style: style });
 
       return React.createElement(
         'div',
@@ -157,7 +147,7 @@ export var Map = function (_Component) {
           ref: function ref(ele) {
             _this2.refElement = ele;
           }
-        }, rest),
+        }, restProps),
         this.renderChildren(children, this._entity)
       );
     }
@@ -167,7 +157,6 @@ export var Map = function (_Component) {
 }(Component);
 
 Map.propTypes = {
-  AMap: PropTypes.object,
   refer: PropTypes.func, // 类似ref的函数形式,可以让父组件调用_entity
   options: PropTypes.object,
   events: PropTypes.object

+ 3 - 25
lib/Marker.js

@@ -2,8 +2,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
 
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
-function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
-
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -41,7 +39,6 @@ export var Marker = function (_Component) {
     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,
@@ -49,7 +46,7 @@ export var Marker = function (_Component) {
       //let opts = { ...(options || {}), map: __map__, content: children };
 
       var opts = _extends({}, options || {}, { map: __map__ });
-      this._entity = createMarker(AMap, opts, events);
+      this._entity = createMarker(opts, events);
       if (this._entity) {
         if (this.props.refer) this.props.refer(this._entity);
       }
@@ -69,7 +66,6 @@ export var Marker = function (_Component) {
     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,
@@ -78,7 +74,7 @@ export var Marker = function (_Component) {
 
       var opts = _extends({}, options || {}, { map: __map__ });
       if (!this._entity) {
-        this._entity = createMarker(AMap, opts, events);
+        this._entity = createMarker(opts, events);
         if (this._entity) {
           if (this.props.refer) this.props.refer(this._entity);
         }
@@ -100,8 +96,6 @@ export var Marker = function (_Component) {
         //   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);
       }
@@ -122,23 +116,8 @@ export var Marker = function (_Component) {
   }, {
     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 = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
-
+      debug(__com__, 'render', this._entity);
       return null;
-      // return (
-      //   <React.Fragment>
-      //   </React.Fragment>
-      // )
     }
   }]);
 
@@ -146,7 +125,6 @@ export var Marker = function (_Component) {
 }(Component);
 
 Marker.propTypes = {
-  AMap: PropTypes.object,
   __map__: PropTypes.object,
   options: PropTypes.object,
   events: PropTypes.object

+ 19 - 35
lib/MassMarks.js

@@ -2,8 +2,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
 
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
-function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
-
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -34,14 +32,13 @@ export var MassMarks = function (_Component) {
   _createClass(MassMarks, [{
     key: 'componentWillMount',
     value: function componentWillMount() {
-      debug(__com__, 'componentWillMount', this.props.children, this._entity);
+      debug(__com__, 'componentWillMount', this.props, this._entity);
     }
   }, {
     key: 'componentDidMount',
     value: function componentDidMount() {
-      debug(__com__, 'componentDidMount', this.props.children, this._entity);
+      debug(__com__, 'componentDidMount', this.props, this._entity);
       var _props = this.props,
-          AMap = _props.AMap,
           __map__ = _props.__map__,
           options = _props.options,
           events = _props.events,
@@ -49,33 +46,37 @@ export var MassMarks = function (_Component) {
       //let opts = { ...(options || {}), map: __map__, content: children };
 
       var opts = _extends({}, options || {}, { map: __map__ });
-      this._entity = createMassMarks(AMap, opts, events);
+      this._entity = createMassMarks(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);
+      debug(__com__, 'componentWillReceiveProps', this.props, this._entity);
     }
   }, {
     key: 'componentWillUpdate',
     value: function componentWillUpdate() {
-      debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
+      debug(__com__, 'componentWillUpdate', this.props, this._entity);
     }
   }, {
     key: 'componentDidUpdate',
     value: function componentDidUpdate(prevProps) {
-      debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
+      debug(__com__, 'componentDidUpdate', this.props, 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 };
+          events = _props2.events;
 
       var opts = _extends({}, options || {}, { map: __map__ });
       if (!this._entity) {
-        this._entity = createMassMarks(AMap, opts, events);
+        debug(__com__, 'componentDidUpdate', opts, events);
+        this._entity = createMassMarks(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
         return;
       }
 
@@ -88,13 +89,12 @@ export var MassMarks = function (_Component) {
   }, {
     key: 'componentWillUnmount',
     value: function componentWillUnmount() {
-      debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
+      debug(__com__, 'componentWillUnmount', this.props, this._entity);
       if (this._entity) {
-        //   this._entity.clearMap();
         this._entity.setMap(null);
-        delete this._entity;
-        //   delete this._entity;
+        // delete this._entity;
         this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
       }
     }
 
@@ -106,23 +106,8 @@ export var MassMarks = function (_Component) {
   }, {
     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 = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
-
+      debug(__com__, 'render', this._entity);
       return null;
-      // return (
-      //   <React.Fragment>
-      //   </React.Fragment>
-      // )
     }
   }]);
 
@@ -130,7 +115,6 @@ export var MassMarks = function (_Component) {
 }(Component);
 
 MassMarks.propTypes = {
-  AMap: PropTypes.object,
   __map__: PropTypes.object,
   options: PropTypes.object,
   events: PropTypes.object

+ 10 - 25
lib/Polygon.js

@@ -2,8 +2,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
 
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
-function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
-
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -36,7 +34,6 @@ export var Polygon = function (_Component) {
     value: function componentDidMount() {
       debug(__com__, 'componentDidMount', this._entity);
       var _props = this.props,
-          AMap = _props.AMap,
           __map__ = _props.__map__,
           options = _props.options,
           events = _props.events,
@@ -44,14 +41,16 @@ export var Polygon = function (_Component) {
       //let opts = { ...(options || {}), map: __map__, content: children };
 
       var opts = _extends({}, options || {}, { map: __map__ });
-      this._entity = createPolygon(AMap, opts, events);
+      this._entity = createPolygon(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(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,
@@ -60,7 +59,10 @@ export var Polygon = function (_Component) {
 
       var opts = _extends({}, options || {}, { map: __map__ });
       if (!this._entity) {
-        this._entity = createPolygon(AMap, opts, events);
+        this._entity = createPolygon(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
         return;
       }
 
@@ -75,11 +77,10 @@ export var Polygon = function (_Component) {
     value: function componentWillUnmount() {
       debug(__com__, 'componentWillUnmount', this._entity);
       if (this._entity) {
-        //   this._entity.clearMap();
         this._entity.setMap(null);
-        delete this._entity;
-        //   delete this._entity;
+        // delete this._entity;
         this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
       }
     }
 
@@ -92,22 +93,7 @@ export var Polygon = function (_Component) {
     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 = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
-
       return null;
-      // return (
-      //   <React.Fragment>
-      //   </React.Fragment>
-      // )
     }
   }]);
 
@@ -115,7 +101,6 @@ export var Polygon = function (_Component) {
 }(Component);
 
 Polygon.propTypes = {
-  AMap: PropTypes.object,
   __map__: PropTypes.object,
   options: PropTypes.object,
   events: PropTypes.object

+ 11 - 26
lib/Polyline.js

@@ -2,8 +2,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
 
 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
-function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
-
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -36,7 +34,6 @@ export var Polyline = function (_Component) {
     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,
@@ -44,14 +41,16 @@ export var Polyline = function (_Component) {
       //let opts = { ...(options || {}), map: __map__, content: children };
 
       var opts = _extends({}, options || {}, { map: __map__ });
-      this._entity = createPolyline(AMap, opts, events);
+      this._entity = createPolyline(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(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,
@@ -60,7 +59,10 @@ export var Polyline = function (_Component) {
 
       var opts = _extends({}, options || {}, { map: __map__ });
       if (!this._entity) {
-        this._entity = createPolyline(AMap, opts, events);
+        this._entity = createPolyline(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
         return;
       }
 
@@ -75,11 +77,10 @@ export var Polyline = function (_Component) {
     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;
+        // delete this._entity;
         this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
       }
     }
 
@@ -91,23 +92,8 @@ export var Polyline = function (_Component) {
   }, {
     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 = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
-
+      debug(__com__, 'render', this._entity);
       return null;
-      // return (
-      //   <React.Fragment>
-      //   </React.Fragment>
-      // )
     }
   }]);
 
@@ -115,7 +101,6 @@ export var Polyline = function (_Component) {
 }(Component);
 
 Polyline.propTypes = {
-  AMap: PropTypes.object,
   __map__: PropTypes.object,
   options: PropTypes.object,
   events: PropTypes.object

+ 118 - 80
lib/api.js

@@ -9,6 +9,9 @@ import isEmpty from 'lodash/isEmpty';
 //import loadjscssfile from './loadScript';
 import APILoader from './APILoader';
 
+//const xdebug = console.log;
+var xdebug = function xdebug() {};
+
 export var loadApi = function loadApi() {
   var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0325e3d6d69cd56de4980b4f28906fd8';
 
@@ -65,9 +68,9 @@ export var loadMap = function loadMap(key) {
 /**
  * [加载插件](https://lbs.amap.com/api/javascript-api/guide/abc/plugins)
  * 加载完成后,可以调用:
- *  var toolbar = new AMap.ToolBar();
+ *  var toolbar = new window.AMap.ToolBar();
  *  map.addControl(toolbar);
- * @param {string} name 插件名或插件数组,如:AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
+ * @param {string} name 插件名或插件数组,如:window.AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
  */
 export var loadPlugin = function loadPlugin(name) {
   return new Promise(function (resolve, reject) {
@@ -83,33 +86,14 @@ export var loadPlugin = function loadPlugin(name) {
 };
 
 ////////////////////////////////////////////////////////////
-// 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, _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 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!');
+    xdebug(__func__, 'fail! no entity!');
     return false;
   }
 
@@ -181,11 +165,11 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
         func(value);
       } else {
         // ignore properties can not set.
-        console.log(__func__, 'warning! no setter! can not update ' + key);
+        xdebug(__func__, 'warning! no setter! can not update ' + key);
       }
     } else {
       // key removed, not support!
-      console.log(__func__, 'warning! remove prop not support! key=' + key);
+      xdebug(__func__, 'warning! remove prop not support! key=' + key);
     }
   });
   forOwn(events, function (value, key) {
@@ -198,7 +182,7 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
     }
   });
   if (!isEmpty(props) || !isEmpty(events)) {
-    console.log(__func__, 'update:', props, events
+    xdebug(__func__, 'update:', props, events
     // newOptions,
     // newEvents,
     // oldOptions,
@@ -208,6 +192,28 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
   return true;
 };
 
+////////////////////////////////////////////////////////////
+// Map
+////////////////////////////////////////////////////////////
+export var createMap = function createMap(dom, options, events) {
+  var __func__ = 'createMap';
+  if (!window.AMap) {
+    xdebug(__func__, 'fail! no window.AMap!');
+    return null;
+  }
+  if (!dom) {
+    xdebug(__func__, 'fail! no dom!');
+    return null;
+  }
+  var map = new window.AMap.Map(dom, _extends({}, options || {}));
+  forOwn(events, function (value, key) {
+    xdebug(__func__, 'event on ' + key);
+    map.on(key, value);
+  });
+  xdebug(__func__, 'ok!');
+  return map;
+};
+
 export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
   var operators = {
     view: null,
@@ -286,18 +292,18 @@ export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export var createMarker = function createMarker(AMap, options, events) {
+export var createMarker = function createMarker(options, events) {
   var __func__ = 'createMarker';
-  if (!AMap) {
-    console.log(__func__, 'fail! no AMap!');
+  if (!window.AMap) {
+    xdebug(__func__, 'fail! no window.AMap!');
     return null;
   }
   if (!options) {
-    console.log(__func__, 'fail! no options!');
+    xdebug(__func__, 'fail! no options!');
     return null;
   }
   if (!options.map) {
-    console.log(__func__, 'fail! no options.map!');
+    xdebug(__func__, 'fail! no options.map!');
     return null;
   }
   // let marker = new AMap.Marker({
@@ -305,11 +311,11 @@ export var createMarker = function createMarker(AMap, options, events) {
   //   position: [116.405467, 39.907761]
   // });
   // marker.setMap(map);
-  var entity = new AMap.Marker(options);
+  var entity = new window.AMap.Marker(options);
   forOwn(events, function (value, key) {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -374,7 +380,7 @@ export var updateMarker = function updateMarker(entity, newOptions, newEvents, o
 };
 
 ////////////////////////////////////////////////////////////
-// MassMarks, warning! is a layer!
+// Traffic layer, warning! is a layer!
 ////////////////////////////////////////////////////////////
 /**
  *
@@ -383,14 +389,10 @@ export var updateMarker = function updateMarker(entity, newOptions, newEvents, o
  * @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!');
+var createTraffic = function createTraffic(options, events) {
+  var __func__ = 'createTraffic';
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
     return null;
   }
 
@@ -398,14 +400,64 @@ var createMassMarks = function createMassMarks(AMap, options, events) {
       data = options.data,
       restOpts = _objectWithoutProperties(options, ['map', 'data']);
 
-  var entity = new AMap.MassMarks(data, restOpts);
+  var entity = new window.AMap.TileLayer.Traffic(data, restOpts);
   forOwn(events, function (value, key) {
     entity.on(key, value);
   });
-  if (map) {
-    entity.setMap(map);
+  entity.setMap(map);
+  xdebug(__func__, 'ok!');
+  return entity;
+};
+
+export { createTraffic };
+export var updateTraffic = function updateTraffic(entity, newOptions, newEvents, oldOptions, oldEvents) {
+  var operators = {
+    map: function map(v) {
+      return entity.setMap(v);
+    },
+    zIndex: function zIndex(v) {
+      return entity.setzIndex(v);
+    },
+    opacity: function opacity(v) {
+      return entity.setOpacity(v);
+    },
+    zooms: null,
+    detectRetina: null,
+    autoRefresh: null,
+    interval: null
+  };
+
+  return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateTraffic');
+};
+
+////////////////////////////////////////////////////////////
+// MassMarks, warning! is a layer!
+////////////////////////////////////////////////////////////
+/**
+ *
+ * @param {*} AMap
+ * @param {*} map
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
+ * @param {*} events
+ */
+var createMassMarks = function createMassMarks(options, events) {
+  var __func__ = 'createMassMarks';
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
+    return null;
   }
-  console.log(__func__, 'ok!');
+
+  var map = options.map,
+      data = options.data,
+      style = options.style,
+      restOpts = _objectWithoutProperties(options, ['map', 'data', 'style']);
+
+  var entity = new window.AMap.MassMarks(data || [], _extends({}, restOpts, { style: style || [] }));
+  forOwn(events, function (value, key) {
+    entity.on(key, value);
+  });
+  entity.setMap(map);
+  xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
   return entity;
 };
 
@@ -425,12 +477,14 @@ export var updateMassMarks = function updateMassMarks(entity, newOptions, newEve
       return entity.setStyle(v);
     },
     map: function map(v) {
-      return entity.setMap(v);
+      xdebug('updateMassMarks', 'setMap', v, 'layers:', v && v.getLayers());
+      entity.setMap(v);
     },
     data: function data(v) {
-      return entity.setData(v);
+      entity.setData(v);
     }
   };
+  xdebug('updateMassMarks', 'mapOld:', oldOptions && oldOptions.map && oldOptions.map.getLayers(), 'mapNew:', newOptions && newOptions.map && newOptions.map.getLayers());
 
   return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMassMarks');
 };
@@ -445,25 +499,17 @@ export var updateMassMarks = function updateMassMarks(entity, newOptions, newEve
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export var createPolygon = function createPolygon(AMap, options, events) {
+export var createPolygon = function createPolygon(options, events) {
   var __func__ = 'createPolygon';
-  if (!AMap) {
-    console.log(__func__, 'fail! no AMap!');
-    return null;
-  }
-  if (!options) {
-    console.log(__func__, 'fail! no options!');
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
     return null;
   }
-  if (!options.map) {
-    console.log(__func__, 'fail! no options.map!');
-    return null;
-  }
-  var entity = new AMap.Polygon(options);
+  var entity = new window.AMap.Polygon(options);
   forOwn(events, function (value, key) {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -509,25 +555,17 @@ export var updatePolygon = function updatePolygon(entity, newOptions, newEvents,
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export var createPolyline = function createPolyline(AMap, options, events) {
+export var createPolyline = function createPolyline(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!');
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
     return null;
   }
-  var entity = new AMap.Polyline(options);
+  var entity = new window.AMap.Polyline(options);
   forOwn(events, function (value, key) {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -578,17 +616,17 @@ export var updatePolyline = function updatePolyline(entity, newOptions, newEvent
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export var createInfoWindow = function createInfoWindow(AMap, options, events) {
+export var createInfoWindow = function createInfoWindow(options, events) {
   var __func__ = 'createInfoWindow';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:' + !!AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
     return null;
   }
-  var entity = new AMap.InfoWindow(options);
+  var entity = new window.AMap.InfoWindow(options);
   forOwn(events, function (value, key) {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "react-amap-next",
-  "version": "1.1.5",
+  "version": "1.1.6",
   "description": "这是高德地图的react版本,相比react-amap更加简单,更加贴合react用户",
   "keywords": [
     "react",

+ 60 - 34
src/App.js

@@ -105,7 +105,6 @@ class MarkerTest extends Component {
           {'消息:'+this.state.msg}
         </div>
         <Map
-          AMap={this.state.AMap}
           style={{ width: 1200, height: 800 }}
           options={{ center: this.state.center, layers: this.state.layers, zoom:13 }}
           events={{
@@ -115,7 +114,6 @@ class MarkerTest extends Component {
       >
           {this.state.showMarker &&
           <Marker
-            AMap={this.state.AMap}
             options={{
               icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
               position: this.state.position || [116.405467, 39.907761]
@@ -128,7 +126,6 @@ class MarkerTest extends Component {
           }
           {this.state.showMarker &&
           <Marker
-            AMap={this.state.AMap}
             options={{
               icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
               position: [116.385428, 39.92723],
@@ -144,7 +141,6 @@ class MarkerTest extends Component {
           />
           }
           <Marker
-            AMap={this.state.AMap}
             refer={(entity) => this.setState({carEntity: entity})}
             options={{
               position: [116.397428, 39.90923],
@@ -157,7 +153,6 @@ class MarkerTest extends Component {
             }}
           />
           <Polyline
-            AMap={this.state.AMap}
             options={{
               path: this.state.lineArr,
               strokeColor: "#00A",  //线颜色
@@ -170,7 +165,6 @@ class MarkerTest extends Component {
             }}
           />
           <Polyline
-            AMap={this.state.AMap}
             options={{
               // path: lineArr,
               path:this.state.passedPath,
@@ -197,32 +191,29 @@ class MassMarkTest extends Component {
     super();
     this.state = {};
     this._mapDblclick = this._mapDblclick.bind(this);
+    this._mapClick = this._mapClick.bind(this);
     this._changeStyle = this._changeStyle.bind(this);
+    this._setMapRefer = this._setMapRefer.bind(this);
+    this._setMassRefer = this._setMassRefer.bind(this);
   }
 
   componentDidMount() {
     loadMap('0325e3d6d69cd56de4980b4f28906fd8').then(AMap => {
-      let roadNet = new AMap.TileLayer.RoadNet();
-      let traffic = new AMap.TileLayer.Traffic({
-        autoRefresh: true, //是否自动刷新,默认为false
-        interval: 15 //刷新间隔,默认180s
-      });
-      let style = [{
-        url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png',
-        anchor: new AMap.Pixel(16, 16),
-        size: new AMap.Size(21, 21)
-      },{
-        url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png',
-        anchor: new AMap.Pixel(24, 24),
-        size: new AMap.Size(17, 17)
-      },{
-        url: 'https://a.amap.com/jsapi_demos/static/images/mass2.png',
-        anchor: new AMap.Pixel(23, 23),
-        size: new AMap.Size(5, 5)
-      }
-    ];
+      // let style = [{
+      //   url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png',
+      //   anchor: new AMap.Pixel(16, 16),
+      //   size: new AMap.Size(21, 21)
+      // },{
+      //   url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png',
+      //   anchor: new AMap.Pixel(24, 24),
+      //   size: new AMap.Size(17, 17)
+      // },{
+      //   url: 'https://a.amap.com/jsapi_demos/static/images/mass2.png',
+      //   anchor: new AMap.Pixel(23, 23),
+      //   size: new AMap.Size(5, 5)
+      // }];
 
-      this.setState({ AMap, layers: [roadNet, traffic], style });
+      this.setState({ AMap });
     });
     loadJs('https://a.amap.com/jsapi_demos/static/citys.js','js').then(ret => {
       console.log('ret:', ret, window.citys);
@@ -234,9 +225,40 @@ class MassMarkTest extends Component {
     })
   }
 
+  _getStyle() {
+    if (!this.styles) {
+      if (window.AMap) {
+        this.styles = [{
+          url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png',
+          anchor: new window.AMap.Pixel(16, 16),
+          size: new window.AMap.Size(21, 21)
+        },{
+          url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png',
+          anchor: new window.AMap.Pixel(24, 24),
+          size: new window.AMap.Size(17, 17)
+        },{
+          url: 'https://a.amap.com/jsapi_demos/static/images/mass2.png',
+          anchor: new window.AMap.Pixel(23, 23),
+          size: new window.AMap.Size(5, 5)
+        }];
+      }
+    }
+    return this.styles;
+  }
+
   _mapDblclick() {
+    if (this.massRefer) {
+      this.massRefer.show();
+      this.massRefer.setData(this.state.citys);
+    }
     this.setState({msg:'双击了Map!'});
   }
+  _mapClick() {
+    if (this.mapRefer) {
+      let layers= this.mapRefer.getLayers();
+      console.log('_mapClick:', layers);
+    }
+  }
   _changeStyle(item) {
     let style = (item.style+1) % 3;
     let data = this.state.citys
@@ -244,8 +266,15 @@ class MassMarkTest extends Component {
     data2[item.id] = {...item, style};
     this.setState({citys:data2});
   }
+  _setMapRefer (refer) {
+    this.mapRefer = refer;
+  }
+  _setMassRefer (refer) {
+    this.massRefer = refer;
+  }
 
   render() {
+    let massStyles = this._getStyle();
     return (
       <div>
       <div>
@@ -263,22 +292,23 @@ class MassMarkTest extends Component {
           {'消息:'+this.state.msg}
         </div>
         <Map
-          AMap={this.state.AMap}
+          refer={this._setMapRefer}
           style={{ width: 1100, height: 800 }}
-          options={{ center: this.state.center, layers: this.state.layers }}
+          options={{ center: this.state.center }}
           events={{
             // click:e=>this.setState({msg: '点击了Map'}),
             dblclick: this._mapDblclick,
+            click:this._mapClick
           }}
       >
           <MassMarks
-            AMap={this.state.AMap}
+            refer={this._setMassRefer}
             options={{
               data: this.state.citys,
               opacity:0.8,
               zIndex: 111,
               cursor:'pointer',
-              style: this.state.style
+              style: massStyles
             }}
             events={{
               click:e=> {
@@ -351,7 +381,6 @@ class PolygonTest extends Component {
           {'消息:'+this.state.msg}
         </div>
         <Map
-          AMap={this.state.AMap}
           style={{ width: 1100, height: 800 }}
           options={{ center: this.state.center, layers: this.state.layers }}
           events={{
@@ -360,7 +389,6 @@ class PolygonTest extends Component {
           }}
       >
           <Polygon
-            AMap={this.state.AMap}
             options={{
               path: poly,
               strokeColor: "#FF33FF", //线颜色
@@ -423,13 +451,11 @@ class InfoWindowTest extends Component {
           <input type='button' onClick={() => this.setState({ center: this.state.center2 })} value='center2' />
         </div>
         <Map
-          AMap={this.state.AMap}
           style={{ width: 1100, height: 800 }}
           options={{ center: this.state.center, layers: this.state.layers }}
       >
       {this.state.isOpen && (
           <InfoWindow
-            AMap={this.state.AMap}
             options={{
               position: this.state.center,
               isCustom:false,

+ 12 - 21
src/lib/InfoWindow.js

@@ -8,7 +8,6 @@ const debug = () => {};
 // https://lbs.amap.com/api/javascript-api/reference/infowindow
 export class InfoWindow extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     __map__: PropTypes.object,
     options: PropTypes.object,
     events: PropTypes.object
@@ -23,19 +22,25 @@ export class InfoWindow extends Component {
 
   componentDidMount() {
     debug(__com__, 'componentDidMount', this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
-    this._entity = createInfoWindow(AMap, opts, events);
+    this._entity = createInfoWindow(opts, events);
+    if (this._entity) {
+      if (this.props.refer) this.props.refer(this._entity);
+    }
   }
 
   componentDidUpdate(prevProps) {
     debug(__com__, 'componentDidUpdate', this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
     if (!this._entity) {
-      this._entity = createInfoWindow(AMap, opts, events);
+      this._entity = createInfoWindow(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
       return;
     }
 
@@ -52,9 +57,9 @@ export class InfoWindow extends Component {
     if (this._entity) {
       //   this._entity.clearMap();
       this._entity.setMap(null);
-      delete this._entity;
-      //   delete this._entity;
+      // delete this._entity;
       this._entity = null;
+      if (this.props.refer) this.props.refer(this._entity);
     }
   }
 
@@ -64,21 +69,7 @@ export class InfoWindow extends Component {
   // }
   render() {
     debug(__com__, 'render', this._entity);
-    let {
-      AMap,
-      options,
-      events,
-      match,
-      location,
-      history,
-      staticContext,
-      ...rest
-    } = this.props;
     return null;
-    // return (
-    //   <React.Fragment>
-    //   </React.Fragment>
-    // )
   }
 }
 

+ 21 - 30
src/lib/Map.js

@@ -1,6 +1,6 @@
 import React, { Component, PureComponent } from 'react';
 import PropTypes from 'prop-types';
-import { loadMap, createMap, updateMap } from './api';
+import { createMap, updateMap } from './api';
 
 const __com__ = 'Map';
 //const debug = console.log;
@@ -8,7 +8,6 @@ const debug = () => {};
 
 export class Map extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     refer: PropTypes.func, // 类似ref的函数形式,可以让父组件调用_entity
     options: PropTypes.object,
     events: PropTypes.object
@@ -24,17 +23,17 @@ export class Map extends Component {
     super();
     this.refElement = null;
     this._entity = null;
-    debug(__com__, 'component constructor', this.refElement, this._entity);
+    debug(__com__, 'component constructor', this._entity);
   }
 
   componentWillMount() {
-    debug(__com__, 'componentWillMount', this.refElement, this._entity);
+    debug(__com__, 'componentWillMount', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
   }
 
   componentDidMount() {
-    debug(__com__, 'componentDidMount', this.refElement, this._entity);
-    let { AMap, options, events } = this.props;
-    this._entity = createMap(AMap, this.refElement, options, events);
+    debug(__com__, 'componentDidMount', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
+    let { options, events } = this.props;
+    this._entity = createMap(this.refElement, options, events);
     if (this._entity) {
       if (this.props.refer) this.props.refer(this._entity);
       this.setState({ __map__: this._entity });
@@ -42,18 +41,18 @@ export class Map extends Component {
   }
 
   componentWillReceiveProps(nextProps) {
-    debug(__com__, 'componentWillReceiveProps', this.refElement, this._entity);
+    debug(__com__, 'componentWillReceiveProps', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
   }
 
   componentWillUpdate() {
-    debug(__com__, 'componentWillUpdate', this.refElement, this._entity);
+    debug(__com__, 'componentWillUpdate', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
   }
 
   componentDidUpdate(prevProps) {
-    debug(__com__, 'componentDidUpdate', this.refElement, this._entity);
-    let { AMap, options, events } = this.props;
+    debug(__com__, 'componentDidUpdate', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
+    let { options, events } = this.props;
     if (!this._entity) {
-      this._entity = createMap(AMap, this.refElement, options, events);
+      this._entity = createMap(this.refElement, options, events);
       if (this._entity) {
         if (this.props.refer) this.props.refer(this._entity);
         this.setState({ __map__: this._entity });
@@ -72,14 +71,13 @@ export class Map extends Component {
   }
 
   componentWillUnmount() {
-    debug(__com__, 'componentWillUnmount', this.refElement, this._entity);
+    debug(__com__, 'componentWillUnmount', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
     if (this._entity) {
-      let { refer } = this.props;
       //   this._entity.clearMap();
       this._entity.destroy();
       //   delete this._entity;
       this._entity = null;
-      if (this.props.refer) this.props.refer(this._entity);
+      if (this.props.refer) this.props.refer(this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
     }
   }
 
@@ -105,7 +103,7 @@ export class Map extends Component {
     });
   }
   // shouldComponentUpdate(nextProps, nextState) {
-  //   debug(__com__, 'shouldComponentUpdate', this.refElement, this._entity);
+  //   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) {
@@ -116,25 +114,18 @@ export class Map extends Component {
   //   return true;
   // }
   render() {
-    debug(__com__, 'component render', this._entity);
-    let {
-      AMap,
-      refer,
-      options,
-      events,
-      match,
-      location,
-      history,
-      children,
-      staticContext,
-      ...rest
-    } = this.props;
+    debug(__com__, 'render', this._entity, 'layerCount:'+(this._entity && this._entity.getLayers().length));
+    let { className, style, children } = this.props;
+    let restProps = {};
+    if (className) restProps = { ...restProps, className };
+    if (style) restProps = { ...restProps, style };
+
     return (
       <div
         ref={ele => {
           this.refElement = ele;
         }}
-        {...rest}
+        {...restProps}
       >
         {this.renderChildren(children, this._entity)}
       </div>

+ 5 - 22
src/lib/Marker.js

@@ -7,7 +7,6 @@ const debug = () => {};
 
 export class Marker extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     __map__: PropTypes.object,
     options: PropTypes.object,
     events: PropTypes.object
@@ -33,10 +32,10 @@ export class Marker extends Component {
 
   componentDidMount() {
     debug(__com__, 'componentDidMount', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
-    this._entity = createMarker(AMap, opts, events);
+    this._entity = createMarker(opts, events);
     if (this._entity) {
       if (this.props.refer) this.props.refer(this._entity);
     }
@@ -52,11 +51,11 @@ export class Marker extends Component {
 
   componentDidUpdate(prevProps) {
     debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
     if (!this._entity) {
-      this._entity = createMarker(AMap, opts, events);
+      this._entity = createMarker(opts, events);
       if (this._entity) {
         if (this.props.refer) this.props.refer(this._entity);
       }
@@ -78,8 +77,6 @@ export class Marker extends Component {
       //   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);
     }
@@ -97,22 +94,8 @@ export class Marker extends Component {
   //   return true;
   // }
   render() {
-    debug(__com__, 'render', this.props.children, this._entity);
-    let {
-      AMap,
-      options,
-      events,
-      match,
-      location,
-      history,
-      staticContext,
-      ...rest
-    } = this.props;
+    debug(__com__, 'render', this._entity);
     return null;
-    // return (
-    //   <React.Fragment>
-    //   </React.Fragment>
-    // )
   }
 }
 

+ 20 - 30
src/lib/MassMarks.js

@@ -7,7 +7,6 @@ const debug = () => {};
 
 export class MassMarks extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     __map__: PropTypes.object,
     options: PropTypes.object,
     events: PropTypes.object
@@ -21,32 +20,38 @@ export class MassMarks extends Component {
   }
 
   componentWillMount() {
-    debug(__com__, 'componentWillMount', this.props.children, this._entity);
+    debug(__com__, 'componentWillMount', this.props, this._entity);
   }
 
   componentDidMount() {
-    debug(__com__, 'componentDidMount', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    debug(__com__, 'componentDidMount', this.props, this._entity);
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
-    this._entity = createMassMarks(AMap, opts, events);
+    this._entity = createMassMarks(opts, events);
+    if (this._entity) {
+      if (this.props.refer) this.props.refer(this._entity);
+    }
   }
 
   componentWillReceiveProps(nextProps) {
-    debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
+    debug(__com__, 'componentWillReceiveProps', this.props, this._entity);
   }
 
   componentWillUpdate() {
-    debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
+    debug(__com__, 'componentWillUpdate', this.props, this._entity);
   }
 
   componentDidUpdate(prevProps) {
-    debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
-    //let opts = { ...(options || {}), map: __map__, content: children };
+    debug(__com__, 'componentDidUpdate', this.props, this._entity);
+    let { __map__, options, events } = this.props;
     let opts = { ...(options || {}), map: __map__ };
     if (!this._entity) {
-      this._entity = createMassMarks(AMap, opts, events);
+      debug(__com__, 'componentDidUpdate', opts, events);
+      this._entity = createMassMarks(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
       return;
     }
 
@@ -59,13 +64,12 @@ export class MassMarks extends Component {
   }
 
   componentWillUnmount() {
-    debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
+    debug(__com__, 'componentWillUnmount', this.props, this._entity);
     if (this._entity) {
-      //   this._entity.clearMap();
       this._entity.setMap(null);
-      delete this._entity;
-      //   delete this._entity;
+      // delete this._entity;
       this._entity = null;
+      if (this.props.refer) this.props.refer(this._entity);
     }
   }
 
@@ -74,22 +78,8 @@ export class MassMarks extends Component {
   //   return false;
   // }
   render() {
-    debug(__com__, 'render', this.props.children, this._entity);
-    let {
-      AMap,
-      options,
-      events,
-      match,
-      location,
-      history,
-      staticContext,
-      ...rest
-    } = this.props;
+    debug(__com__, 'render', this._entity);
     return null;
-    // return (
-    //   <React.Fragment>
-    //   </React.Fragment>
-    // )
   }
 }
 

+ 13 - 23
src/lib/Polygon.js

@@ -7,7 +7,6 @@ const debug = () => {};
 
 export class Polygon extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     __map__: PropTypes.object,
     options: PropTypes.object,
     events: PropTypes.object
@@ -22,19 +21,25 @@ export class Polygon extends Component {
 
   componentDidMount() {
     debug(__com__, 'componentDidMount', this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
-    this._entity = createPolygon(AMap, opts, events);
-  }
+    this._entity = createPolygon(opts, events);
+    if (this._entity) {
+      if (this.props.refer) this.props.refer(this._entity);
+    }
+}
 
   componentDidUpdate(prevProps) {
     debug(__com__, 'componentDidUpdate', this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
     if (!this._entity) {
-      this._entity = createPolygon(AMap, opts, events);
+      this._entity = createPolygon(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
       return;
     }
 
@@ -49,11 +54,10 @@ export class Polygon extends Component {
   componentWillUnmount() {
     debug(__com__, 'componentWillUnmount', this._entity);
     if (this._entity) {
-      //   this._entity.clearMap();
       this._entity.setMap(null);
-      delete this._entity;
-      //   delete this._entity;
+      // delete this._entity;
       this._entity = null;
+      if (this.props.refer) this.props.refer(this._entity);
     }
   }
 
@@ -63,21 +67,7 @@ export class Polygon extends Component {
   // }
   render() {
     debug(__com__, 'render', this._entity);
-    let {
-      AMap,
-      options,
-      events,
-      match,
-      location,
-      history,
-      staticContext,
-      ...rest
-    } = this.props;
     return null;
-    // return (
-    //   <React.Fragment>
-    //   </React.Fragment>
-    // )
   }
 }
 

+ 13 - 23
src/lib/Polyline.js

@@ -7,7 +7,6 @@ const debug = () => {};
 
 export class Polyline extends Component {
   static propTypes = {
-    AMap: PropTypes.object,
     __map__: PropTypes.object,
     options: PropTypes.object,
     events: PropTypes.object
@@ -22,19 +21,25 @@ export class Polyline extends Component {
 
   componentDidMount() {
     debug(__com__, 'componentDidMount', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
-    this._entity = createPolyline(AMap, opts, events);
+    this._entity = createPolyline(opts, events);
+    if (this._entity) {
+      if (this.props.refer) this.props.refer(this._entity);
+    }
   }
 
   componentDidUpdate(prevProps) {
     debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
-    let { AMap, __map__, options, events, children } = this.props;
+    let { __map__, options, events, children } = this.props;
     //let opts = { ...(options || {}), map: __map__, content: children };
     let opts = { ...(options || {}), map: __map__ };
     if (!this._entity) {
-      this._entity = createPolyline(AMap, opts, events);
+      this._entity = createPolyline(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
       return;
     }
 
@@ -49,11 +54,10 @@ export class Polyline extends Component {
   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;
+      // delete this._entity;
       this._entity = null;
+      if (this.props.refer) this.props.refer(this._entity);
     }
   }
 
@@ -62,22 +66,8 @@ export class Polyline extends Component {
   //   return false;
   // }
   render() {
-    debug(__com__, 'render', this.props.children, this._entity);
-    let {
-      AMap,
-      options,
-      events,
-      match,
-      location,
-      history,
-      staticContext,
-      ...rest
-    } = this.props;
+    debug(__com__, 'render', this._entity);
     return null;
-    // return (
-    //   <React.Fragment>
-    //   </React.Fragment>
-    // )
   }
 }
 

+ 74 - 62
src/lib/api.js

@@ -5,6 +5,9 @@ import isEmpty from 'lodash/isEmpty';
 //import loadjscssfile from './loadScript';
 import APILoader from './APILoader'
 
+//const xdebug = console.log;
+const xdebug = () => {};
+
 export const loadApi = (key = '0325e3d6d69cd56de4980b4f28906fd8') => {
   return new APILoader({
     key,
@@ -62,9 +65,9 @@ export const loadMap = key => {
 /**
  * [加载插件](https://lbs.amap.com/api/javascript-api/guide/abc/plugins)
  * 加载完成后,可以调用:
- *  var toolbar = new AMap.ToolBar();
+ *  var toolbar = new window.AMap.ToolBar();
  *  map.addControl(toolbar);
- * @param {string} name 插件名或插件数组,如:AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
+ * @param {string} name 插件名或插件数组,如:window.AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
  */
 export const loadPlugin = name => {
   return new Promise((resolve, reject) => {
@@ -80,28 +83,9 @@ export const loadPlugin = name => {
 };
 
 ////////////////////////////////////////////////////////////
-// Map
+// 工具方法
 ////////////////////////////////////////////////////////////
-export const createMap = (AMap, dom, options, events) => {
-  const __func__ = 'createMap';
-  if (!AMap) {
-    console.log(__func__, 'fail! no AMap!');
-    return null;
-  }
-  if (!dom) {
-    console.log(__func__, 'fail! no dom!');
-    return null;
-  }
-  let map = new AMap.Map(dom, { ...(options || {}) });
-  forOwn(events, (value, key) => {
-    console.log(__func__, 'event on ' + key);
-    map.on(key, value);
-  });
-  console.log(__func__, 'ok!');
-  return map;
-};
-
-export const commonUpdate = (
+const commonUpdate = (
   entity,
   newOptions,
   newEvents,
@@ -112,7 +96,7 @@ export const commonUpdate = (
 ) => {
   // const __func__ = 'commonUpdate';
   if (!entity) {
-    console.log(__func__, 'fail! no entity!');
+    xdebug(__func__, 'fail! no entity!');
     return false;
   }
 
@@ -190,11 +174,11 @@ export const commonUpdate = (
         func(value);
       } else {
         // ignore properties can not set.
-        console.log(__func__, 'warning! no setter! can not update ' + key);
+        xdebug(__func__, 'warning! no setter! can not update ' + key);
       }
     } else {
       // key removed, not support!
-      console.log(__func__, 'warning! remove prop not support! key=' + key);
+      xdebug(__func__, 'warning! remove prop not support! key=' + key);
     }
   });
   forOwn(events, (value, key) => {
@@ -207,7 +191,7 @@ export const commonUpdate = (
     }
   });
   if (!isEmpty(props) || !isEmpty(events)) {
-    console.log(
+    xdebug(
       __func__, 'update:',
       props,
       events,
@@ -220,6 +204,28 @@ export const commonUpdate = (
   return true;
 };
 
+////////////////////////////////////////////////////////////
+// Map
+////////////////////////////////////////////////////////////
+export const createMap = (dom, options, events) => {
+  const __func__ = 'createMap';
+  if (!window.AMap) {
+    xdebug(__func__, 'fail! no window.AMap!');
+    return null;
+  }
+  if (!dom) {
+    xdebug(__func__, 'fail! no dom!');
+    return null;
+  }
+  let map = new window.AMap.Map(dom, { ...(options || {}) });
+  forOwn(events, (value, key) => {
+    xdebug(__func__, 'event on ' + key);
+    map.on(key, value);
+  });
+  xdebug(__func__, 'ok!');
+  return map;
+};
+
 export const updateMap = (
   map,
   newOptions,
@@ -284,18 +290,18 @@ export const updateMap = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createMarker = (AMap, options, events) => {
+export const createMarker = (options, events) => {
   const __func__ = 'createMarker';
-  if (!AMap) {
-    console.log(__func__, 'fail! no AMap!');
+  if (!window.AMap) {
+    xdebug(__func__, 'fail! no window.AMap!');
     return null;
   }
   if (!options) {
-    console.log(__func__, 'fail! no options!');
+    xdebug(__func__, 'fail! no options!');
     return null;
   }
   if (!options.map) {
-    console.log(__func__, 'fail! no options.map!');
+    xdebug(__func__, 'fail! no options.map!');
     return null;
   }
   // let marker = new AMap.Marker({
@@ -303,11 +309,11 @@ export const createMarker = (AMap, options, events) => {
   //   position: [116.405467, 39.907761]
   // });
   // marker.setMap(map);
-  let entity = new AMap.Marker(options);
+  let entity = new window.AMap.Marker(options);
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -363,19 +369,19 @@ export const updateMarker = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createTraffic = (AMap, options, events) => {
+export const createTraffic = (options, events) => {
   const __func__ = 'createTraffic';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:'+!!AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
     return null;
   }
   let {map, data, ...restOpts} = options;
-  let entity = new AMap.TileLayer.Traffic(data, restOpts);
+  let entity = new window.AMap.TileLayer.Traffic(data, restOpts);
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
   entity.setMap(map);
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -417,19 +423,19 @@ export const updateTraffic = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createMassMarks = (AMap, options, events) => {
+export const createMassMarks = (options, events) => {
   const __func__ = 'createMassMarks';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:'+!!AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
     return null;
   }
-  let {map, data, ...restOpts} = options;
-  let entity = new AMap.MassMarks(data, restOpts);
+  let {map, data, style, ...restOpts} = options;
+  let entity = new window.AMap.MassMarks(data||[], {...restOpts, style: style||[]});
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
   entity.setMap(map);
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
   return entity;
 };
 
@@ -447,9 +453,15 @@ export const updateMassMarks = (
     cursor: v => entity.setCursor(v),
     alwaysRender: null,
     style: v => entity.setStyle(v),
-    map: v => entity.setMap(v),
-    data: v=> entity.setData(v)
+    map: v => {
+      xdebug('updateMassMarks', 'setMap', v, 'layers:', (v && v.getLayers()));
+      entity.setMap(v)
+    },
+    data: v=> {
+      entity.setData(v);
+    }
   };
+  xdebug('updateMassMarks', 'mapOld:', (oldOptions && oldOptions.map && oldOptions.map.getLayers()), 'mapNew:', (newOptions && newOptions.map && newOptions.map.getLayers()));
 
   return commonUpdate (
     entity,
@@ -472,17 +484,17 @@ export const updateMassMarks = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createPolygon = (AMap, options, events) => {
+export const createPolygon = (options, events) => {
   const __func__ = 'createPolygon';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:'+!!AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
     return null;
   }
-  let entity = new AMap.Polygon(options);
+  let entity = new window.AMap.Polygon(options);
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -532,17 +544,17 @@ export const updatePolygon = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createPolyline = (AMap, options, events) => {
+export const createPolyline = (options, events) => {
   const __func__ = 'createPolyline';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:'+!!AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
     return null;
   }
-  let entity = new AMap.Polyline(options);
+  let entity = new window.AMap.Polyline(options);
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };
 
@@ -597,17 +609,17 @@ export const updatePolyline = (
  * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  * @param {*} events
  */
-export const createInfoWindow = (AMap, options, events) => {
+export const createInfoWindow = (options, events) => {
   const __func__ = 'createInfoWindow';
-  if (!AMap || !options || !options.map) {
-    console.log(__func__, 'fail! parameters!', 'AMap:'+!!AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
+  if (!window.AMap || !options || !options.map) {
+    xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
     return null;
   }
-  let entity = new AMap.InfoWindow(options);
+  let entity = new window.AMap.InfoWindow(options);
   forOwn(events, (value, key) => {
     entity.on(key, value);
   });
-  console.log(__func__, 'ok!');
+  xdebug(__func__, 'ok!');
   return entity;
 };