<!-- 飞控地图选择 -->
<template>
  <div class="map-switch" @mousemove="onMousemove" @mouseleave="onMouseleave">
    <div class="map-switch-btn">
      <div class="map-item" :class="selectIconClass"></div>
    </div>

    <div class="map-list" v-show="showMenu">
      <div class="map-item">
        <div
          class="dim"
          :class="{ active: !is_3d }"
          v-show="!is_3d"
          @click="handle_change_3d(true)"
        >
          2D
        </div>
        <div
          class="dim"
          :class="{ active: is_3d }"
          v-show="is_3d"
          @click="handle_change_3d(false)"
        >
          3D
        </div>
      </div>
      <div
        v-for="item in tabs"
        :key="item.id"
        class="map-item"
        @click="onSelect(item.class_name)"
      >
        <el-tooltip effect="dark" :content="item.name" placement="top-start">
          <div
            class="map-item"
            :class="item.class_name"
            @click="handle_change(item.id)"
            style="position: relative; overflow: hidden"
          ></div>
        </el-tooltip>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  components: {},
  data() {
    return {
      selectIconClass: "map-item-satellite",
      showMenu: false,
      is_3d: true,
      current: 1,
      tabs: [
        {
          id: 1,
          name: "卫星",
          class_name: "map-item-satellite",
        },
        // {
        //   id: 4,
        //   name: "星图",
        //   class_name: "map-item-satellite",
        // },
        {
          id: 2,
          name: "街道",
          class_name: "map-item-street",
        },
        {
          id: 3,
          name: "夜景",
          class_name: "map-item-night-blue",
        },
      ],
      handler: null,
    };
  },
  computed: {
    ...mapState("MMCFlightControlCenter", [
      "cesiumImagesLayers",
      "cesium3DModels",
    ]),
  },
  mounted() {
    console.log("handle_change2");
    setTimeout(() => {
      this.handle_change(1);
      this.handle_change_3d(false);
    }, 3500);
  },
  watch: {},
  methods: {
    onMousemove() {
      this.showMenu = true;
      clearTimeout(this.handler);
    },
    onMouseleave() {
      this.handler = setTimeout(() => {
        this.showMenu = false;
      }, 300);
    },
    // 选中的图标
    onSelect(className) {
      this.selectIconClass = className;
    },
    handle_change_3d(bool) {
      this.is_3d = bool;
      this.$store.dispatch("MMCFlightControlCenter/switch3DModelsShow", {
        show: bool,
      });
    },
    handle_change(id) {
      this.cesiumImagesLayers.satellite.show = false;
      this.cesiumImagesLayers.star_satellite.show = false;
      this.cesiumImagesLayers.street.show = false;
      this.cesiumImagesLayers.night.show = false;
      this.cesiumImagesLayers.text.show = false;
      this.current = id;
      if (id == 1) {
        this.cesiumImagesLayers.satellite.show = true;
        this.cesiumImagesLayers.text.show = true;
      } else if (id == 2) {
        this.cesiumImagesLayers.street.show = true;
      } else if (id == 3) {
        this.cesiumImagesLayers.night.show = true;
      } else if (id == 4) {
        this.cesiumImagesLayers.star_satellite.show = true;
        this.cesiumImagesLayers.text.show = true;
      }
      console.log("this.cesiumImagesLayers", this.cesiumImagesLayers, id);
    },
  },
};
</script>

<style lang="scss" scoped>
.map-switch {
  z-index: 1;
  bottom: 30px;
  position: absolute;
  right: 14px;
  width: 48px;
  height: 48px;
  transition: 0.2s;
  transform: translateX(0);

  .map-switch-btn {
    cursor: pointer;
    position: absolute;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 2px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;

    &.active {
      width: 166px;
    }

    .map-item {
      box-sizing: border-box;
      border-radius: 50%;
      border: 3px solid #fff;
      position: relative;
      width: 100%;
      height: 100%;

      &.map-item-satellite {
        background: url(./assets/images/3d.png) center no-repeat;
        // background: url("./assets/images/ditu_icon.png") center no-repeat;
        background-size: 112% 112%;
      }

      &.map-item-street {
        background: url(./assets/images/2d.png) center no-repeat;
      }

      &.map-item-night-blue {
        background: url(./assets/images/night-blue.png) center no-repeat;
        // background-size: 115% 115%;
      }

      &.map-item-3d {
        background: url(./assets/images/3d.png) center no-repeat;
      }

      &.map-item-2d {
        background: url(./assets/images/2d.png) center no-repeat;
      }

      &.map-item-street {
      }

      .typeNmae {
        position: absolute;
        bottom: 0;
        right: 0;
        z-index: 1;
        height: 20px;
        border: 1px solid #43ddfe;
        box-shadow: inset 0 0 7px 0 #43ddfe;
        border-radius: 1px;
        font-size: 12px;
        line-height: 20px;
        text-align: center;
        color: #04d5da;
      }
    }
  }

  .map-list {
    position: absolute;
    background: #fff;
    right: 60px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 6px;
    gap: 6px;

    // display: flex;
    .map-item {
      width: 42px;
      height: 36px;
      cursor: pointer;

      .dim {
        width: 100%;
        height: 100%;
        font-size: 14px;
        color: #ffffff;
        font-weight: 700;
        border-radius: 4px;
        background: #000000;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }

    .map-item-satellite {
      background: url(./assets/images/3d.png) center no-repeat;
    }

    .map-item-street {
      background: url(./assets/images/2d.png) center no-repeat;
    }

    .map-item-night-blue {
      background: url(./assets/images/night-blue.png) center no-repeat;
    }

    .map-item-3d {
      background: url(./assets/images/3d.png) center no-repeat;
    }

    .map-item-2d {
      background: url(./assets/images/2d.png) center no-repeat;
    }
  }
}
</style>