Polygon.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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: 'componentWillMount',
  25. value: function componentWillMount() {
  26. debug(__com__, 'componentWillMount', this._entity);
  27. }
  28. }, {
  29. key: 'componentDidMount',
  30. value: function componentDidMount() {
  31. debug(__com__, 'componentDidMount', this._entity);
  32. var _props = this.props,
  33. AMap = _props.AMap,
  34. __map__ = _props.__map__,
  35. options = _props.options,
  36. events = _props.events,
  37. children = _props.children;
  38. //let opts = { ...(options || {}), map: __map__, content: children };
  39. var opts = _extends({}, options || {}, { map: __map__ });
  40. this._entity = createPolygon(AMap, opts, events);
  41. }
  42. }, {
  43. key: 'componentWillReceiveProps',
  44. value: function componentWillReceiveProps(nextProps) {
  45. debug(__com__, 'componentWillReceiveProps', this._entity);
  46. }
  47. }, {
  48. key: 'componentWillUpdate',
  49. value: function componentWillUpdate() {
  50. debug(__com__, 'componentWillUpdate', this._entity);
  51. }
  52. }, {
  53. key: 'componentDidUpdate',
  54. value: function componentDidUpdate(prevProps) {
  55. debug(__com__, 'componentDidUpdate', this._entity);
  56. var _props2 = this.props,
  57. AMap = _props2.AMap,
  58. __map__ = _props2.__map__,
  59. options = _props2.options,
  60. events = _props2.events,
  61. children = _props2.children;
  62. //let opts = { ...(options || {}), map: __map__, content: children };
  63. var opts = _extends({}, options || {}, { map: __map__ });
  64. if (!this._entity) {
  65. this._entity = createPolygon(AMap, opts, events);
  66. return;
  67. }
  68. // need check props changes, then update.
  69. var oldOpts = _extends({}, prevProps.options || {}, {
  70. map: prevProps.__map__
  71. });
  72. updatePolygon(this._entity, opts, events, oldOpts, prevProps.events);
  73. }
  74. }, {
  75. key: 'componentWillUnmount',
  76. value: function componentWillUnmount() {
  77. debug(__com__, 'componentWillUnmount', this._entity);
  78. if (this._entity) {
  79. // this._entity.clearMap();
  80. this._entity.setMap(null);
  81. delete this._entity;
  82. // delete this._entity;
  83. this._entity = null;
  84. }
  85. }
  86. // shouldComponentUpdate(nextProps, nextState) {
  87. // debug(__com__, 'shouldComponentUpdate', this._entity);
  88. // return false;
  89. // }
  90. }, {
  91. key: 'render',
  92. value: function render() {
  93. debug(__com__, 'render', this._entity);
  94. var _props3 = this.props,
  95. AMap = _props3.AMap,
  96. options = _props3.options,
  97. events = _props3.events,
  98. match = _props3.match,
  99. location = _props3.location,
  100. history = _props3.history,
  101. staticContext = _props3.staticContext,
  102. rest = _objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
  103. return null;
  104. // return (
  105. // <React.Fragment>
  106. // </React.Fragment>
  107. // )
  108. }
  109. }]);
  110. return Polygon;
  111. }(Component);
  112. Polygon.propTypes = {
  113. AMap: PropTypes.object,
  114. __map__: PropTypes.object,
  115. options: PropTypes.object,
  116. events: PropTypes.object
  117. };
  118. export default Polygon;