Polyline.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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; }
  5. 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; }
  6. import React, { Component, PureComponent } from 'react';
  7. import PropTypes from 'prop-types';
  8. import { createPolyline, updatePolyline } from './api';
  9. var __com__ = 'Polyline';
  10. //const debug = console.log;
  11. var debug = function debug() {};
  12. export var Polyline = function (_Component) {
  13. _inherits(Polyline, _Component);
  14. function Polyline() {
  15. _classCallCheck(this, Polyline);
  16. var _this = _possibleConstructorReturn(this, (Polyline.__proto__ || Object.getPrototypeOf(Polyline)).call(this));
  17. _this.refElement = null;
  18. _this._entity = null;
  19. debug(__com__, 'constructor', _this._entity);
  20. return _this;
  21. }
  22. _createClass(Polyline, [{
  23. key: 'componentDidMount',
  24. value: function componentDidMount() {
  25. debug(__com__, 'componentDidMount', this.props.children, this._entity);
  26. var _props = this.props,
  27. __map__ = _props.__map__,
  28. options = _props.options,
  29. events = _props.events,
  30. children = _props.children;
  31. //let opts = { ...(options || {}), map: __map__, content: children };
  32. var opts = _extends({}, options || {}, { map: __map__ });
  33. this._entity = createPolyline(opts, events);
  34. if (this._entity) {
  35. if (this.props.refer) this.props.refer(this._entity);
  36. }
  37. }
  38. }, {
  39. key: 'componentDidUpdate',
  40. value: function componentDidUpdate(prevProps) {
  41. debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
  42. var _props2 = this.props,
  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 = createPolyline(opts, events);
  51. if (this._entity) {
  52. if (this.props.refer) this.props.refer(this._entity);
  53. }
  54. return;
  55. }
  56. // need check props changes, then update.
  57. var oldOpts = _extends({}, prevProps.options || {}, {
  58. map: prevProps.__map__
  59. });
  60. updatePolyline(this._entity, opts, events, oldOpts, prevProps.events);
  61. }
  62. }, {
  63. key: 'componentWillUnmount',
  64. value: function componentWillUnmount() {
  65. debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
  66. if (this._entity) {
  67. this._entity.setMap(null);
  68. // delete this._entity;
  69. this._entity = null;
  70. if (this.props.refer) this.props.refer(this._entity);
  71. }
  72. }
  73. // shouldComponentUpdate(nextProps, nextState) {
  74. // debug(__com__, 'shouldComponentUpdate', this._entity);
  75. // return false;
  76. // }
  77. }, {
  78. key: 'render',
  79. value: function render() {
  80. debug(__com__, 'render', this._entity);
  81. return null;
  82. }
  83. }]);
  84. return Polyline;
  85. }(Component);
  86. Polyline.propTypes = {
  87. __map__: PropTypes.object,
  88. options: PropTypes.object,
  89. events: PropTypes.object
  90. };
  91. export default Polyline;