<template>
  <div class="h-100">
    <map-box ref="mapbox" v-if="$store.state.mapIsStyleReady">
      <!-- <template #content>
        <Statistics :plane="plane" />
      </template> -->
    </map-box>
  </div>
</template>

<script>
import MapBox from '@/components/MapBox'
// import Statistics from '@/components/Statistics'

export default {
  name: 'Home',
  data () {
    return {
    }
  },
  components: {
    MapBox
    // Statistics
  },
  computed: {
    airList () {
      return this.$store.state.airList
    },
    /**
     * @description: 侧边栏显隐
     */
    isCollapse () {
      return this.$store.state.app.isCollapse
    }
  },
  methods: {
    /**
     * @description: 创建飞机图标
     */
    makePlanes (planes) {
      this.$refs.mapbox.removePlanes()// 先清除画布上现有的飞机
      planes.forEach((plane, index) => { // 创建所有飞机
        let planeDefaultLonLat
        if (localStorage.getItem(plane.name) !== null) { // 从本地缓存 拿飞机得初始位置
          planeDefaultLonLat = JSON.parse(localStorage.getItem(plane.name))
          plane.lon = planeDefaultLonLat.lon
          plane.lat = planeDefaultLonLat.lat
        } else {
          plane.lon = 0
          plane.lat = 0
        }
        this.$refs.mapbox.makePlane(plane, index)
      })
    }
  },
  mounted () {
  },
  watch: {
    airList: {
      handler (val) {
        if (val && val.length > 0) {
          this.makePlanes(val)
        }
      },
      immediate: true // 页面加载先触发一次
    },
    /**
     * @description: 侧边栏显隐
     */
    isCollapse () {
      return this.$store.state.app.isCollapse
    }
  },
  destroyed () {
  }
}
</script>

<style></style>
