"use strict";

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

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

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

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 _transitionInterpolator = _interopRequireDefault(require("./transition-interpolator"));

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

var _webMercator = require("@math.gl/web-mercator");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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 LINEARLY_INTERPOLATED_PROPS = {
  bearing: 0,
  pitch: 0,
  position: [0, 0, 0]
};
var DEFAULT_OPTS = {
  speed: 1.2,
  curve: 1.414
};

var FlyToInterpolator = function (_TransitionInterpolat) {
  (0, _inherits2.default)(FlyToInterpolator, _TransitionInterpolat);

  var _super = _createSuper(FlyToInterpolator);

  function FlyToInterpolator() {
    var _this;

    var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    (0, _classCallCheck2.default)(this, FlyToInterpolator);
    _this = _super.call(this, {
      compare: ['longitude', 'latitude', 'zoom', 'bearing', 'pitch', 'position'],
      extract: ['width', 'height', 'longitude', 'latitude', 'zoom', 'bearing', 'pitch', 'position'],
      required: ['width', 'height', 'latitude', 'longitude', 'zoom']
    });
    _this.opts = void 0;
    _this.opts = _objectSpread(_objectSpread({}, DEFAULT_OPTS), opts);
    return _this;
  }

  var _proto = FlyToInterpolator.prototype;

  _proto.interpolateProps = function interpolateProps(startProps, endProps, t) {
    var viewport = (0, _webMercator.flyToViewport)(startProps, endProps, t, this.opts);

    for (var key in LINEARLY_INTERPOLATED_PROPS) {
      viewport[key] = (0, _core.lerp)(startProps[key] || LINEARLY_INTERPOLATED_PROPS[key], endProps[key] || LINEARLY_INTERPOLATED_PROPS[key], t);
    }

    return viewport;
  };

  _proto.getDuration = function getDuration(startProps, endProps) {
    var transitionDuration = endProps.transitionDuration;

    if (transitionDuration === 'auto') {
      transitionDuration = (0, _webMercator.getFlyToDuration)(startProps, endProps, this.opts);
    }

    return transitionDuration;
  };

  return FlyToInterpolator;
}(_transitionInterpolator.default);

exports.default = FlyToInterpolator;
//# sourceMappingURL=fly-to-interpolator.js.map