UNPKG

@mapbox/react-map-gl

Version:

A React wrapper for MapboxGL-js and overlay API.

133 lines (116 loc) 5.21 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; // 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. import { document } from '../utils/globals'; import PropTypes from 'prop-types'; import BaseControl from './base-control'; import { createElement } from 'react'; import mapboxgl from '../utils/mapboxgl'; var propTypes = Object.assign({}, BaseControl.propTypes, { // Custom className className: PropTypes.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.object }); var defaultProps = Object.assign({}, BaseControl.defaultProps, { className: '', container: null }); var FullscreenControl = /*#__PURE__*/ function (_BaseControl) { _inherits(FullscreenControl, _BaseControl); function FullscreenControl(props) { var _this; _classCallCheck(this, FullscreenControl); _this = _possibleConstructorReturn(this, _getPrototypeOf(FullscreenControl).call(this, props)); _defineProperty(_assertThisInitialized(_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 }); }); _defineProperty(_assertThisInitialized(_this), "_onClickFullscreen", function () { _this._mapboxFullscreenControl._onClickFullscreen(); }); _this._mapboxFullscreenControl = null; _this.state = { isFullscreen: false }; return _this; } _createClass(FullscreenControl, [{ key: "componentDidMount", value: function componentDidMount() { var container = this.props.container || this._context.mapContainer; this._mapboxFullscreenControl = new mapboxgl.FullscreenControl({ container: container }); this.setState({ showButton: this._mapboxFullscreenControl._checkFullscreenSupport() }); document.addEventListener(this._mapboxFullscreenControl._fullscreenchange, this._onFullscreenChange); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { document.removeEventListener(this._mapboxFullscreenControl._fullscreenchange, this._onFullscreenChange); } }, { key: "_renderButton", value: function _renderButton(type, label, callback, children) { return 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 createElement('div', { className: "mapboxgl-ctrl mapboxgl-ctrl-group ".concat(className), ref: this._containerRef }, [this._renderButton(type, 'Toggle fullscreen', this._onClickFullscreen)]); } }]); return FullscreenControl; }(BaseControl); _defineProperty(FullscreenControl, "propTypes", propTypes); _defineProperty(FullscreenControl, "defaultProps", defaultProps); export { FullscreenControl as default }; //# sourceMappingURL=fullscreen-control.js.map