"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _core = require("@math.gl/core");

var _controller = _interopRequireDefault(require("./controller"));

var _mapController = require("./map-controller");

var _mathUtils = require("../utils/math-utils");

var _linearInterpolator = _interopRequireDefault(require("../transitions/linear-interpolator"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var GlobeState = function (_MapState) {
  (0, _inherits2.default)(GlobeState, _MapState);

  var _super = _createSuper(GlobeState);

  function GlobeState() {
    (0, _classCallCheck2.default)(this, GlobeState);
    return _super.apply(this, arguments);
  }

  var _proto = GlobeState.prototype;

  _proto.applyConstraints = function applyConstraints(props) {
    var maxZoom = props.maxZoom,
        minZoom = props.minZoom,
        zoom = props.zoom;
    props.zoom = (0, _core.clamp)(zoom, minZoom, maxZoom);
    var longitude = props.longitude,
        latitude = props.latitude;

    if (longitude < -180 || longitude > 180) {
      props.longitude = (0, _mathUtils.mod)(longitude + 180, 360) - 180;
    }

    props.latitude = (0, _core.clamp)(latitude, -89, 89);
    return props;
  };

  return GlobeState;
}(_mapController.MapState);

var GlobeController = function (_Controller) {
  (0, _inherits2.default)(GlobeController, _Controller);

  var _super2 = _createSuper(GlobeController);

  function GlobeController() {
    var _this;

    (0, _classCallCheck2.default)(this, GlobeController);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super2.call.apply(_super2, [this].concat(args));
    _this.ControllerState = GlobeState;
    _this.transition = {
      transitionDuration: 300,
      transitionInterpolator: new _linearInterpolator.default(['longitude', 'latitude', 'zoom'])
    };
    _this.dragMode = 'pan';
    return _this;
  }

  var _proto2 = GlobeController.prototype;

  _proto2.setProps = function setProps(props) {
    (0, _get2.default)((0, _getPrototypeOf2.default)(GlobeController.prototype), "setProps", this).call(this, props);
    this.dragRotate = false;
    this.touchRotate = false;
  };

  return GlobeController;
}(_controller.default);

exports.default = GlobeController;
//# sourceMappingURL=globe-controller.js.map