Polygon.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. 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; }; }();
  3. 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; }
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. 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; }
  6. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7. import React, { Component, PureComponent } from 'react';
  8. import PropTypes from 'prop-types';
  9. import { createPolygon, updatePolygon } from './api';
  10. var __com__ = 'Polygon';
  11. //const debug = console.log;
  12. var debug = function debug() {};
  13. export var Polygon = function (_Component) {
  14. _inherits(Polygon, _Component);
  15. function Polygon() {
  16. _classCallCheck(this, Polygon);
  17. var _this = _possibleConstructorReturn(this, (Polygon.__proto__ || Object.getPrototypeOf(Polygon)).call(this));
  18. _this.refElement = null;
  19. _this._entity = null;
  20. debug(__com__, 'constructor', _this._entity);
  21. return _this;
  22. }
  23. _createClass(Polygon, [{
  24. key: 'componentDidMount',
  25. value: function componentDidMount() {
  26. debug(__com__, 'componentDidMount', this._entity);
  27. var _props = this.props,
  28. AMap = _props.AMap,
  29. __map__ = _props.__map__,
  30. options = _props.options,
  31. events = _props.events,
  32. children = _props.children;
  33. //let opts = { ...(options || {}), map: __map__, content: children };
  34. var opts = _extends({}, options || {}, { map: __map__ });
  35. this._entity = createPolygon(AMap, opts, events);
  36. }
  37. }, {
  38. key: 'componentDidUpdate',
  39. value: function componentDidUpdate(prevProps) {
  40. debug(__com__, 'componentDidUpdate', this._entity);
  41. var _props2 = this.props,
  42. AMap = _props2.AMap,
  43. __map__ = _props2.__map__,
  44. options = _props2.options,
  45. events = _props2.events,
  46. children = _props2.children;
  47. //let opts = { ...(options || {}), map: __map__, content: children };
  48. var opts = _extends({}, options || {}, { map: __map__ });
  49. if (!this._entity) {
  50. this._entity = createPolygon(AMap, opts, events);
  51. return;
  52. }
  53. // need check props changes, then update.
  54. var oldOpts = _extends({}, prevProps.options || {}, {
  55. map: prevProps.__map__
  56. });
  57. updatePolygon(this._entity, opts, events, oldOpts, prevProps.events);
  58. }
  59. }, {
  60. key: 'componentWillUnmount',
  61. value: function componentWillUnmount() {
  62. debug(__com__, 'componentWillUnmount', this._entity);
  63. if (this._entity) {
  64. // this._entity.clearMap();
  65. this._entity.setMap(null);
  66. delete this._entity;
  67. // delete this._entity;
  68. this._entity = null;
  69. }
  70. }
  71. // shouldComponentUpdate(nextProps, nextState) {
  72. // debug(__com__, 'shouldComponentUpdate', this._entity);
  73. // return false;
  74. // }
  75. }, {
  76. key: 'render',
  77. value: function render() {
  78. debug(__com__, 'render', this._entity);
  79. var _props3 = this.props,
  80. AMap = _props3.AMap,
  81. options = _props3.options,
  82. events = _props3.events,
  83. match = _props3.match,
  84. location = _props3.location,
  85. history = _props3.history,
  86. staticContext = _props3.staticContext,
  87. rest = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
  88. return null;
  89. // return (
  90. // <React.Fragment>
  91. // </React.Fragment>
  92. // )
  93. }
  94. }]);
  95. return Polygon;
  96. }(Component);
  97. Polygon.propTypes = {
  98. AMap: PropTypes.object,
  99. __map__: PropTypes.object,
  100. options: PropTypes.object,
  101. events: PropTypes.object
  102. };
  103. export default Polygon;