<template>
  <div class="plant-gs-warp">
    <div ref="viewwarp" class="plant-gs-content" :style="{ 'background-image': 'url(' + getAssetsFile('images/plant/bg1.png') + ')' }">
      <vc-config-provider :cesium-path="vcConfig.cesiumPath" :access-token="vcConfig.accessToken">
        <vc-viewer ref="viewerRef" @ready="onViewerReady">
          <vc-layer-imagery :minimum-level="12" :maximum-level="18" :contrast="1.8" :saturation="1" :alpha="1">
            <vc-imagery-provider-amap :key="'c843a50db7157faf295c6fa37c48719f'"></vc-imagery-provider-amap>
          </vc-layer-imagery>
          <!-- <vc-entity :position="[99.402267, 23.538889, 4000]" description="Hello VueCesium">
            <vc-graphics-plane
              ref="plane2"
              :plane="[{ x: 0, y: 1, z: 1 }, 0]"
              :dimensions="[400, 300]"
              :material="[255, 0, 0, 125]"
              :outline="true"
              outline-color="black"
            ></vc-graphics-plane>
          </vc-entity> -->
        </vc-viewer>
      </vc-config-provider>
    </div>
  </div>
</template>
<script setup>
import { isEmpty, getAssetsFile } from '@/utils';
import { ref, reactive, onMounted, computed, nextTick, getCurrentInstance } from 'vue';
import { VcViewer, VcConfigProvider, VcImageryProviderAmap, VcLayerImagery, VcGraphicsPlane, VcEntity } from 'vue-cesium';
import 'vue-cesium/dist/index.css';

const vcConfig = reactive({
  cesiumPath: 'https://cdn.bootcdn.net/ajax/libs/cesium/1.80.0/Cesium.js',
  accessToken:
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjJjZTUxYi1lOTQ3LTQ3YjctOGI3ZS02ZGUzY2E4YWFkNDkiLCJpZCI6Mjg4MjAxLCJpYXQiOjE3NDMwNTY0MzN9.rjHQiqf7Y8bccaqsapqveULVAUH6M1QkeFp-AKG-frA',
});
const viewerRef = ref(null);
const viewwarp = ref(null);
let plane2 = ref(null);
onMounted(() => {
  console.info('onMounted', viewerRef);
  Promise.all([plane2.value.creatingPromise]).then((instances) => {
    console.info('instances');
    // instances[0].viewer.zoomTo(instances[0].viewer.entities);
  });
});

const onViewerReady = (readyObj) => {
  console.info('readyObj', readyObj.Cesium); // Cesium namespace object
  console.log(readyObj.viewer); // instanceof Cesium.Viewer

  // 在这里处理 Viewer 的初始化逻辑
  const { Cesium, viewer } = readyObj;

  // 示例：设置地球背景颜色
  viewer.scene.globe.baseColor = Cesium.Color.DARKBLUE;
  viewer.camera.setView({
    destination: Cesium.Cartesian3.fromDegrees(99.406653, 23.534142, 4000),
    orientation: {
      heading: Cesium.Math.toRadians(0), // 方向角
      pitch: Cesium.Math.toRadians(-90), // 俯仰角
      roll: 0, // 滚动角
    },
  });
};
</script>
<style lang="scss" scoped>
.plant-gs-warp {
  height: 100%;
  padding: 10px 0;
  width: 100%;
  box-sizing: border-box;
  .plant-gs-content {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 100%;
    height: 100%;
    overflow: hidden;
    ::v-deep() {
      .vc-viewer {
        height: calc(100% - 30px) !important;
        width: calc(100% - 20px) !important;
        margin: 20px 10px 10px 10px !important;
      }
      canvas {
        border-radius: 10px !important;
      }
      .cesium-viewer-bottom {
        display: none !important;
      }
    }
  }
}
</style>
