<template>
  <div style="width: 100%;height: 100%;">
    <div ref="map" id="map" style="width: 100%;height: 100%;"></div>
  </div>
</template>
<script>
import Chart from '@/components/chart'

export default {
  props: ['defaultData'],
  expose: ['getRequestData'],
  components: {
    Chart
  },
  data() {
    return {
      requestData:null,
      map:null
    }
  },
  watch: {
    defaultData: {
      handler(a, b) {
        this.getOption()
      },
      deep: true
    }
  },
  mounted() {
    this.getRequestData()
    this.getOption()
  },
  methods: {
    getOption() {
      if(!this.map){
        console.log(this.$refs.map)
        this.map = new AMap.Map(this.$refs.map, {
          zoom: 11,
          center: [113.4, 23.35],
        });
      }
    },
    async getRequestData(){
      this.requestData = {}
      for (const e of this.defaultData.requests) {
        let fn = new Function('_this', e.text)
        let data = await fn(this)
        e.data = data
        this.requestData = ({...this.requestData, ...data})
      }
    }
  },
}
</script>
<style>

</style>
