UNPKG

@mapbox/react-map-gl

Version:

A React wrapper for MapboxGL-js and overlay API.

148 lines (122 loc) 5.96 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _globals = require("../utils/globals"); var _propTypes = _interopRequireDefault(require("prop-types")); var _baseControl = _interopRequireDefault(require("./base-control")); var _react = require("react"); var _mapboxgl = _interopRequireDefault(require("../utils/mapboxgl")); // Copyright (c) 2015 Uber Technologies, Inc. // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var propTypes = Object.assign({}, _baseControl["default"].propTypes, { // Custom className className: _propTypes["default"].string, /* eslint-disable max-len */ // `container` is the [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) // which should be made full screen. By default, the map container element will be made full screen. /* eslint-enable max-len */ container: _propTypes["default"].object }); var defaultProps = Object.assign({}, _baseControl["default"].defaultProps, { className: '', container: null }); var FullscreenControl = /*#__PURE__*/ function (_BaseControl) { (0, _inherits2["default"])(FullscreenControl, _BaseControl); function FullscreenControl(props) { var _this; (0, _classCallCheck2["default"])(this, FullscreenControl); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(FullscreenControl).call(this, props)); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_onFullscreenChange", function () { var nextState = !_this._mapboxFullscreenControl._fullscreen; // this is a hack // Mapbox use `_fullscreen` flag to toggle fullscreen mode _this._mapboxFullscreenControl._fullscreen = nextState; _this.setState({ isFullscreen: nextState }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_onClickFullscreen", function () { _this._mapboxFullscreenControl._onClickFullscreen(); }); _this._mapboxFullscreenControl = null; _this.state = { isFullscreen: false }; return _this; } (0, _createClass2["default"])(FullscreenControl, [{ key: "componentDidMount", value: function componentDidMount() { var container = this.props.container || this._context.mapContainer; this._mapboxFullscreenControl = new _mapboxgl["default"].FullscreenControl({ container: container }); this.setState({ showButton: this._mapboxFullscreenControl._checkFullscreenSupport() }); _globals.document.addEventListener(this._mapboxFullscreenControl._fullscreenchange, this._onFullscreenChange); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { _globals.document.removeEventListener(this._mapboxFullscreenControl._fullscreenchange, this._onFullscreenChange); } }, { key: "_renderButton", value: function _renderButton(type, label, callback, children) { return (0, _react.createElement)('button', { key: type, className: "mapboxgl-ctrl-icon mapboxgl-ctrl-".concat(type), type: 'button', title: label, onClick: callback, children: children }); } }, { key: "_render", value: function _render() { if (!this.state.showButton) { return null; } var className = this.props.className; var isFullscreen = this.state.isFullscreen; var type = isFullscreen ? 'shrink' : 'fullscreen'; return (0, _react.createElement)('div', { className: "mapboxgl-ctrl mapboxgl-ctrl-group ".concat(className), ref: this._containerRef }, [this._renderButton(type, 'Toggle fullscreen', this._onClickFullscreen)]); } }]); return FullscreenControl; }(_baseControl["default"]); exports["default"] = FullscreenControl; (0, _defineProperty2["default"])(FullscreenControl, "propTypes", propTypes); (0, _defineProperty2["default"])(FullscreenControl, "defaultProps", defaultProps); //# sourceMappingURL=fullscreen-control.js.map