text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.testExports = exports.default = exports.MAPBOX_LIMITS = void 0;
  
  var _math = require("math.gl");
  
  var _controller = _interopRequireDefault(require("./controller"));
  
  var _viewState = _interopRequireDefault(require("./view-state"));
  
  var _viewportMercatorProject = _interopRequireWildcard(require("viewport-mercator-project"));
  
  var _assert = _interopRequireDefault(require("../utils/assert"));
  
  var _linearInterpolator = _interopRequireDefault(require("../transitions/linear-interpolator"));
  
  var _transitionManager = require("./transition-manager");
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  
  function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  
  function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } _setPrototypeOf(subClass.prototype, superClass && superClass.prototype); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  var LINEAR_TRANSITION_PROPS = {
    transitionDuration: 300,
    transitionEasing: function transitionEasing(t) {
      return t;
    },
    transitionInterpolator: new _linearInterpolator.default(),
    transitionInterruption: _transitionManager.TRANSITION_EVENTS.BREAK
  }; // MAPBOX LIMITS
  
  var MAPBOX_LIMITS = {
    minZoom: 0,
    maxZoom: 20,
    minPitch: 0,
    maxPitch: 60
  };
  exports.MAPBOX_LIMITS = MAPBOX_LIMITS;
  var DEFAULT_STATE = {
    pitch: 0,
    bearing: 0,
    altitude: 1.5
  };
  /* Utils */
  
  var MapState =
  /*#__PURE__*/
  function (_ViewState) {
    _inherits(MapState, _ViewState);
  
    function MapState() {
      var _this;
  
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
          width = _ref.width,
          height = _ref.height,
          latitude = _ref.latitude,
          longitude = _ref.longitude,
          zoom = _ref.zoom,
          _ref$bearing = _ref.bearing,
          bearing = _ref$bearing === void 0 ? DEFAULT_STATE.bearing : _ref$bearing,
          _ref$pitch = _ref.pitch,
          pitch = _ref$pitch === void 0 ? DEFAULT_STATE.pitch : _ref$pitch,
          _ref$altitude = _ref.altitude,
          altitude = _ref$altitude === void 0 ? DEFAULT_STATE.altitude : _ref$altitude,
          _ref$maxZoom = _ref.maxZoom,
          maxZoom = _ref$maxZoom === void 0 ? MAPBOX_LIMITS.maxZoom : _ref$maxZoom,
          _ref$minZoom = _ref.minZoom,
          minZoom = _ref$minZoom === void 0 ? MAPBOX_LIMITS.minZoom : _ref$minZoom,
          _ref$maxPitch = _ref.maxPitch,
          maxPitch = _ref$maxPitch === void 0 ? MAPBOX_LIMITS.maxPitch : _ref$maxPitch,
          _ref$minPitch = _ref.minPitch,
          minPitch = _ref$minPitch === void 0 ? MAPBOX_LIMITS.minPitch : _ref$minPitch,
          startPanLngLat = _ref.startPanLngLat,
          startZoomLngLat = _ref.startZoomLngLat,
          startBearing = _ref.startBearing,
          startPitch = _ref.startPitch,
          startZoom = _ref.startZoom;
  
      _classCallCheck(this, MapState);
  
      (0, _assert.default)(Number.isFinite(longitude), '`longitude` must be supplied');
      (0, _assert.default)(Number.isFinite(latitude), '`latitude` must be supplied');
      (0, _assert.default)(Number.isFinite(zoom), '`zoom` must be supplied');
      _this = _possibleConstructorReturn(this, (MapState.__proto__ || Object.getPrototypeOf(MapState)).call(this, {
        width: width,
        height: height,
        latitude: latitude,
        longitude: longitude,
        zoom: zoom,
        bearing: bearing,
        pitch: pitch,
        altitude: altitude,
        maxZoom: maxZoom,
        minZoom: minZoom,
        maxPitch: maxPitch,
        minPitch: minPitch
      }));
      _this._interactiveState = {
        startPanLngLat: startPanLngLat,
        startZoomLngLat: startZoomLngLat,
        startBearing: startBearing,
        startPitch: startPitch,
        startZoom: startZoom
      };
      return _this;
    }
    /* Public API */
  
  
    _createClass(MapState, [{
      key: "getViewportProps",
      value: function getViewportProps() {
        return this._viewportProps;
      }
    }, {
      key: "getInteractiveState",
      value: function getInteractiveState() {
        return this._interactiveState;
      }
      /**
       * Start panning
       * @param {[Number, Number]} pos - position on screen where the pointer grabs
       */
  
    }, {
      key: "panStart",
      value: function panStart(_ref2) {
        var pos = _ref2.pos;
        return this._getUpdatedState({
          startPanLngLat: this._unproject(pos)
        });
      }
      /**
       * Pan
       * @param {[Number, Number]} pos - position on screen where the pointer is
       * @param {[Number, Number], optional} startPos - where the pointer grabbed at
       *   the start of the operation. Must be supplied of `panStart()` was not called
       */
  
    }, {
      key: "pan",
      value: function pan(_ref3) {
        var pos = _ref3.pos,
            startPos = _ref3.startPos;
  
        var startPanLngLat = this._interactiveState.startPanLngLat || this._unproject(startPos);
  
        if (!startPanLngLat) {
          return this;
        }
  
        var _this$_calculateNewLn = this._calculateNewLngLat({
          startPanLngLat: startPanLngLat,
          pos: pos
        }),
            _this$_calculateNewLn2 = _slicedToArray(_this$_calculateNewLn, 2),
            longitude = _this$_calculateNewLn2[0],
            latitude = _this$_calculateNewLn2[1];
  
        return this._getUpdatedState({
          longitude: longitude,
          latitude: latitude
        });
      }
      /**
       * End panning
       * Must call if `panStart()` was called
       */
  
    }, {
      key: "panEnd",
      value: function panEnd() {
        return this._getUpdatedState({
          startPanLngLat: null
        });
      }
      /**
       * Start rotating
       * @param {[Number, Number]} pos - position on screen where the center is
       */
  
    }, {
      key: "rotateStart",
      value: function rotateStart(_ref4) {
        var pos = _ref4.pos;
        return this._getUpdatedState({
          startBearing: this._viewportProps.bearing,
          startPitch: this._viewportProps.pitch
        });
      }
      /**
       * Rotate
       * @param {Number} deltaScaleX - a number between [-1, 1] specifying the
       *   change to bearing.
       * @param {Number} deltaScaleY - a number between [-1, 1] specifying the
       *   change to pitch. -1 sets to minPitch and 1 sets to maxPitch.
       */
  
    }, {
      key: "rotate",
      value: function rotate(_ref5) {
        var _ref5$deltaScaleX = _ref5.deltaScaleX,
            deltaScaleX = _ref5$deltaScaleX === void 0 ? 0 : _ref5$deltaScaleX,
            _ref5$deltaScaleY = _ref5.deltaScaleY,
            deltaScaleY = _ref5$deltaScaleY === void 0 ? 0 : _ref5$deltaScaleY;
        var _this$_interactiveSta = this._interactiveState,
            startBearing = _this$_interactiveSta.startBearing,
            startPitch = _this$_interactiveSta.startPitch;
  
        if (!Number.isFinite(startBearing) || !Number.isFinite(startPitch)) {
          return this;
        }
  
        var _this$_calculateNewPi = this._calculateNewPitchAndBearing({
          deltaScaleX: deltaScaleX,
          deltaScaleY: deltaScaleY,
          startBearing: startBearing,
          startPitch: startPitch
        }),
            pitch = _this$_calculateNewPi.pitch,
            bearing = _this$_calculateNewPi.bearing;
  
        return this._getUpdatedState({
          bearing: bearing,
          pitch: pitch
        });
      }
      /**
       * End rotating
       * Must call if `rotateStart()` was called
       */
  
    }, {
      key: "rotateEnd",
      value: function rotateEnd() {
        return this._getUpdatedState({
          startBearing: null,
          startPitch: null
        });
      }
      /**
       * Start zooming
       * @param {[Number, Number]} pos - position on screen where the center is
       */
  
    }, {
      key: "zoomStart",
      value: function zoomStart(_ref6) {
        var pos = _ref6.pos;
        return this._getUpdatedState({
          startZoomLngLat: this._unproject(pos),
          startZoom: this._viewportProps.zoom
        });
      }
      /**
       * Zoom
       * @param {[Number, Number]} pos - position on screen where the current center is
       * @param {[Number, Number]} startPos - the center position at
       *   the start of the operation. Must be supplied of `zoomStart()` was not called
       * @param {Number} scale - a number between [0, 1] specifying the accumulated
       *   relative scale.
       */
  
    }, {
      key: "zoom",
      value: function zoom(_ref7) {
        var pos = _ref7.pos,
            startPos = _ref7.startPos,
            scale = _ref7.scale;
        (0, _assert.default)(scale > 0, '`scale` must be a positive number'); // Make sure we zoom around the current mouse position rather than map center
  
        var _this$_interactiveSta2 = this._interactiveState,
            startZoom = _this$_interactiveSta2.startZoom,
            startZoomLngLat = _this$_interactiveSta2.startZoomLngLat;
  
        if (!Number.isFinite(startZoom)) {
          // We have two modes of zoom:
          // scroll zoom that are discrete events (transform from the current zoom level),
          // and pinch zoom that are continuous events (transform from the zoom level when
          // pinch started).
          // If startZoom state is defined, then use the startZoom state;
          // otherwise assume discrete zooming
          startZoom = this._viewportProps.zoom;
          startZoomLngLat = this._unproject(startPos) || this._unproject(pos);
        } // take the start lnglat and put it where the mouse is down.
  
  
        (0, _assert.default)(startZoomLngLat, '`startZoomLngLat` prop is required ' + 'for zoom behavior to calculate where to position the map.');
  
        var zoom = this._calculateNewZoom({
          scale: scale,
          startZoom: startZoom
        });
  
        var zoomedViewport = new _viewportMercatorProject.default(Object.assign({}, this._viewportProps, {
          zoom: zoom
        }));
  
        var _zoomedViewport$getLo = zoomedViewport.getLocationAtPoint({
          lngLat: startZoomLngLat,
          pos: pos
        }),
            _zoomedViewport$getLo2 = _slicedToArray(_zoomedViewport$getLo, 2),
            longitude = _zoomedViewport$getLo2[0],
            latitude = _zoomedViewport$getLo2[1];
  
        return this._getUpdatedState({
          zoom: zoom,
          longitude: longitude,
          latitude: latitude
        });
      }
      /**
       * End zooming
       * Must call if `zoomStart()` was called
       */
  
    }, {
      key: "zoomEnd",
      value: function zoomEnd() {
        return this._getUpdatedState({
          startZoomLngLat: null,
          startZoom: null
        });
      }
    }, {
      key: "zoomIn",
      value: function zoomIn() {
        return this._zoomFromCenter(2);
      }
    }, {
      key: "zoomOut",
      value: function zoomOut() {
        return this._zoomFromCenter(0.5);
      }
    }, {
      key: "moveLeft",
      value: function moveLeft() {
        return this._panFromCenter([100, 0]);
      }
    }, {
      key: "moveRight",
      value: function moveRight() {
        return this._panFromCenter([-100, 0]);
      }
    }, {
      key: "moveUp",
      value: function moveUp() {
        return this._panFromCenter([0, 100]);
      }
    }, {
      key: "moveDown",
      value: function moveDown() {
        return this._panFromCenter([0, -100]);
      }
    }, {
      key: "rotateLeft",
      value: function rotateLeft() {
        return this._getUpdatedState({
          bearing: this._viewportProps.bearing - 15
        });
      }
    }, {
      key: "rotateRight",
      value: function rotateRight() {
        return this._getUpdatedState({
          bearing: this._viewportProps.bearing + 15
        });
      }
    }, {
      key: "rotateUp",
      value: function rotateUp() {
        return this._getUpdatedState({
          pitch: this._viewportProps.pitch + 10
        });
      }
    }, {
      key: "rotateDown",
      value: function rotateDown() {
        return this._getUpdatedState({
          pitch: this._viewportProps.pitch - 10
        });
      }
    }, {
      key: "shortestPathFrom",
      value: function shortestPathFrom(viewState) {
        // const endViewStateProps = new this.ControllerState(endProps).shortestPathFrom(startViewstate);
        var fromProps = viewState.getViewportProps();
        var props = Object.assign({}, this._viewportProps);
        var bearing = props.bearing,
            longitude = props.longitude;
  
        if (Math.abs(bearing - fromProps.bearing) > 180) {
          props.bearing = bearing < 0 ? bearing + 360 : bearing - 360;
        }
  
        if (Math.abs(longitude - fromProps.longitude) > 180) {
          props.longitude = longitude < 0 ? longitude + 360 : longitude - 360;
        }
  
        return props;
      }
      /* Private methods */
  
    }, {
      key: "_zoomFromCenter",
      value: function _zoomFromCenter(scale) {
        var _this$_viewportProps = this._viewportProps,
            width = _this$_viewportProps.width,
            height = _this$_viewportProps.height;
        return this.zoom({
          pos: [width / 2, height / 2],
          scale: scale
        });
      }
    }, {
      key: "_panFromCenter",
      value: function _panFromCenter(offset) {
        var _this$_viewportProps2 = this._viewportProps,
            width = _this$_viewportProps2.width,
            height = _this$_viewportProps2.height;
        return this.pan({
          startPos: [width / 2, height / 2],
          pos: [width / 2 + offset[0], height / 2 + offset[1]]
        });
      }
    }, {
      key: "_getUpdatedState",
      value: function _getUpdatedState(newProps) {
        // Update _viewportProps
        return new MapState(Object.assign({}, this._viewportProps, this._interactiveState, newProps));
      } // Apply any constraints (mathematical or defined by _viewportProps) to map state
  
    }, {
      key: "_applyConstraints",
      value: function _applyConstraints(props) {
        // Ensure zoom is within specified range
        var maxZoom = props.maxZoom,
            minZoom = props.minZoom,
            zoom = props.zoom;
        props.zoom = (0, _math.clamp)(zoom, minZoom, maxZoom); // Ensure pitch is within specified range
  
        var maxPitch = props.maxPitch,
            minPitch = props.minPitch,
            pitch = props.pitch;
        props.pitch = (0, _math.clamp)(pitch, minPitch, maxPitch);
        Object.assign(props, (0, _viewportMercatorProject.normalizeViewportProps)(props));
        return props;
      }
    }, {
      key: "_unproject",
      value: function _unproject(pos) {
        var viewport = new _viewportMercatorProject.default(this._viewportProps);
        return pos && viewport.unproject(pos);
      } // Calculate a new lnglat based on pixel dragging position
  
    }, {
      key: "_calculateNewLngLat",
      value: function _calculateNewLngLat(_ref8) {
        var startPanLngLat = _ref8.startPanLngLat,
            pos = _ref8.pos;
        var viewport = new _viewportMercatorProject.default(this._viewportProps);
        return viewport.getMapCenterByLngLatPosition({
          lngLat: startPanLngLat,
          pos: pos
        });
      } // Calculates new zoom
  
    }, {
      key: "_calculateNewZoom",
      value: function _calculateNewZoom(_ref9) {
        var scale = _ref9.scale,
            startZoom = _ref9.startZoom;
        var _this$_viewportProps3 = this._viewportProps,
            maxZoom = _this$_viewportProps3.maxZoom,
            minZoom = _this$_viewportProps3.minZoom;
        var zoom = startZoom + Math.log2(scale);
        return (0, _math.clamp)(zoom, minZoom, maxZoom);
      } // Calculates a new pitch and bearing from a position (coming from an event)
  
    }, {
      key: "_calculateNewPitchAndBearing",
      value: function _calculateNewPitchAndBearing(_ref10) {
        var deltaScaleX = _ref10.deltaScaleX,
            deltaScaleY = _ref10.deltaScaleY,
            startBearing = _ref10.startBearing,
            startPitch = _ref10.startPitch;
        // clamp deltaScaleY to [-1, 1] so that rotation is constrained between minPitch and maxPitch.
        // deltaScaleX does not need to be clamped as bearing does not have constraints.
        deltaScaleY = (0, _math.clamp)(deltaScaleY, -1, 1);
        var _this$_viewportProps4 = this._viewportProps,
            minPitch = _this$_viewportProps4.minPitch,
            maxPitch = _this$_viewportProps4.maxPitch;
        var bearing = startBearing + 180 * deltaScaleX;
        var pitch = startPitch;
  
        if (deltaScaleY > 0) {
          // Gradually increase pitch
          pitch = startPitch + deltaScaleY * (maxPitch - startPitch);
        } else if (deltaScaleY < 0) {
          // Gradually decrease pitch
          pitch = startPitch - deltaScaleY * (minPitch - startPitch);
        }
  
        return {
          pitch: pitch,
          bearing: bearing
        };
      }
    }]);
  
    return MapState;
  }(_viewState.default);
  
  var MapController =
  /*#__PURE__*/
  function (_Controller) {
    _inherits(MapController, _Controller);
  
    function MapController(props) {
      var _this2;
  
      _classCallCheck(this, MapController);
  
      _this2 = _possibleConstructorReturn(this, (MapController.__proto__ || Object.getPrototypeOf(MapController)).call(this, MapState, props));
      _this2.invertPan = true;
      return _this2;
    }
  
    _createClass(MapController, [{
      key: "_getTransitionProps",
      value: function _getTransitionProps() {
        // Transitions on double-tap and key-down are only supported by MapController
        return LINEAR_TRANSITION_PROPS;
      }
    }]);
  
    return MapController;
  }(_controller.default);
  
  exports.default = MapController;
  var testExports = {
    MapState: MapState
  };
  exports.testExports = testExports;
  //# sourceMappingURL=map-controller.js.map