import Layer from '../layer'
import { PointLayer, Popup } from '@cgcs2000/l7'
import renderPopup from '../libs/render_popup'

class Point extends Layer {
  constructor(layer, scene, zIndex) {
    super(layer, scene)
    let { visible, minZoom, maxZoom } = this.layer
    this.layerInstance = new PointLayer({
      visible: visible === undefined ? true : !!visible,
      minZoom: Number(minZoom) || 0,
      maxZoom: Number(maxZoom) || 18,
      zIndex
    })
    this.setSource()
    this.layerInstance.on('click', e => {
      const popup = new Popup({
        offsets: [0, 0],
        closeButton: true
      })
        .setLnglat(e.lngLat)
        .setHTML(renderPopup(e.feature))
      scene.addPopup(popup)
    })
  }
}

export default Point
