    import { Zondy } from '../../../base'
    import { SubLayer } from '../baseLayer'
    import { defaultValue } from '../../../util'
    import { Extent, Point } from '../../../base/geometry'
    import { LayerType } from '../../../base/enum'

    class IGSSceneSubLayer extends SubLayer {
      constructor(options) {
        super(options)
        options = defaultValue(options, {})

        /**
         * 最大屏幕几何异常
         * @member {Number} IGSSceneSubLayer.prototype.maximumScreenSpaceError
         */
        this.maximumScreenSpaceError = defaultValue(
          options.maximumScreenSpaceError,
          16
        )

        /**
         * 模型阴影区域亮度
         * @member {Number} IGSSceneSubLayer.prototype.luminanceAtZenith
         */
        this.luminanceAtZenith = defaultValue(options.luminanceAtZenith, 0.2)

        /**
         * 子图层的索引
         * @member {Number} IGSSceneSubLayer.prototype.layerIndex
         */
        this.layerIndex = defaultValue(options.layerIndex, 0)
        this.layerRenderIndex = defaultValue(options.layerRenderIndex, 0)

        /**
         * 子图层类型
         * @member {String} IGSSceneSubLayer.prototype.type
         */
        this.type = defaultValue(options.layerType, undefined)

        /**
         * 子图层渲染类型
         * @member {String} IGSSceneSubLayer.prototype.renderType
         */
        this.renderType = defaultValue(options.layerRenderType, undefined)

        /**
         * 开始级别
         * @member {Number} IGSSceneSubLayer.prototype.beginLevel
         */
        this.beginLevel = defaultValue(options.beginLevel, -1)

        /**
         * 结束级别
         * @member {Number} IGSSceneSubLayer.prototype.endLevel
         */
        this.endLevel = defaultValue(options.endLevel, -1)

        /**
         * 网格划分的源点
         * @member {Point} IGSSceneSubLayer.prototype.originPoint
         */
        if (options.originalPoints) {
          this.originPoint = new Point({
            coordinates: [options.originalPoints.x, options.originalPoints.y]
          })
        } else {
          this.originPoint = undefined
        }

        /**
         * 最大网格大小
         * @member {Number} IGSSceneSubLayer.prototype.maxFrameSize
         */
        if (options.frameSizes) {
          this.maxFrameSize = options.frameSizes[0]
        } else {
          this.maxFrameSize = undefined
        }

        /**
         * 扩展属性
         * @member {Array} IGSSceneSubLayer.prototype.extendedProps
         */
        this.extendedProps = defaultValue(options.extendedProps, [])

        /**
         * 子图层服务地址
         * @member {String} IGSSceneSubLayer.prototype.url
         */
        this.url = defaultValue(options.url || options.gdbpUrl, undefined)

        /**
         * 子图层服范围(二维)
         * @member {Extent} IGSSceneSubLayer.prototype.range
         */
        if (options.range) {
          this.range = new Extent({
            xmin: options.range.xMin,
            ymin: options.range.yMin,
            xmax: options.range.xMax,
            ymax: options.range.yMax
          })
        } else {
          this.range = undefined
        }

        /**
         * 子图层服范围(三维)
         * @member {Extent} IGSSceneSubLayer.prototype.range3D
         */
        if (options.range3D) {
          this.range3D = new Extent({
            xmin: options.range3D.xMin,
            ymin: options.range3D.yMin,
            xmax: options.range3D.xMax,
            ymax: options.range3D.yMax,
            zmin: options.range3D.zMin,
            zmax: options.range3D.zMax
          })
        } else {
          this.range3D = undefined
        }

        /**
         * 子图层所属的场景服务图层
         * @member {Layer} SubLayer.prototype.layer
         */
        this.layer = defaultValue(options.layer, undefined)
        if (
          options.children &&
          options.children instanceof Array &&
          options.children.length > 0
        ) {
          for (let i = 0; i < options.children.length; i++) {
            options.children[i].layer = this.layer
            this.sublayers.push(new IGSSceneSubLayer(options.children[i]))
          }
        }
        this.elevationScale = defaultValue(options.elevationScale, undefined)
        this.requestVertexNormals = defaultValue(
          options.requestVertexNormals,
          false
        )
        this.labelLayer = defaultValue(options.labelLayer, undefined)
        this.layerName = defaultValue(options.layerName, undefined)
      }

      /**
       * 将对象转为json对象
       * @return {Object} json对象
       * */
      toJSON() {
        const json = {
          id: this.id,
          layer: this.layer,
          sublayers: this.sublayers,
          title: this.title,
          visible: this.visible,
          maximumScreenSpaceError: this.maximumScreenSpaceError,
          luminanceAtZenith: this.luminanceAtZenith,
          layerIndex: this.layerIndex,
          type: this.type,
          renderType: this.renderType,
          beginLevel: this.beginLevel,
          endLevel: this.endLevel,
          originPoint: this.originPoint,
          maxFrameSize: this.maxFrameSize,
          extendedProps: this.extendedProps
        }

        return JSON.parse(JSON.stringify(json))
      }
    }

    /**
     * 通过json对象初始化该对象
     * @param {Object} json json对象
     * @memberof IGSSceneSubLayer
     */
    IGSSceneSubLayer.fromJSON = function (json) {
      return new IGSSceneSubLayer(json)
    }

    Zondy.Layer.IGSSceneSubLayer = IGSSceneSubLayer
    export default IGSSceneSubLayer