"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

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

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

var THREE = _interopRequireWildcard(require("three"));

var _View2 = _interopRequireDefault(require("../View"));

var _CameraUtils = _interopRequireDefault(require("../../Utils/CameraUtils"));

var _PlanarLayer = _interopRequireDefault(require("./Planar/PlanarLayer"));

var PlanarView =
/*#__PURE__*/
function (_View) {
  (0, _inherits2["default"])(PlanarView, _View);

  function PlanarView(viewerDiv, extent) {
    var _this;

    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    (0, _classCallCheck2["default"])(this, PlanarView);
    THREE.Object3D.DefaultUp.set(0, 0, 1); // Setup View

    _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(PlanarView).call(this, extent.crs, viewerDiv, options)); // Configure camera

    var dim = extent.dimensions();
    var max = Math.max(dim.x, dim.y);
    var camera3D = _this.camera.camera3D;
    camera3D.near = 0.1;
    camera3D.far = 2 * max;

    _this.camera.camera3D.updateProjectionMatrix();

    var tileLayer = new _PlanarLayer["default"]('planar', extent, options.object3d, options);

    _this.addLayer(tileLayer);

    var p = {
      coord: extent.center(),
      range: max,
      tilt: 20,
      heading: 0
    };

    _CameraUtils["default"].transformCameraToLookAtTarget((0, _assertThisInitialized2["default"])(_this), camera3D, p);

    _this.tileLayer = tileLayer;
    return _this;
  }

  (0, _createClass2["default"])(PlanarView, [{
    key: "addLayer",
    value: function addLayer(layer) {
      return (0, _get2["default"])((0, _getPrototypeOf2["default"])(PlanarView.prototype), "addLayer", this).call(this, layer, this.tileLayer);
    }
  }]);
  return PlanarView;
}(_View2["default"]);

var _default = PlanarView;
exports["default"] = _default;