    import * as L from '@mapgis/leaflet'
    import { defaultValue } from '@mapgis/webclient-common'
    import { getBounds } from './support/utils'

    class WMSLayerUtil {}

    /**
     * 添加WMS图层
     * @param {WMSLayer} layer WMS图层基本对象
     * @param {Object} innerView leaflet的视图对象
     * @param {options} WMS图层options
     * @return {Object} 创建的WMS图层对象
     * */
    WMSLayerUtil.addWMSLayer = function (layer, innerView, options) {
      options = defaultValue(options, {})
      let url = layer.url
      // 处理请求接口
      url = `${url.replace('services', 'ogc/doc')}?`
      // 处理有文件夹的情况
      const urlParts = url.split('igs/rest/ogc/doc/')
      const urlP1 = urlParts[0]
      let urlP2 = urlParts[1].split('/WMSServer')[0]
      urlP2 = urlP2.replace('/', ':')
      url = `${urlP1}igs/rest/ogc/doc/${urlP2}/WMSServer?`
      if (layer.tokenKey && layer.tokenValue) {
        url += `${layer.tokenKey}=${layer.tokenValue}`
      }
      // 设置地图显示范围
      const bounds = getBounds(layer, innerView)
      const wmsLayer = L.TileLayer.wmsclip(url, {
        // 图层名称
        layers: layer.layers,
        format: layer.imageFormat,
        // wms版本号
        version: layer.version,
        // 图层透明度
        opacity: layer.opacity,
        // 只显示一个图层,不平铺显示
        noWrap: true,
        tileSize: layer.imageWidth,
        transparent: layer.imageTransparency,
        bounds,
        // 裁剪对象
        clippingArea: options.clippingArea ? options.clippingArea : null
      }).addTo(innerView)
      // 设置图层id
      wmsLayer.id = layer.id
      // 设置图层顺序
      wmsLayer.setZIndex(layer._realIndex)
      return wmsLayer
    }

    export default WMSLayerUtil