<!--
 * @Description: 管线图层
 * @Author: 王晓颖
 * @Date: 2021-06-04 14:55:15
 -->
<template>
  <div>
    <slot/>
  </div>
</template>

<script>
import commonMixin from '../base/mixins/common.js'
export default {
  name: 'PipeLayer',
  mixins: [commonMixin('layer')],
  props: {
    glowPower: {
      type: Number,
      default: 0.02
    }, // 发光强度
    opacity: {
      type: Number,
      default: 1
    }, // 透明度
    width: {
      type: Number,
      default: 5
    }, // 线宽度
    height: {
      type: Number,
      default: 0
    }, // 高度
    color: {
      type: String,
      default: '#5affb2'
    }, // 偏移值
    show: {
      type: Boolean,
      default: false
    } // 是否可见
  },
  data() {
    return {
      layer: null, // 图层
      data: [] // 完整数据
    }
  },
  watch: {
    show(val) {
      if (val) {
        this.initLayer()
      } else {
        this.removeLayer()
      }
    }
  },
  methods: {
    load() {
      if (this.show) {
        this.initLayer()
      }
    },
    initLayer() {
      const { mars3d, map, color, width, glowPower, opacity } = this
      if (map) {
        if (this.show && this.layer) { // 如果已经有图层了，先移除
          this.removeLayer()
        }
        this.layer = new mars3d.layer.GeoJsonLayer({
          type: 'geojson',
          url: 'static/geojson/pipe_old.json',
          symbol: {
            styleOptions: {
              lineType: 'glow',
              // materialType: 'LineFlicker',
              glowPower: glowPower, // 发光强度
              width: width, // 线宽
              color: color,
              opacity: opacity,
              clampToGround: false
            }
          },
          show: true
        })
        map.addLayer(this.layer)
        // this.loadData()
      }
    },
    // 移除图层
    removeLayer() {
      const { map, layer } = this
      if (this.layer) {
        map.removeLayer(layer)
        this.layer = null
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
