    import { Layer } from './baseLayer'
    import { Zondy } from '../../base'
    import {defaultValue, Log, toJSON} from '../../util'
    import TerrainServer from '../../service/igs/TerrainServer'
    import {Extent, Geometry} from '../../base/geometry'
    import { LayerType, LoadStatus } from '../../base/enum'
    import {jsonClone} from '../../util/Utils';
    /**
     * 地形图层
     * @class TerrainCacheLayer
     * @moduleEX LayerModule
     * @extends Layer
     * @fires TerrainCacheLayer#图层加载完毕事件
     * @param {Object} options 构造参数
     * @param {String} [options.url] 服务基地址
     * @param {String} [options.tokenKey = 'token'] token名
     * @param {String} [options.tokenValue] token值
     * @param {Boolean} [options.autoReset = false] 是否自动跳转
     * @param {Boolean} [options.requestVertexNormals = true] 是否请求地形法向量
     * @example <caption><h7>添加地形</h7></caption>
     * // ES5引入方式
     * const { Map, SceneView } = Zondy
     * const { TerrainCacheLayer } = Zondy.Layer
     * // ES6引入方式
     * import { Map, SceneView, TerrainCacheLayer } from "@mapgis/webclient-common"
     * // 初始化图层管理容器
     * const map = new Map();
     * // 初始化地图视图对象
     * const sceneView = new SceneView({
     *   // 视图id
     *   viewId: "mapgis-3d-viewer",
     *   // 图层管理容器
     *   map: map
     * });
     * // 初始化地形图层对象
     * terrainCacheLayer = new TerrainCacheLayer({
     *   url: 'http://192.168.82.89:8089/igs/rest/services/Scene/TwTerrain/SceneServer'
     * });
     * map.add(terrainCacheLayer);
     * */
    class TerrainCacheLayer extends Layer {
      constructor(options) {
        super(options)
        options = defaultValue(options, {})

        /**
         * 服务基地址
         * @member {String} TerrainCacheLayer.prototype.url
         */
        this.url = defaultValue(options.url, undefined)
        /**
         * 图层类型
         * @member {String} TerrainCacheLayer.prototype.type
         */
        this.type = LayerType.terrain
        /**
         * 初始化图层的额外参数，三维引擎专有的初始化参数请传入此对象
         * @member {Object} TerrainCacheLayer.prototype.extendOptions
         */
        this.extendOptions = defaultValue(options.extendOptions, {})

        // 地形服务
        this._terrainServer = new TerrainServer({
          url: this.url
        })
      }

      /**
       * 从igs获取图层信息的方法
       */
      load() {
        return super.load()
      }

      /**
       * 子类加载服务端元信息的方法
       * @private
       * */
      _load() {
        const self = this
        return new Promise((resolve) => {
          self.loadStatus = LoadStatus.loaded
          self.loaded = true
          resolve(self)
        })
      }

      /**
       * 将图层转为json对象
       * @return {Object} josn对象
       * */
      toJSON() {
        const _json = super.toJSON()

        _json.url = this.url
        _json.tokenKey = this.tokenKey
        _json.tokenValue = this.tokenValue
        _json.autoReset = this.autoReset
        _json.requestVertexNormals = this.requestVertexNormals
        _json.fullExtent = toJSON(this.fullExtent, Extent)

        return _json
      }

      static fromJSON(json) {
        json = jsonClone(json)
        const _layer = new TerrainCacheLayer(json)
        _layer._isFromJSON = true
        _layer.fullExtent = Geometry.fromJSON(json.fullExtent)

        return _layer
      }

      /**
       * 克隆并返回一个新图层
       * @return {TerrainCacheLayer} 新的图层对象
       * */
      clone() {
        return new TerrainCacheLayer(this.toJSON())
      }
    }

    /**
     * 通过url创建图层对象
     * @param {String} url 服务基地址
     * @return {TerrainCacheLayer} 新的图层对象
     * */
    TerrainCacheLayer.fromServerUrl = function (url) {
      return new TerrainCacheLayer({
        url
      })
    }

    Zondy.Layer.TerrainCacheLayer = TerrainCacheLayer
    export default TerrainCacheLayer