'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _index = require('../index.js');

var _index2 = _interopRequireDefault(_index);

var _layertype = require('../layertype.js');

var _layertype2 = _interopRequireDefault(_layertype);

var _asserts = require('../asserts.js');

var _asserts2 = _interopRequireDefault(_asserts);

var _tileproperty = require('../layer/tileproperty.js');

var _tileproperty2 = _interopRequireDefault(_tileproperty);

var _vector = require('../layer/vector.js');

var _vector2 = _interopRequireDefault(_vector);

var _vectortilerendertype = require('../layer/vectortilerendertype.js');

var _vectortilerendertype2 = _interopRequireDefault(_vectortilerendertype);

var _obj = require('../obj.js');

var _obj2 = _interopRequireDefault(_obj);

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

/**
 * @classdesc
 * Layer for vector tile data that is rendered client-side.
 * Note that any property set in the options is set as a {@link ol.Object}
 * property on the layer object; for example, setting `title: 'My Title'` in the
 * options means that `title` is observable, and has get/set accessors.
 *
 * @constructor
 * @extends {ol.layer.Vector}
 * @param {olx.layer.VectorTileOptions=} opt_options Options.
 * @api
 */
var _ol_layer_VectorTile_ = function (opt_options) {
  var options = opt_options ? opt_options : {};

  var renderMode = options.renderMode || _vectortilerendertype2.default.HYBRID;
  _asserts2.default.assert(renderMode == undefined || renderMode == _vectortilerendertype2.default.IMAGE || renderMode == _vectortilerendertype2.default.HYBRID || renderMode == _vectortilerendertype2.default.VECTOR, 28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`
  if (options.declutter && renderMode == _vectortilerendertype2.default.IMAGE) {
    renderMode = _vectortilerendertype2.default.HYBRID;
  }
  options.renderMode = renderMode;

  var baseOptions = _obj2.default.assign({}, options);

  delete baseOptions.preload;
  delete baseOptions.useInterimTilesOnError;
  _vector2.default.call(this, /** @type {olx.layer.VectorOptions} */baseOptions);

  this.setPreload(options.preload ? options.preload : 0);
  this.setUseInterimTilesOnError(options.useInterimTilesOnError ? options.useInterimTilesOnError : true);

  /**
   * The layer type.
   * @protected
   * @type {ol.LayerType}
   */
  this.type = _layertype2.default.VECTOR_TILE;
};

_index2.default.inherits(_ol_layer_VectorTile_, _vector2.default);

/**
 * Return the level as number to which we will preload tiles up to.
 * @return {number} The level to preload tiles up to.
 * @observable
 * @api
 */
_ol_layer_VectorTile_.prototype.getPreload = function () {
  return (
    /** @type {number} */this.get(_tileproperty2.default.PRELOAD)
  );
};

/**
 * Whether we use interim tiles on error.
 * @return {boolean} Use interim tiles on error.
 * @observable
 * @api
 */
_ol_layer_VectorTile_.prototype.getUseInterimTilesOnError = function () {
  return (
    /** @type {boolean} */this.get(_tileproperty2.default.USE_INTERIM_TILES_ON_ERROR)
  );
};

/**
 * Set the level as number to which we will preload tiles up to.
 * @param {number} preload The level to preload tiles up to.
 * @observable
 * @api
 */
_ol_layer_VectorTile_.prototype.setPreload = function (preload) {
  this.set(_tileproperty2.default.PRELOAD, preload);
};

/**
 * Set whether we use interim tiles on error.
 * @param {boolean} useInterimTilesOnError Use interim tiles on error.
 * @observable
 * @api
 */
_ol_layer_VectorTile_.prototype.setUseInterimTilesOnError = function (useInterimTilesOnError) {
  this.set(_tileproperty2.default.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
};

/**
 * Return the associated {@link ol.source.VectorTile vectortilesource} of the layer.
 * @function
 * @return {ol.source.VectorTile} Source.
 * @api
 */
_ol_layer_VectorTile_.prototype.getSource;
exports.default = _ol_layer_VectorTile_;
module.exports = exports['default'];