    import { BaseGraphicsLayerView, FeatureSet } from '@mapgis/webclient-common'
    import * as L from '@mapgis/leaflet'
    import { reorderGraphicLayer } from './support/Utils'
    import LeafletPlugin from '../util/LeafletPlugin'

    class GraphicsLayerView extends BaseGraphicsLayerView {
      /**
       * 添加图层视图
       * @param {LayerEvent} 图层事件
       * @return {Promise<LayerView>} 图层视图
       */
      onAdd(event) {
        const layer = this.layer
        const innerView = this.innerView
        const features = layer.graphics || []
        const self = this
        reorderGraphicLayer(this, function () {
          // leaflet 要素图层
          self.innerLayer = L.featureGroup().addTo(innerView)
          self.innerLayer.commonLayerId = layer.id
          self.innerLayer._realIndex = layer._realIndex
          // 处理透明度和是否可见
          LeafletPlugin.setVisibleOpacity(
            self.innerLayer,
            layer._opacity,
            layer._visible
          )
          features.forEach((feature) => {
            self._addFeature(self.innerLayer, feature)
          })
        })
        return Promise.resolve(this)
      }

      /**
       * 移除图层视图
       * @param {LayerEvent} 图层事件
       * @return {Promise<LayerView>} 图层视图
       */
      onRemove(event) {
        this.innerView.removeLayer(this.innerLayer)
        this.innerLayer = null
        return Promise.resolve(this)
      }

      /**
       * 更新图层视图
       * @param {LayerViewUpdateEvent} 图层事件
       * @return {Promise<LayerView>} 图层视图
       */
      onUpdate(event) {
        const layer = this.layer
        const innerLayer = this.innerLayer
        if (event.updateContent && innerLayer) {
          event.updateContent.forEach((layerUpdateCotent) => {
            if (
              layerUpdateCotent &&
              layerUpdateCotent.operationType === 'property'
            ) {
              switch (layerUpdateCotent.name) {
                case 'opacity': {
                  LeafletPlugin.setVisibleOpacity(
                    this.innerLayer,
                    layer._opacity,
                    layer._visible
                  )
                  break
                }
                case 'visible': {
                  const flag = layerUpdateCotent.params[0]
                  LeafletPlugin.setVisibleOpacity(
                    this.innerLayer,
                    layer._opacity,
                    flag
                  )
                  break
                }
                case 'index': {
                  this.innerLayer._realIndex = this.layer._realIndex
                  reorderGraphicLayer(this)
                  break
                }
                default: {
                  break
                }
              }
            }
            if (layerUpdateCotent && layerUpdateCotent.operationType === 'method') {
              switch (layerUpdateCotent.name) {
                case 'add': {
                  const params = layerUpdateCotent.params
                  this._addFeature(innerLayer, params[0])
                  break
                }
                case 'remove': {
                  const params = layerUpdateCotent.params
                  this._removeFeature(innerLayer, params[0])
                  break
                }
                case 'addMany': {
                  const params = layerUpdateCotent.params
                  let features = params[0]
                  if (features instanceof FeatureSet) {
                    features = features.features
                  }
                  features.forEach((feature) => {
                    this._addFeature(innerLayer, feature)
                  })
                  break
                }
                case 'removeMany': {
                  const params = layerUpdateCotent.params
                  const features = params[0]
                  features.forEach((feature) => {
                    this._removeFeature(innerLayer, feature)
                  })
                  break
                }
                case 'removeAll': {
                  innerLayer.clearLayers()
                  break
                }
                default: {
                  break
                }
              }
            }
          })
        }
        return Promise.resolve(this)
      }

      /**
       * @description 添加要素
       * @param {L.FeatureGroup} innerLayer
       * @param {Feature} feature
       * @return {*}
       */
      _addFeature(innerLayer, feature) {
        if (feature.geometry && !feature.geometry.spatialReference) {
          feature.geometry.spatialReference = this.layer.spatialReference
        }
        this.render.drawFeature(innerLayer, [feature])
      }

      /**
       * @description 添加要素
       * @param {L.FeatureGroup} innerLayer
       * @param {Feature} feature
       * @return {*}
       */
      _removeFeature(innerLayer, feature) {
        this.render.clearFeature(innerLayer, [feature])
      }
    }
    export default GraphicsLayerView