Geolocation.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 } from "react";
  7. import PropTypes from "prop-types";
  8. import { getLocation } from "./api";
  9. var debug = function debug() {};
  10. var Geolocation = function (_Component) {
  11. _inherits(Geolocation, _Component);
  12. function Geolocation(props) {
  13. _classCallCheck(this, Geolocation);
  14. var _this = _possibleConstructorReturn(this, (Geolocation.__proto__ || Object.getPrototypeOf(Geolocation)).call(this, props));
  15. _this._entity = null;
  16. return _this;
  17. }
  18. _createClass(Geolocation, [{
  19. key: "componentDidMount",
  20. value: function componentDidMount() {
  21. var _props = this.props,
  22. __map__ = _props.__map__,
  23. options = _props.options,
  24. events = _props.events,
  25. children = _props.children;
  26. var opts = _extends({}, options || {}, { map: __map__ });
  27. var evts = events || {};
  28. this._entity = getLocation(opts, evts);
  29. }
  30. }, {
  31. key: "componentDidUpdate",
  32. value: function componentDidUpdate(prevProps) {
  33. var _props2 = this.props,
  34. __map__ = _props2.__map__,
  35. options = _props2.options,
  36. events = _props2.events;
  37. var opts = _extends({}, options || {}, { map: __map__ });
  38. var evts = events || {};
  39. if (!this._entity) {
  40. this._entity = getLocation(opts, evts);
  41. return;
  42. }
  43. }
  44. }, {
  45. key: "render",
  46. value: function render() {
  47. return null;
  48. }
  49. }]);
  50. return Geolocation;
  51. }(Component);
  52. Geolocation.propTypes = {
  53. __map__: PropTypes.object,
  54. options: PropTypes.object,
  55. events: PropTypes.object
  56. };
  57. export default Geolocation;