UNPKG

react-map-gl

Version:

A React wrapper for MapboxGL-js and overlay API.

121 lines (106 loc) 4.25 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"; import { createElement } from 'react'; import PropTypes from 'prop-types'; import BaseControl from './base-control'; import MapState from '../utils/map-state'; import { LINEAR_TRANSITION_PROPS } from '../utils/map-controller'; import deprecateWarn from '../utils/deprecate-warn'; var noop = function noop() {}; var propTypes = Object.assign({}, BaseControl.propTypes, { className: PropTypes.string, onViewStateChange: PropTypes.func, onViewportChange: PropTypes.func, showCompass: PropTypes.bool, showZoom: PropTypes.bool }); var defaultProps = Object.assign({}, BaseControl.defaultProps, { className: '', showCompass: true, showZoom: true }); var NavigationControl = function (_BaseControl) { _inherits(NavigationControl, _BaseControl); function NavigationControl(props) { var _this; _classCallCheck(this, NavigationControl); _this = _possibleConstructorReturn(this, _getPrototypeOf(NavigationControl).call(this, props)); _defineProperty(_assertThisInitialized(_this), "_onZoomIn", function () { _this._updateViewport({ zoom: _this._context.viewport.zoom + 1 }); }); _defineProperty(_assertThisInitialized(_this), "_onZoomOut", function () { _this._updateViewport({ zoom: _this._context.viewport.zoom - 1 }); }); _defineProperty(_assertThisInitialized(_this), "_onResetNorth", function () { _this._updateViewport({ bearing: 0, pitch: 0 }); }); deprecateWarn(props); return _this; } _createClass(NavigationControl, [{ key: "_updateViewport", value: function _updateViewport(opts) { var viewport = this._context.viewport; var mapState = new MapState(Object.assign({}, viewport, opts)); var viewState = Object.assign({}, mapState.getViewportProps(), LINEAR_TRANSITION_PROPS); var onViewportChange = this.props.onViewportChange || this._context.onViewportChange || noop; var onViewStateChange = this.props.onViewStateChange || this._context.onViewStateChange || noop; onViewStateChange({ viewState: viewState }); onViewportChange(viewState); } }, { key: "_renderCompass", value: function _renderCompass() { var bearing = this._context.viewport.bearing; return createElement('span', { className: 'mapboxgl-ctrl-compass-arrow', style: { transform: "rotate(".concat(-bearing, "deg)") } }); } }, { 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() { var _this$props = this.props, className = _this$props.className, showCompass = _this$props.showCompass, showZoom = _this$props.showZoom; return createElement('div', { className: "mapboxgl-ctrl mapboxgl-ctrl-group ".concat(className), ref: this._containerRef }, [showZoom && this._renderButton('zoom-in', 'Zoom In', this._onZoomIn), showZoom && this._renderButton('zoom-out', 'Zoom Out', this._onZoomOut), showCompass && this._renderButton('compass', 'Reset North', this._onResetNorth, this._renderCompass())]); } }]); return NavigationControl; }(BaseControl); _defineProperty(NavigationControl, "propTypes", propTypes); _defineProperty(NavigationControl, "defaultProps", defaultProps); export { NavigationControl as default }; //# sourceMappingURL=navigation-control.js.map