"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var THREE = _interopRequireWildcard(require("three"));
var _View = _interopRequireDefault(require("../View"));
var _CameraUtils = _interopRequireDefault(require("../../Utils/CameraUtils"));
var _PlanarControls = _interopRequireDefault(require("../../Controls/PlanarControls"));
var _PlanarLayer = _interopRequireDefault(require("./Planar/PlanarLayer"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
class PlanarView extends _View.default {
  /**
   * @constructor
   * @extends View
   *
   * @example <caption><b>Enable WebGl 1.0 instead of WebGl 2.0.</b></caption>
   * var viewerDiv = document.getElementById('viewerDiv');
   * const extent = new Extent('EPSG:3946', 1837816.94334, 1847692.32501, 5170036.4587, 5178412.82698);
   * var view = new itowns.PlanarView(viewerDiv, extent, {  renderer: { isWebGL2: false } });
   *
   * @example <caption><b>Instance with placement on the ground.</b></caption>
   * var viewerDiv = document.getElementById('viewerDiv');
   * const extent = new Extent('EPSG:3946', 1837816.94334, 1847692.32501, 5170036.4587, 5178412.82698);
   * var view = new itowns.PlanarView(viewerDiv, extent, { placement: { heading: -49.6, range: 6200, tilt: 17 } });
   *
   * @param {HTMLDivElement} viewerDiv - Where to attach the view and display it
   * in the DOM.
   * @param {Extent} extent - The ground extent.
   * @param {object=} options - See options of {@link View}.
   * @param {boolean} [options.noControls=false] - If true, no controls are associated to the view.
   * @param {object=} [options.controls] - options for the {@link PlanarControls} associated to the view, if
   * `options.noControls` is false.
   * @param {CameraUtils~CameraTransformOptions|Extent} [options.placement] - The
   * {@link CameraUtils~CameraTransformOptions} to apply to view's camera or the extent it must display at
   * initialization. By default, camera will display the view's extent (given in `extent` parameter).
   */
  constructor(viewerDiv, extent) {
    let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    THREE.Object3D.DEFAULT_UP.set(0, 0, 1);

    // Setup View
    super(extent.crs, viewerDiv, options);
    this.isPlanarView = true;

    // Configure camera
    const dim = extent.planarDimensions();
    const max = Math.max(dim.x, dim.y);
    this.camera3D.near = 0.1;
    this.camera3D.far = this.camera3D.isOrthographicCamera ? 2000 : 2 * max;
    this.camera3D.updateProjectionMatrix();
    const tileLayer = new _PlanarLayer.default('planar', extent, options.object3d, options);
    this.mainLoop.gfxEngine.label2dRenderer.infoTileLayer = tileLayer.info;
    this.addLayer(tileLayer);

    // Configure camera
    const placement = options.placement || {};
    if (!placement.isExtent) {
      placement.coord = placement.coord || extent.center();
      placement.tilt = placement.tilt || 90;
      placement.heading = placement.heading || 0;
      placement.range = placement.range || max;
    }
    _CameraUtils.default.transformCameraToLookAtTarget(this, this.camera3D, placement);
    if (!options.noControls) {
      this.controls = new _PlanarControls.default(this, options.controls);
    }
    this.tileLayer = tileLayer;
  }
  addLayer(layer) {
    return super.addLayer(layer, this.tileLayer);
  }
}
var _default = PlanarView;
exports.default = _default;