    import Zondy from './Zondy'
    import { defaultValue, getGUID } from '../util'

    /**
     * IGS地图服务图层
     * @class TileMatrixSet
     * @classdesc IGS地图图层
     * @param {Object} options 构造参数
     * @param {Extent} [options.extent = undefined] 图层范围
     * @param {String} [options.id = getGUID()] 图块矩阵集id
     * @param {String} [options.tileInfo = undefined] 切片信息
     * @param {WMTSLayer} [options.layer = undefined] 图层
     */

    class TileMatrixSet {
      constructor(options) {
        options = defaultValue(options, {})
        /**
         * 图层范围
         * @member {Extent} TileMatrixSet.prototype.extent
         */
        this.extent = defaultValue(options.extent, undefined)
        /**
         * 图块矩阵集id
         * @member {String} TileMatrixSet.prototype.id
         */
        this.id = defaultValue(options.id, getGUID())
        /**
         * 切片信息
         * @member {String} TileMatrixSet.prototype.tileInfo
         */
        this.tileInfo = defaultValue(options.tileInfo, undefined)
        /**
         * 图层
         * @member {WMTSLayer} TileMatrixSet.prototype.layer
         */
        this.layer = defaultValue(options.layer, undefined)
        /**
         * 矩阵集
         * @member {Array} TileMatrixSet.prototype.tileMatrix
         */
        this.tileMatrix = defaultValue(options.tileMatrix, [])
        /**
         * 矩阵identifier
         * @member {String} TileMatrixSet.prototype.identifier
         */
        this.identifier = defaultValue(options.identifier, undefined)

        /**
         * 支持的CRS
         * @member {String} TileMatrixSet.prototype.supportedCRS
         */
        this.supportedCRS = defaultValue(options.supportedCRS, undefined)
      }

      /**
       * @function TileMatrixSet.prototype.fromJSON
       * @description 获取切片分辨率
       */
      getTileResolution() {
        const resolution = []
        for (let i = 0; i < this.tileMatrix.length; i++) {
          resolution.push(
            (Number(this.tileMatrix[i].scaleDenominator) * 0.28) / 1000
          )
        }
        return resolution
      }

      /**
       * @function TileMatrixSet.prototype.fromJSON
       * @description 将JSON格式的图块矩阵集参数转换为JS对象
       * @param {Object} json 图块矩阵集的实例化JSON
       */
      fromJSON(json) {
        json = defaultValue(json, {})

        this.extent = defaultValue(json.extent, undefined)
        this.id = defaultValue(json.id, getGUID())
        this.tileInfo = defaultValue(json.tileInfo, undefined)
        this.layer = defaultValue(json.layer, undefined)
      }

      /**
       * @function TileMatrixSet.prototype.toJSON
       * @description 将JS对象转换为JSON格式
       * @returns {Object} 图块矩阵集的实例化JSON
       */
      toJSON() {
        return {
          extent: this.extent && this.extent.toJSON(),
          id: this.id,
          tileInfo: this.tileInfo && this.tileInfo.toJSON(),
          tileMatrix: this.tileMatrix,
          identifier: this.identifier,
          supportedCRS: this.supportedCRS
        }
      }

      /**
       * 克隆图块矩阵集对象
       * @return {TileMatrixSet} 克隆后的图块矩阵集对象
       */
      clone() {
        return new TileMatrixSet(this.toJSON())
      }
    }

    Zondy.TileMatrixSet = TileMatrixSet
    export default TileMatrixSet