'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 _layer = require('../layer/layer.js');

var _layer2 = _interopRequireDefault(_layer);

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

var _tileproperty2 = _interopRequireDefault(_tileproperty);

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

var _obj2 = _interopRequireDefault(_obj);

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

/**
 * @classdesc
 * For layer sources that provide pre-rendered, tiled images in grids that are
 * organized by zoom levels for specific resolutions.
 * 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.Layer}
 * @fires ol.render.Event
 * @param {olx.layer.TileOptions=} opt_options Tile layer options.
 * @api
 */
var _ol_layer_Tile_ = function (opt_options) {
  var options = opt_options ? opt_options : {};

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

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

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

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

_index2.default.inherits(_ol_layer_Tile_, _layer2.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_Tile_.prototype.getPreload = function () {
  return (
    /** @type {number} */this.get(_tileproperty2.default.PRELOAD)
  );
};

/**
 * Return the associated {@link ol.source.Tile tilesource} of the layer.
 * @function
 * @return {ol.source.Tile} Source.
 * @api
 */
_ol_layer_Tile_.prototype.getSource;

/**
 * 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_Tile_.prototype.setPreload = function (preload) {
  this.set(_tileproperty2.default.PRELOAD, preload);
};

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

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