UNPKG

google-react-maps

Version:

A more powerfully custom version of the Google Maps Javascript API built for React. Multiple Datalayer support. GEOJSON Enabled.

115 lines (93 loc) 4.64 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } var KmlLayer = function (_React$Component) { _inherits(KmlLayer, _React$Component); function KmlLayer(props) { _classCallCheck(this, KmlLayer); var _this = _possibleConstructorReturn(this, (KmlLayer.__proto__ || Object.getPrototypeOf(KmlLayer)).call(this, props)); _this.displayName = 'KmlLayer'; _this.state = { KmlLayer: null }; return _this; } _createClass(KmlLayer, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; if (this.props.map && this.props.maps) { var _props = this.props, map = _props.map, maps = _props.maps, zIndex = _props.zIndex, preserveViewport = _props.preserveViewport, screenOverlays = _props.screenOverlays, suppressInfoWindows = _props.suppressInfoWindows, url = _props.url; var KmlLayer = new maps.KmlLayer({ map: map, zIndex: zIndex, preserveViewport: preserveViewport, screenOverlays: screenOverlays, suppressInfoWindows: suppressInfoWindows, url: url }); this.setState({ KmlLayer: KmlLayer }); this.listener = KmlLayer.addListener('status_changed', function (status) { switch (KmlLayer.getStatus()) { case 'INVALID_DOCUMENT': { console.error('Your kml doc is too big for google maps.'); if (_this2.props.onStatusChanged) { _this2.props.onStatusChanged(KmlLayer.getStatus()); } } } }); } else console.error(new Error("You must put <KmlLayer /> components within a <Map /> context. Or provide the maps and map props manually.")); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { if (this.state.KmlLayer) this.state.KmlLayer.setMap(null); if (this.listener) { this.listener.remove(); } } }, { key: 'render', value: function render() { if (this.state.KmlLayer && this.props.url != this.state.KmlLayer.url) this.state.KmlLayer.setUrl(this.props.url); return _react2.default.createElement( 'div', null, 'KmlLayer' ); } }]); return KmlLayer; }(_react2.default.Component); KmlLayer.propTypes = { maps: _propTypes2.default.object, map: _propTypes2.default.object, zIndex: _propTypes2.default.number.isRequired, preserveViewport: _propTypes2.default.bool, screenOverlays: _propTypes2.default.bool, suppressInfoWindows: _propTypes2.default.bool, url: _propTypes2.default.string.isRequired, onStatusChanged: _propTypes2.default.func }; exports.default = KmlLayer; module.exports = exports['default']; //# sourceMappingURL=kmlLayer.js.map