"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 _TiledGeometryLayer = _interopRequireDefault(require("../../../Layer/TiledGeometryLayer"));
var _Extent = require("../../Geographic/Extent");
var _Crs = _interopRequireDefault(require("../../Geographic/Crs"));
var _PlanarTileBuilder = _interopRequireDefault(require("./PlanarTileBuilder"));
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; }
/**
 * @property {boolean} isPlanarLayer - Used to checkout whether this layer is a
 * PlanarLayer. Default is true. You should not change this, as it is used
 * internally for optimisation.
 */
class PlanarLayer extends _TiledGeometryLayer.default {
  /**
   * A {@link TiledGeometryLayer} to use with a {@link PlanarView}. It has
   * specific method for updating and subdivising its grid.
   *
   * @constructor
   * @extends TiledGeometryLayer
   *
   * @param {string} id - The id of the layer, that should be unique. It is
   * not mandatory, but an error will be emitted if this layer is added a
   * {@link View} that already has a layer going by that id.
   * @param {Extent} extent - The extent to define the layer within.
   * @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
   * contain the geometry of the TiledGeometryLayer. It is usually a
   * `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
   * @param {Object} [config] - Optional configuration, all elements in it
   * will be merged as is in the layer. For example, if the configuration
   * contains three elements `name, protocol, extent`, these elements will be
   * available using `layer.name` or something else depending on the property
   * name.
   * @param {number} [config.maxSubdivisionLevel=5] - Maximum subdivision
   * level for this tiled layer.
   * @param {number} [config.maxDeltaElevationLevel=4] - Maximum delta between
   * two elevations tile.
   *
   * @throws {Error} `object3d` must be a valid `THREE.Object3d`.
   */
  constructor(id, extent, object3d) {
    let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
    const tms = _Crs.default.formatToTms(extent.crs);
    if (!_Extent.globalExtentTMS.get(extent.crs)) {
      // Add new global extent for this new crs projection.
      _Extent.globalExtentTMS.set(extent.crs, extent);
    }
    config.tileMatrixSets = [tms];
    super(id, object3d || new THREE.Group(), [extent], new _PlanarTileBuilder.default({
      crs: extent.crs
    }), config);
    this.isPlanarLayer = true;
    this.extent = extent;
    this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
    this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;
    this.maxDeltaElevationLevel = this.maxDeltaElevationLevel || 4.0;
  }
}
var _default = PlanarLayer;
exports.default = _default;