<!--
 * @Author: zhangbo
 * @Date: 2021-03-04 09:22:59
 * @E-mail: zhangbo@geovis.com.cn
 * @LastModifiedBy: zhangbo
 * @LastEditTime: 2021-03-05 11:17:23
 * @Desc: 
-->

<script>
export default {
  name: "basePluginEditor",
  data() {
    return {};
  },
  mounted() {
    if (this.$store) {
      const vs = this.$store.state.DataHub.earthList;
      this.updateViewerList(vs);
    }
    if (this.Bus) {
      //修改了球的id后刷新earthList
      // this.Bus.$off("earth-list-update");
      this.Bus.$on("earth-list-update", (oid, nid) => {
        const vs = this.$store.state.DataHub.earthList;
        this.updateViewerList(vs);
        if (oid === this.componentInfo.viewerId) {
          this.componentInfo.viewerId = nid;
        }
      });
      //创建球后刷新earthList
      // this.Bus.$off("earth-list-update-l");
      this.Bus.$on("earth-list-update-l", (vs) => {
        this.updateViewerList(vs);
      });
    }
  },
  methods: {
    updateViewerList(vs) {
      if (!vs) {
        return;
      }
      for (let v of vs) {
        if (!this.viewerList.includes(v.id)) {
          this.viewerList.push(v.id);
        }
      }
      if (this.viewerList.length === 1 && !this.componentInfo.viewerId) {
        this.componentInfo.viewerId = this.viewerList[0];
      }
    },
  },
};
</script>