    import {ElevationInfo, LayerEvent} from '../../base'

    /**
     * 设置地图层
     * @private
     * @param {Object} layer 父图层对象
     * @param {Object} subLayer 子图层对象
     * @param {Object} SubLayerConstructor 子图层构造函数
     * */
    function setSublayer(layer, subLayer, SubLayerConstructor) {
      // 是否添加子图层
      let isAdd = true

      for (let i = 0; i < layer._sublayers.length; i++) {
        // 判断name或id
        if (
          String(layer._sublayers[i].name) === String(subLayer.name) ||
          String(layer._sublayers[i].id) === String(subLayer.id)
        ) {
          Object.assign(layer._sublayers[i], subLayer)
          isAdd = false
          break
        }
      }

      for (let i = 0; i < layer.allSublayers.length; i++) {
        // 判断name或id
        if (
          String(layer.allSublayers[i].name) === String(subLayer.name) ||
          String(layer.allSublayers[i].id) === String(subLayer.id)
        ) {
          Object.assign(layer.allSublayers[i], subLayer)
          isAdd = false
          break
        }
      }

      // 添加子图层
      if (isAdd) {
        // 是子图层对象，直接添加
        if (subLayer instanceof SubLayerConstructor) {
          layer._sublayers.push(subLayer)
        }
        // 是Object对象，造一个WMSSubLayer对象
        else if (subLayer instanceof Object && !(subLayer instanceof Array)) {
          // 从所有子图层中找对应的子图层
          for (let i = 0; i < layer.allSublayers.length; i++) {
            if (
              String(subLayer.id) === String(layer.allSublayers[i].id) ||
              String(subLayer.name) === String(layer.allSublayers[i].name)
            ) {
              layer._sublayers.push(
                new SubLayerConstructor(
                  Object.assign(layer.allSublayers[i].toJSON(), subLayer)
                )
              )
              break
            }
          }
        }
      }
    }

    /**
     * 发送事件私有方法
     * @private
     * @param {Object} layer layer对象
     * @param {String} mainType 主事件
     * @param {String} subType 子事件
     * */
    function fireEvent(layer, mainType, subType) {
      // 发送更新事件
      if (layer._map) {
        layer._map.fire(
          mainType,
          new LayerEvent({
            type: subType,
            target: layer._map,
            layer,
            extend: {
              type: subType
            }
          })
        )
      }
    }

    /**
     * 设置要素的elevationInfo参数
     * @param {Feature} feature 要素对象
     * @param {Layer} layer 图层对象
     * */
    function setElevationInfo(feature, layer) {
      // 如果要素上没有高程参数，就用图层上的，否则用要素自己的
      if (!feature.elevationInfo) {
        if (layer.elevationInfo) {
          feature.elevationInfo = layer.elevationInfo
        } else {
          feature.elevationInfo = new ElevationInfo()
        }
      }
    }

    export { setSublayer, fireEvent, setElevationInfo }