Polyline.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Polyline = undefined;
  6. var _react = require('react');
  7. var _react2 = babelHelpers.interopRequireDefault(_react);
  8. var _propTypes = require('prop-types');
  9. var _propTypes2 = babelHelpers.interopRequireDefault(_propTypes);
  10. var _api = require('./api');
  11. var __com__ = 'Polyline';
  12. //const debug = console.log;
  13. var debug = function debug() {};
  14. var Polyline = exports.Polyline = function (_Component) {
  15. babelHelpers.inherits(Polyline, _Component);
  16. function Polyline() {
  17. babelHelpers.classCallCheck(this, Polyline);
  18. var _this = babelHelpers.possibleConstructorReturn(this, (Polyline.__proto__ || Object.getPrototypeOf(Polyline)).call(this));
  19. _this.refElement = null;
  20. _this._entity = null;
  21. debug(__com__, 'constructor', _this._entity);
  22. return _this;
  23. }
  24. babelHelpers.createClass(Polyline, [{
  25. key: 'componentWillMount',
  26. value: function componentWillMount() {
  27. debug(__com__, 'componentWillMount', this.props.children, this._entity);
  28. }
  29. }, {
  30. key: 'componentDidMount',
  31. value: function componentDidMount() {
  32. debug(__com__, 'componentDidMount', this.props.children, this._entity);
  33. var _props = this.props,
  34. AMap = _props.AMap,
  35. __map__ = _props.__map__,
  36. options = _props.options,
  37. events = _props.events,
  38. children = _props.children;
  39. //let opts = { ...(options || {}), map: __map__, content: children };
  40. var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
  41. this._entity = (0, _api.createPolyline)(AMap, opts, events);
  42. }
  43. }, {
  44. key: 'componentWillReceiveProps',
  45. value: function componentWillReceiveProps(nextProps) {
  46. debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
  47. }
  48. }, {
  49. key: 'componentWillUpdate',
  50. value: function componentWillUpdate() {
  51. debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
  52. }
  53. }, {
  54. key: 'componentDidUpdate',
  55. value: function componentDidUpdate(prevProps) {
  56. debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
  57. var _props2 = this.props,
  58. AMap = _props2.AMap,
  59. __map__ = _props2.__map__,
  60. options = _props2.options,
  61. events = _props2.events,
  62. children = _props2.children;
  63. //let opts = { ...(options || {}), map: __map__, content: children };
  64. var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
  65. if (!this._entity) {
  66. this._entity = (0, _api.createPolyline)(AMap, opts, events);
  67. return;
  68. }
  69. // need check props changes, then update.
  70. var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
  71. map: prevProps.__map__
  72. });
  73. (0, _api.updatePolyline)(this._entity, opts, events, oldOpts, prevProps.events);
  74. }
  75. }, {
  76. key: 'componentWillUnmount',
  77. value: function componentWillUnmount() {
  78. debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
  79. if (this._entity) {
  80. // this._entity.clearMap();
  81. this._entity.setMap(null);
  82. delete this._entity;
  83. // delete this._entity;
  84. this._entity = null;
  85. }
  86. }
  87. // shouldComponentUpdate(nextProps, nextState) {
  88. // debug(__com__, 'shouldComponentUpdate', this._entity);
  89. // return false;
  90. // }
  91. }, {
  92. key: 'render',
  93. value: function render() {
  94. debug(__com__, 'render', this.props.children, this._entity);
  95. var _props3 = this.props,
  96. AMap = _props3.AMap,
  97. options = _props3.options,
  98. events = _props3.events,
  99. match = _props3.match,
  100. location = _props3.location,
  101. history = _props3.history,
  102. staticContext = _props3.staticContext,
  103. rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
  104. return null;
  105. // return (
  106. // <React.Fragment>
  107. // </React.Fragment>
  108. // )
  109. }
  110. }]);
  111. return Polyline;
  112. }(_react.Component);
  113. Polyline.propTypes = {
  114. AMap: _propTypes2.default.object,
  115. __map__: _propTypes2.default.object,
  116. options: _propTypes2.default.object,
  117. events: _propTypes2.default.object
  118. };
  119. exports.default = Polyline;