import { LayerView } from '@mapgis/webclient-common'
import { IGSM3DLayerUtil } from '../view/utils'
import ApplyLayerUpdateUtil from './support/ApplyLayerUpdateUtil'

class IGSM3DLayerView extends LayerView {
  /**
   * 添加图层视图
   * @param {LayerEvent} event 图层事件
   * @return {Promise<LayerView>} 图层视图
   */
  onAdd(event) {
    const layer = this.layer
    const innerView = this.innerView
    const that = this
    return new Promise((reslove) => {
      IGSM3DLayerUtil.addM3DLayer(layer, innerView, this.view, (layer) => {
        this.innerLayer = layer
        reslove(that)
      })
    })
  }

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

  /**
   * 更新图层视图
   * @param {LayerViewUpdateEvent} event 图层事件
   * @return {Promise<LayerView>} 图层视图
   */
  onUpdate(event) {
    const _layer = this.innerLayer
    ApplyLayerUpdateUtil.applyUpdate(this.view, this.layer, _layer, event)
    return Promise.resolve(this)
  }
}
export default IGSM3DLayerView
